From d11224e04dde09a1964835162f6915acc7aec934 Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Mon, 12 Dec 2016 12:05:11 +0100 Subject: [PATCH] virt plugin: handle disconnect on inst#0 Only one virt reader instance should take care of connection handling (connection/disconnection) to avoid races and plugin data corruption, potentially crashing collectd. This bug cannot be triggered with instances=1 (default settings). Signed-off-by: Francesco Romani --- src/virt.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/virt.c b/src/virt.c index 93f9aee3..471bdd74 100644 --- a/src/virt.c +++ b/src/virt.c @@ -520,6 +520,13 @@ static int lv_connect(void) { return 0; } +static void lv_disconnect(void) { + if (conn != NULL) + virConnectClose(conn); + conn = NULL; + WARNING(PLUGIN_NAME " plugin: closed connection to libvirt"); +} + static int lv_read(user_data_t *ud) { time_t t; struct lv_read_instance *inst = NULL; @@ -544,9 +551,8 @@ static int lv_read(user_data_t *ud) { if ((last_refresh == (time_t)0) || ((interval > 0) && ((last_refresh + interval) <= t))) { if (refresh_lists(inst) != 0) { - if (conn != NULL) - virConnectClose(conn); - conn = NULL; + if (inst->id == 0) + lv_disconnect(); return -1; } last_refresh = t; -- 2.30.2