udev: try again to create /run/udev/queue when queueing the next event

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.
This commit is contained in:
Yu Watanabe
2025-04-27 09:45:39 +09:00
parent d93292bc59
commit 17b43e213b
2 changed files with 12 additions and 11 deletions
+11 -11
View 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;
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.");
return log_warning_errno(errno, "Failed to unlink /run/udev/queue: %m");
}
log_debug("No events are queued, removed /run/udev/queue.");
manager->queue_file_created = false;
return 0;
}
+1
View 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;