From c09f8ee768891aee1222ad0a3e19c66b099cc973 Mon Sep 17 00:00:00 2001 From: Pavel Rochnyack Date: Fri, 24 May 2019 17:48:18 +0700 Subject: [PATCH] virt plugin: Added timeout to event_loop thread As per virEventRunDefaultImpl() documentation, this function will block forever if there are no registered event handlers. This leads to Collectd is unable to correctly stop event_loop thread if libvirtd was restarted. Added empty timeout callback to fix this. --- src/virt.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/virt.c b/src/virt.c index 933b59ec..6a919929 100644 --- a/src/virt.c +++ b/src/virt.c @@ -2203,6 +2203,9 @@ static int domain_lifecycle_event_cb(__attribute__((unused)) virConnectPtr con_, return 0; } +static void virt_eventloop_timeout_cb(int timer ATTRIBUTE_UNUSED, + void *timer_info) {} + static int register_event_impl(void) { if (virEventRegisterDefaultImpl() < 0) { virErrorPtr err = virGetLastError(); @@ -2212,6 +2215,14 @@ static int register_event_impl(void) { return -1; } + if (virEventAddTimeout(CDTIME_T_TO_MS(plugin_get_interval()), + virt_eventloop_timeout_cb, NULL, NULL) < 0) { + virErrorPtr err = virGetLastError(); + ERROR(PLUGIN_NAME " plugin: virEventAddTimeout failed: %s", + err && err->message ? err->message : "Unknown error"); + return -1; + } + return 0; } -- 2.11.0