mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 08:25:20 +09:00
notify-recv: optionally return event source from notify_socket_prepare()
This commit is contained in:
@@ -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");
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user