]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: adjust event source priorities 37023/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 27 Mar 2025 04:52:53 +0000 (13:52 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 8 Apr 2025 19:26:09 +0000 (04:26 +0900)
src/udev/udev-manager.c
src/udev/udev-manager.h
src/udev/udev-watch.c

index 6dd62d35e65e738e4246cc7ee6381bc42505e54f..13ae360aa9f3d09cc0e24b4eb5e5c3744797e3fd 100644 (file)
@@ -189,6 +189,10 @@ static int worker_new(Worker **ret, Manager *manager, sd_device_monitor *worker_
         if (r < 0)
                 return r;
 
+        r = sd_event_source_set_priority(worker->child_event_source, EVENT_PRIORITY_WORKER_SIGCHLD);
+        if (r < 0)
+                return r;
+
         r = hashmap_ensure_put(&manager->workers, &worker_hash_op, &worker->pidref, worker);
         if (r < 0)
                 return r;
@@ -1123,6 +1127,10 @@ static int manager_start_device_monitor(Manager *manager) {
         if (r < 0)
                 return log_error_errno(r, "Failed to start device monitor: %m");
 
+        r = sd_event_source_set_priority(sd_device_monitor_get_event_source(manager->monitor), EVENT_PRIORITY_DEVICE_MONITOR);
+        if (r < 0)
+                return log_error_errno(r, "Failed to set priority to device monitor: %m");
+
         return 0;
 }
 
@@ -1134,7 +1142,7 @@ static int manager_start_worker_notify(Manager *manager) {
 
         r = notify_socket_prepare(
                         manager->event,
-                        SD_EVENT_PRIORITY_NORMAL,
+                        EVENT_PRIORITY_WORKER_NOTIFY,
                         on_worker_notify,
                         manager,
                         &manager->worker_notify_socket_path);
index 16a558e7b869b45c40974e75b888553a23d4d798..9467508848f0d3d33d702e1b26ee48de4c06732d 100644 (file)
 #include "udev-ctrl.h"
 #include "udev-def.h"
 
+/* This must have a higher priority than the worker notification, to make IN_IGNORED event received earlier
+ * than notifications about requests of adding/removing inotify watches. */
+#define EVENT_PRIORITY_INOTIFY_WATCH  (SD_EVENT_PRIORITY_NORMAL - 30)
+/* This must have a higher priority than the worker SIGCHLD event, to make notifications about completions of
+ * processing events received before SIGCHLD. */
+#define EVENT_PRIORITY_WORKER_NOTIFY  (SD_EVENT_PRIORITY_NORMAL - 20)
+/* This should have a higher priority than other events, especially timer events about killing long running
+ * worker processes or idle worker processes. */
+#define EVENT_PRIORITY_WORKER_SIGCHLD (SD_EVENT_PRIORITY_NORMAL - 10)
+/* This should have a lower priority to make signal and timer event sources processed earlier. */
+#define EVENT_PRIORITY_DEVICE_MONITOR (SD_EVENT_PRIORITY_NORMAL + 10)
+
 typedef struct Event Event;
 typedef struct UdevRules UdevRules;
 typedef struct Worker Worker;
index 7adde732df30210a81838c5d064f6c50aa55d008..506c3e0835b7f06c628a205108e57f51fe6135a1 100644 (file)
@@ -386,6 +386,10 @@ int manager_start_inotify(Manager *manager) {
         if (r < 0)
                 return log_error_errno(r, "Failed to create inotify event source: %m");
 
+        r = sd_event_source_set_priority(s, EVENT_PRIORITY_INOTIFY_WATCH);
+        if (r < 0)
+                return log_error_errno(r, "Failed to set priority to inotify event source: %m");
+
         (void) sd_event_source_set_description(s, "manager-inotify");
 
         manager->inotify_event = TAKE_PTR(s);