]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: disable timer event source for cleaning up idle workers when no worker exists
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 1 Apr 2025 06:36:45 +0000 (15:36 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 1 Apr 2025 06:55:52 +0000 (15:55 +0900)
No functional change, as the timer event does nothing when there are no
workers.

src/udev/udev-manager.c

index 891a48ad0cd941a8632ade26c30b965c9bbe095c..958d3daa81a872b3c38423f64e11307a6cbeaba1 100644 (file)
@@ -1068,6 +1068,7 @@ static int on_sigchld(sd_event_source *s, const siginfo_t *si, void *userdata) {
 
 static int on_post(sd_event_source *s, void *userdata) {
         Manager *manager = ASSERT_PTR(userdata);
+        int r;
 
         if (manager->events) {
                 /* Try to process pending events if idle workers exist. Why is this necessary?
@@ -1089,14 +1090,27 @@ static int on_post(sd_event_source *s, void *userdata) {
 
         if (!hashmap_isempty(manager->workers)) {
                 /* There are idle workers */
-                (void) event_reset_time_relative(manager->event, &manager->kill_workers_event,
-                                                 CLOCK_MONOTONIC, 3 * USEC_PER_SEC, USEC_PER_SEC,
-                                                 on_kill_workers_event, manager,
-                                                 0, "kill-workers-event", false);
+                r = event_reset_time_relative(
+                                manager->event,
+                                &manager->kill_workers_event,
+                                CLOCK_MONOTONIC,
+                                3 * USEC_PER_SEC,
+                                USEC_PER_SEC,
+                                on_kill_workers_event,
+                                manager,
+                                SD_EVENT_PRIORITY_NORMAL,
+                                "kill-workers-event",
+                                /* force_reset = */ false);
+                if (r < 0)
+                        log_warning_errno(r, "Failed to enable timer event source for cleaning up idle workers, ignoring: %m");
+
                 return 1;
         }
 
         /* There are no idle workers. */
+        r = sd_event_source_set_enabled(manager->kill_workers_event, SD_EVENT_OFF);
+        if (r < 0)
+                log_warning_errno(r, "Failed to disable timer event source for cleaning up idle workers, ignoring: %m");
 
         if (manager->exit)
                 return sd_event_exit(manager->event, 0);