]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
notify-recv: optionally return event source from notify_socket_prepare()
authorLennart Poettering <lennart@poettering.net>
Tue, 13 May 2025 08:00:22 +0000 (10:00 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 13 May 2025 12:42:33 +0000 (14:42 +0200)
src/home/homed-manager.c
src/import/importd.c
src/notify/notify.c
src/shared/notify-recv.c
src/shared/notify-recv.h
src/sysupdate/sysupdate-transfer.c
src/sysupdate/sysupdated.c
src/test/test-notify-recv.c
src/udev/udev-manager.c

index 44468e04ea021cafdb6feabeede9658144c41b53..ec3bfdab995d72434da37ddc3a44c33760df0d3a 100644 (file)
@@ -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");
 
index 6390b76d545a31dfd6f86981c50f29c0795bb356..45b5434ca0600f202dedc8585ecb0cf836d3a201 100644 (file)
@@ -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;
 
index 6f924d719cc326bef4ab35744549a3105b12c1e7..4a0f88a40e9b1d500d5094826b972b14185d0029 100644 (file)
@@ -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");
 
index 0e64bdde04b4e76456e97a81dca171b7e2c96422..0169a6220c8db42726ef3e9e1cc1f15d45e085d7 100644 (file)
@@ -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;
 }
 
index 24482fdf1d4e74835f1219e4c85a58e7be6b341d..9035ad4872ce1dd7aa6601af3f61a80b4680315e 100644 (file)
@@ -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,
index 0247864eca448ead1890f32ff065111c2286a0b9..9ed55dd816e2045352f86e170354c55683b79a54 100644 (file)
@@ -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");
 
index e75bfb4a16b7bd6a4763c6f95ada275d09c558ae..9a8402482c91a002857cd4243cb54945dca3ab9c 100644 (file)
@@ -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;
 
index f4f96a74e2111d7aacf5aef9d0492d59c762feeb..3178b9da31522e4b3916f3b6d81499333dfcf146 100644 (file)
@@ -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));
 
index fe26496618d4ec90086bfd09cb9f0efd0a3eb243..2cd40f1d1d119383b2b8309fa6a2a19ea75e05e3 100644 (file)
@@ -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");