if (pthread_create(&thread_data->event_loop_tid, NULL, event_loop_worker,
thread_data)) {
ERROR(PLUGIN_NAME " plugin: failed event loop thread creation");
+ virt_notif_thread_set_active(thread_data, 0);
virConnectDomainEventDeregisterAny(conn, thread_data->domain_event_cb_id);
+ thread_data->domain_event_cb_id = -1;
return -1;
}
/* stop event loop thread and deregister callback */
static void stop_event_loop(virt_notif_thread_t *thread_data) {
- /* stopping loop and de-registering event handler*/
- virt_notif_thread_set_active(thread_data, 0);
- if (conn != NULL && thread_data->domain_event_cb_id != -1)
- virConnectDomainEventDeregisterAny(conn, thread_data->domain_event_cb_id);
+ /* Stopping loop */
+ if (virt_notif_thread_is_active(thread_data)) {
+ virt_notif_thread_set_active(thread_data, 0);
+ if (pthread_join(notif_thread.event_loop_tid, NULL) != 0)
+ ERROR(PLUGIN_NAME " plugin: stopping notification thread failed");
+ }
- if (pthread_join(notif_thread.event_loop_tid, NULL) != 0)
- ERROR(PLUGIN_NAME " plugin: stopping notification thread failed");
+ /* ... and de-registering event handler */
+ if (conn != NULL && thread_data->domain_event_cb_id != -1) {
+ virConnectDomainEventDeregisterAny(conn, thread_data->domain_event_cb_id);
+ thread_data->domain_event_cb_id = -1;
+ }
}
static int persistent_domains_state_notification(void) {