From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:51676) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SxLgB-0006wE-Ov for qemu-devel@nongnu.org; Fri, 03 Aug 2012 13:28:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SxLgA-0008Ge-Oj for qemu-devel@nongnu.org; Fri, 03 Aug 2012 13:28:51 -0400 Received: from e37.co.us.ibm.com ([32.97.110.158]:45940) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SxLgA-0008GU-Hq for qemu-devel@nongnu.org; Fri, 03 Aug 2012 13:28:50 -0400 Received: from /spool/local by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 3 Aug 2012 11:28:49 -0600 Received: from d03relay03.boulder.ibm.com (d03relay03.boulder.ibm.com [9.17.195.228]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 0046D3E4003B for ; Fri, 3 Aug 2012 17:28:44 +0000 (WET) Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q73HSM3I043522 for ; Fri, 3 Aug 2012 11:28:27 -0600 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q73HSM9S022453 for ; Fri, 3 Aug 2012 11:28:22 -0600 From: Corey Bryant Date: Fri, 3 Aug 2012 13:28:06 -0400 Message-Id: <1344014889-12390-4-git-send-email-coreyb@linux.vnet.ibm.com> In-Reply-To: <1344014889-12390-1-git-send-email-coreyb@linux.vnet.ibm.com> References: <1344014889-12390-1-git-send-email-coreyb@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v6 3/6] monitor: Clean up fd sets on monitor disconnect List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@linux.vnet.ibm.com, libvir-list@redhat.com, Corey Bryant , lcapitulino@redhat.com, eblake@redhat.com Each fd set has a boolean that keeps track of whether or not the fd set is in use by a monitor connection. When a monitor disconnects, all fds that are members of an fd set with refcount of zero are closed. This prevents any fd leakage associated with a client disconnect prior to using a passed fd. v5: -This patch is new in v5. -This support addresses concerns from v4 regarding fd leakage if the client disconnects unexpectedly. (eblake@redhat.com, kwolf@redhat.com, dberrange@redhat.com) v6: -No changes Signed-off-by: Corey Bryant --- monitor.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/monitor.c b/monitor.c index 9aa9f7e..a46ef8d 100644 --- a/monitor.c +++ b/monitor.c @@ -2559,6 +2559,19 @@ FdsetInfoList *qmp_query_fdsets(Error **errp) return fdset_list; } +static void monitor_fdsets_set_in_use(Monitor *mon, bool in_use) +{ + mon_fdset_t *mon_fdset; + mon_fdset_t *mon_fdset_next; + + QLIST_FOREACH_SAFE(mon_fdset, &mon->fdsets, next, mon_fdset_next) { + mon_fdset->in_use = in_use; + if (!in_use) { + monitor_fdset_cleanup(mon_fdset); + } + } +} + /* mon_cmds and info_cmds would be sorted at runtime */ static mon_cmd_t mon_cmds[] = { #include "hmp-commands.h" @@ -4763,9 +4776,11 @@ static void monitor_control_event(void *opaque, int event) data = get_qmp_greeting(); monitor_json_emitter(mon, data); qobject_decref(data); + monitor_fdsets_set_in_use(mon, true); break; case CHR_EVENT_CLOSED: json_message_parser_destroy(&mon->mc->parser); + monitor_fdsets_set_in_use(mon, false); break; } } -- 1.7.10.4