From: Francesco Romani Date: Mon, 12 Dec 2016 11:05:11 +0000 (+0100) Subject: virt plugin: handle disconnect on inst#0 X-Git-Tag: collectd-5.8.0~266^2~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d11224e04dde09a1964835162f6915acc7aec934;p=collectd.git 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 --- 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;