From: Lennart Poettering Date: Tue, 13 May 2025 08:00:22 +0000 (+0200) Subject: notify-recv: optionally return event source from notify_socket_prepare() X-Git-Tag: v258-rc1~633^2~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0da0b3f81df423882e2eff67182b1bf0c91e3009;p=thirdparty%2Fsystemd.git notify-recv: optionally return event source from notify_socket_prepare() --- diff --git a/src/home/homed-manager.c b/src/home/homed-manager.c index 44468e04ea0..ec3bfdab995 100644 --- a/src/home/homed-manager.c +++ b/src/home/homed-manager.c @@ -1154,7 +1154,8 @@ static int manager_listen_notify(Manager *m) { * of a client before it exits. */ on_notify_socket, m, - &m->notify_socket_path); + &m->notify_socket_path, + /* ret_event_source= */ NULL); if (r < 0) return log_error_errno(r, "Failed to prepare notify socket: %m"); diff --git a/src/import/importd.c b/src/import/importd.c index 6390b76d545..45b5434ca06 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -724,7 +724,8 @@ static int manager_new(Manager **ret) { SD_EVENT_PRIORITY_NORMAL, manager_on_notify, m, - &m->notify_socket_path); + &m->notify_socket_path, + /* ret_event_source= */ NULL); if (r < 0) return r; diff --git a/src/notify/notify.c b/src/notify/notify.c index 6f924d719cc..4a0f88a40e9 100644 --- a/src/notify/notify.c +++ b/src/notify/notify.c @@ -513,7 +513,8 @@ static int action_fork(char *const *_command) { * more interesting, "positive" information. */ on_notify_socket, &child, - &addr_string); + &addr_string, + /* ret_event_source= */ NULL); if (r < 0) return log_error_errno(r, "Failed to prepare notify socket: %m"); diff --git a/src/shared/notify-recv.c b/src/shared/notify-recv.c index 0e64bdde04b..0169a6220c8 100644 --- a/src/shared/notify-recv.c +++ b/src/shared/notify-recv.c @@ -14,12 +14,12 @@ int notify_socket_prepare( int64_t priority, sd_event_io_handler_t handler, void *userdata, - char **ret_path) { + char **ret_path, + sd_event_source **ret_event_source) { int r; assert(event); - assert(ret_path); /* This creates an autobind AF_UNIX socket and adds an IO event source for the socket, which helps * prepare the notification socket used to communicate with worker processes. */ @@ -58,11 +58,17 @@ int notify_socket_prepare( (void) sd_event_source_set_description(s, "notify-socket"); - r = sd_event_source_set_floating(s, true); - if (r < 0) - return log_debug_errno(r, "Failed to make notification event source floating: %m"); + if (ret_event_source) + *ret_event_source = TAKE_PTR(s); + else { + r = sd_event_source_set_floating(s, true); + if (r < 0) + return log_debug_errno(r, "Failed to make notification event source floating: %m"); + } + + if (ret_path) + *ret_path = TAKE_PTR(path); - *ret_path = TAKE_PTR(path); return 0; } diff --git a/src/shared/notify-recv.h b/src/shared/notify-recv.h index 24482fdf1d4..9035ad4872c 100644 --- a/src/shared/notify-recv.h +++ b/src/shared/notify-recv.h @@ -13,7 +13,8 @@ int notify_socket_prepare( int64_t priority, sd_event_io_handler_t handler, void *userdata, - char **ret_path); + char **ret_path, + sd_event_source **ret_event_source); int notify_recv_with_fds( int fd, diff --git a/src/sysupdate/sysupdate-transfer.c b/src/sysupdate/sysupdate-transfer.c index 0247864eca4..9ed55dd816e 100644 --- a/src/sysupdate/sysupdate-transfer.c +++ b/src/sysupdate/sysupdate-transfer.c @@ -1062,7 +1062,8 @@ static int run_callout( SD_EVENT_PRIORITY_NORMAL - 5, helper_on_notify, ctx, - &bind_name); + &bind_name, + /* ret_event_source= */ NULL); if (r < 0) return log_error_errno(r, "Failed to prepare notify socket: %m"); diff --git a/src/sysupdate/sysupdated.c b/src/sysupdate/sysupdated.c index e75bfb4a16b..9a8402482c9 100644 --- a/src/sysupdate/sysupdated.c +++ b/src/sysupdate/sysupdated.c @@ -1740,7 +1740,8 @@ static int manager_new(Manager **ret) { SD_EVENT_PRIORITY_NORMAL, manager_on_notify, m, - &m->notify_socket_path); + &m->notify_socket_path, + /* ret_event_source= */ NULL); if (r < 0) return r; diff --git a/src/test/test-notify-recv.c b/src/test/test-notify-recv.c index f4f96a74e21..3178b9da315 100644 --- a/src/test/test-notify-recv.c +++ b/src/test/test-notify-recv.c @@ -87,7 +87,7 @@ TEST(notify_socket_prepare) { .pidref = PIDREF_NULL, }; _cleanup_free_ char *path = NULL; - ASSERT_OK(notify_socket_prepare(e, SD_EVENT_PRIORITY_NORMAL - 10, on_recv, &c, &path)); + ASSERT_OK(notify_socket_prepare(e, SD_EVENT_PRIORITY_NORMAL - 10, on_recv, &c, &path, /* ret_event_source= */ NULL)); ASSERT_OK(sigprocmask_many(SIG_BLOCK, NULL, SIGCHLD)); diff --git a/src/udev/udev-manager.c b/src/udev/udev-manager.c index fe26496618d..2cd40f1d1d1 100644 --- a/src/udev/udev-manager.c +++ b/src/udev/udev-manager.c @@ -1227,7 +1227,8 @@ static int manager_start_worker_notify(Manager *manager) { EVENT_PRIORITY_WORKER_NOTIFY, on_worker_notify, manager, - &manager->worker_notify_socket_path); + &manager->worker_notify_socket_path, + /* ret_event_source= */ NULL); if (r < 0) return log_error_errno(r, "Failed to prepare worker notification socket: %m");