From cff85857c765cbb1b85decb6582583d4f209c683 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 1 Apr 2025 15:36:45 +0900 Subject: [PATCH] udev: disable timer event source for cleaning up idle workers when no worker exists No functional change, as the timer event does nothing when there are no workers. --- src/udev/udev-manager.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/udev/udev-manager.c b/src/udev/udev-manager.c index 891a48ad0cd..958d3daa81a 100644 --- a/src/udev/udev-manager.c +++ b/src/udev/udev-manager.c @@ -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); -- 2.47.3