From: Pavel Rochnyack Date: Fri, 24 May 2019 10:48:18 +0000 (+0700) Subject: virt plugin: Added timeout to event_loop thread X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c09f8ee768891aee1222ad0a3e19c66b099cc973;p=collectd.git 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. --- 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; }