]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-manager: do not free device monitor when asked to terminate
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 20 Mar 2025 08:22:13 +0000 (17:22 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 2 Apr 2025 14:24:35 +0000 (23:24 +0900)
Otherwise, if a worker process exited abnormally, the manager cannot
broadcast the kernel event assigned to the worker.

src/udev/udev-manager.c

index 8648fad1264032eb31b98316940d717bbf26c9fb..dd6a2494736961925c93a8e00636549af8fa69a5 100644 (file)
@@ -236,7 +236,11 @@ void manager_exit(Manager *manager) {
         manager->inotify_event = sd_event_source_disable_unref(manager->inotify_event);
         manager->inotify_fd = safe_close(manager->inotify_fd);
 
-        manager->monitor = sd_device_monitor_unref(manager->monitor);
+        /* Disable the device monitor but do not free device monitor, as it may be used when a worker failed,
+         * and the manager needs to broadcast the kernel event assigned to the worker to libudev listeners.
+         * Note, hwere we cannot use sd_device_monitor_stop(), as it changes the multicast group of the socket. */
+        (void) sd_event_source_set_enabled(sd_device_monitor_get_event_source(manager->monitor), SD_EVENT_OFF);
+        (void) sd_device_monitor_detach_event(manager->monitor);
 
         /* discard queued events and kill workers */
         event_queue_cleanup(manager, EVENT_QUEUED);