assert(m);
assert(!m->notify_socket_path);
- r = notify_socket_prepare(
+ r = notify_socket_prepare_full(
m->event,
SD_EVENT_PRIORITY_NORMAL - 5, /* Make sure we process sd_notify() before SIGCHLD for
* any worker, so that we always know the error number
* of a client before it exits. */
on_notify_socket,
m,
+ /* accept_fds = */ true,
&m->notify_socket_path,
- /* ret_event_source= */ NULL);
+ /* ret_event_source = */ NULL);
if (r < 0)
return log_error_errno(r, "Failed to prepare notify socket: %m");
SD_EVENT_PRIORITY_NORMAL,
manager_on_notify,
m,
- &m->notify_socket_path,
- /* ret_event_source= */ NULL);
+ &m->notify_socket_path);
if (r < 0)
return r;
* more interesting, "positive" information. */
on_notify_socket,
&child,
- &addr_string,
- /* ret_event_source= */ NULL);
+ &addr_string);
if (r < 0)
return log_error_errno(r, "Failed to prepare notify socket: %m");
_cleanup_(sd_event_source_disable_unrefp) sd_event_source *notify_event_source = NULL;
_cleanup_(pidref_done_sigkill_wait) PidRef child = PIDREF_NULL;
_cleanup_free_ char *addr_string = NULL;
- r = notify_socket_prepare(
+ r = notify_socket_prepare_full(
event,
SD_EVENT_PRIORITY_NORMAL-10, /* We want the notification message from the child before the SIGCHLD */
on_child_notify,
&child,
+ /* accept_fds = */ false,
&addr_string,
¬ify_event_source);
if (r < 0)
#include "socket-util.h"
#include "strv.h"
-int notify_socket_prepare(
+int notify_socket_prepare_full(
sd_event *event,
int64_t priority,
sd_event_io_handler_t handler,
void *userdata,
+ bool accept_fds,
char **ret_path,
sd_event_source **ret_event_source) {
if (r < 0)
log_debug_errno(r, "Failed to enable SO_PASSPIDFD on notification socket, ignoring: %m");
+ if (!accept_fds) {
+ /* since kernel v6.16 */
+ r = setsockopt_int(fd, SOL_SOCKET, SO_PASSRIGHTS, false);
+ if (r < 0)
+ log_debug_errno(r, "Failed to disable SO_PASSRIGHTS on notification socket, ignoring: %m");
+ }
+
_cleanup_(sd_event_source_unrefp) sd_event_source *s = NULL;
r = sd_event_add_io(event, &s, fd, EPOLLIN, handler, userdata);
if (r < 0)
#include "forward.h"
-int notify_socket_prepare(
+int notify_socket_prepare_full(
sd_event *event,
int64_t priority,
sd_event_io_handler_t handler,
void *userdata,
+ bool accept_fds,
char **ret_path,
sd_event_source **ret_event_source);
+static inline int notify_socket_prepare(
+ sd_event *event,
+ int64_t priority,
+ sd_event_io_handler_t handler,
+ void *userdata,
+ char **ret_path) {
+
+ return notify_socket_prepare_full(event, priority, handler, userdata, false, ret_path, NULL);
+}
+
int notify_recv_with_fds(
int fd,
char **ret_text,
SD_EVENT_PRIORITY_NORMAL - 5,
helper_on_notify,
ctx,
- &bind_name,
- /* ret_event_source= */ NULL);
+ &bind_name);
if (r < 0)
return log_error_errno(r, "Failed to prepare notify socket: %m");
SD_EVENT_PRIORITY_NORMAL,
manager_on_notify,
m,
- &m->notify_socket_path,
- /* ret_event_source= */ NULL);
+ &m->notify_socket_path);
if (r < 0)
return r;
.pidref = PIDREF_NULL,
};
_cleanup_free_ char *path = NULL;
- ASSERT_OK(notify_socket_prepare(e, SD_EVENT_PRIORITY_NORMAL - 10, on_recv, &c, &path, /* ret_event_source= */ NULL));
+ ASSERT_OK(notify_socket_prepare_full(e, SD_EVENT_PRIORITY_NORMAL - 10, on_recv, &c, true, &path, NULL));
ASSERT_OK(sigprocmask_many(SIG_BLOCK, NULL, SIGCHLD));
EVENT_PRIORITY_WORKER_NOTIFY,
on_worker_notify,
manager,
- &manager->worker_notify_socket_path,
- /* ret_event_source= */ NULL);
+ &manager->worker_notify_socket_path);
if (r < 0)
return log_error_errno(r, "Failed to prepare worker notification socket: %m");