]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: remove /run/udev/queue in on_post()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 13 Mar 2022 12:22:57 +0000 (21:22 +0900)
committerLennart Poettering <lennart@poettering.net>
Thu, 24 Mar 2022 15:19:36 +0000 (16:19 +0100)
When the last queued event is processed, information about subsequent
events may be already queued in the netlink socket of sd-device-monitor.
In that case, previously we once removed /run/udev/queue and touch the
file soon later, and `udevadm settle` mistakenly considered all events
are processed.

To mitigate such situation, this makes /run/udev/queue removed in on_post().

src/udev/udevd.c

index 6bb9eeb4bb37e45168783d3e56bce3290ca108ac..8389c39f652f806ea88185a82e06a7dfc1b86393 100644 (file)
@@ -171,12 +171,6 @@ static Event *event_free(Event *event) {
         if (event->worker)
                 event->worker->event = NULL;
 
-        /* only clean up the queue from the process that created it */
-        if (LIST_IS_EMPTY(event->manager->events) &&
-            event->manager->pid == getpid_cached())
-                if (unlink("/run/udev/queue") < 0 && errno != ENOENT)
-                        log_warning_errno(errno, "Failed to unlink /run/udev/queue, ignoring: %m");
-
         return mfree(event);
 }
 
@@ -1480,7 +1474,13 @@ static int on_post(sd_event_source *s, void *userdata) {
         if (!LIST_IS_EMPTY(manager->events))
                 return 1;
 
-        /* There are no pending events. Let's cleanup idle process. */
+        /* There are no queued events. Let's remove /run/udev/queue and clean up the idle processes. */
+
+        if (unlink("/run/udev/queue") < 0) {
+                if (errno != ENOENT)
+                        log_warning_errno(errno, "Failed to unlink /run/udev/queue, ignoring: %m");
+        } else
+                log_debug("No events are queued, removing /run/udev/queue.");
 
         if (!hashmap_isempty(manager->workers)) {
                 /* There are idle workers */