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

[libvirt] [PATCH v5 3/6] monitor: Clean up fd sets on monitor disconnect

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.

 -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)

Signed-off-by: Corey Bryant <coreyb linux vnet ibm com>
 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);
+        monitor_fdsets_set_in_use(mon, true);
+        monitor_fdsets_set_in_use(mon, false);

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