Comments
Patch
@@ -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;
}
}
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) Signed-off-by: Corey Bryant <coreyb@linux.vnet.ibm.com> --- monitor.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)