]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: try again to create /run/udev/queue when queueing the next event
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 26 Apr 2025 06:53:48 +0000 (15:53 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 27 Apr 2025 00:45:39 +0000 (09:45 +0900)
This is mostly a paranoia, but if we failed to create /run/udev/queue
for some reasons on queueing an event, previously we would never create
the file until once the queue became empty. This makes in such case we
try to create the file again when queueing the next event.

src/udev/udev-manager.c
src/udev/udev-manager.h

index 8f96cad6590c0467ca6c09763da29ff5f174765f..0c59c172e0c9ebfab9c80c57562594f3b31c3b95 100644 (file)
@@ -852,16 +852,17 @@ static int event_queue_insert(Manager *manager, sd_device *dev) {
                 .state = EVENT_QUEUED,
         };
 
-        if (!manager->events) {
+        LIST_APPEND(event, manager->events, event);
+        log_device_uevent(dev, "Device is queued");
+
+        if (!manager->queue_file_created) {
                 r = touch("/run/udev/queue");
                 if (r < 0)
                         log_warning_errno(r, "Failed to touch /run/udev/queue, ignoring: %m");
+                else
+                        manager->queue_file_created = true;
         }
 
-        LIST_APPEND(event, manager->events, event);
-
-        log_device_uevent(dev, "Device is queued");
-
         return 0;
 }
 
@@ -1155,13 +1156,12 @@ static int manager_unlink_queue_file(Manager *manager) {
 
         /* 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)
-                        return 0;
-
-                return log_warning_errno(errno, "Failed to unlink /run/udev/queue: %m");
-        }
+                if (errno != ENOENT)
+                        return log_warning_errno(errno, "Failed to unlink /run/udev/queue: %m");
+        } else
+                log_debug("No events are queued, removed /run/udev/queue.");
 
-        log_debug("No events are queued, removed /run/udev/queue.");
+        manager->queue_file_created = false;
         return 0;
 }
 
index 95262651543f3b9747d9a1e3b07a547dbdf2f412..875f6f955afff67068d9d21650a2c9f218570a5c 100644 (file)
@@ -61,6 +61,7 @@ typedef struct Manager {
         UdevConfig config_by_control;
         UdevConfig config;
 
+        bool queue_file_created;
         bool stop_exec_queue;
         bool exit;
 } Manager;