qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v5 3/6] monitor: Clean up fd sets on monitor disconn


From: Corey Bryant
Subject: [Qemu-devel] [PATCH v5 3/6] monitor: Clean up fd sets on monitor disconnect
Date: Mon, 23 Jul 2012 09:08:02 -0400

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. (address@hidden,
  address@hidden, address@hidden)

Signed-off-by: Corey Bryant <address@hidden>
---
 monitor.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/monitor.c b/monitor.c
index e27dbbe..30b085f 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2538,6 +2538,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"
@@ -4751,9 +4764,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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]