From 686117e5b0c313ae2be0150ad6a2ac989b38c064 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 10 Nov 2025 02:44:13 +0100 Subject: [PATCH 1/3] process-util: prefix FORK_PID_ONLY with _ to signify it is internal --- src/basic/process-util.c | 6 +++--- src/basic/process-util.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/basic/process-util.c b/src/basic/process-util.c index de97843816..35d3f8bfd9 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -1662,7 +1662,7 @@ int pidref_safe_fork_full( } if (ret_pid) { - if (FLAGS_SET(flags, FORK_PID_ONLY)) + if (FLAGS_SET(flags, _FORK_PID_ONLY)) *ret_pid = PIDREF_MAKE_FROM_PID(pid); else { r = pidref_set_pid(ret_pid, pid); @@ -1840,7 +1840,7 @@ int pidref_safe_fork_full( freeze(); if (ret_pid) { - if (FLAGS_SET(flags, FORK_PID_ONLY)) + if (FLAGS_SET(flags, _FORK_PID_ONLY)) *ret_pid = PIDREF_MAKE_FROM_PID(getpid_cached()); else { r = pidref_set_self(ret_pid); @@ -1869,7 +1869,7 @@ int safe_fork_full( * a pidref to the caller. */ assert(!FLAGS_SET(flags, FORK_DETACH) || !ret_pid); - r = pidref_safe_fork_full(name, stdio_fds, except_fds, n_except_fds, flags|FORK_PID_ONLY, ret_pid ? &pidref : NULL); + r = pidref_safe_fork_full(name, stdio_fds, except_fds, n_except_fds, flags|_FORK_PID_ONLY, ret_pid ? &pidref : NULL); if (r < 0 || !ret_pid) return r; diff --git a/src/basic/process-util.h b/src/basic/process-util.h index b3ccb2dc35..66ec4fa031 100644 --- a/src/basic/process-util.h +++ b/src/basic/process-util.h @@ -187,7 +187,8 @@ typedef enum ForkFlags { FORK_NEW_NETNS = 1 << 20, /* Run child in its own network namespace 💣 DO NOT USE IN THREADED PROGRAMS! 💣 */ FORK_NEW_PIDNS = 1 << 21, /* Run child in its own PID namespace 💣 DO NOT USE IN THREADED PROGRAMS! 💣 */ FORK_FREEZE = 1 << 22, /* Don't return in child, just call freeze() instead */ - FORK_PID_ONLY = 1 << 23, /* Don't open a pidfd referencing the child process */ + + _FORK_PID_ONLY = 1 << 23, /* Don't open a pidfd referencing the child process */ } ForkFlags; int pidref_safe_fork_full( From d9f993dd862b7f34b1072a2a3f689092c4425a23 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 10 Nov 2025 02:55:40 +0100 Subject: [PATCH 2/3] hostname-setup: prefix helper process name with "sd-" --- src/shared/hostname-setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/hostname-setup.c b/src/shared/hostname-setup.c index 4e977eed12..9e83445040 100644 --- a/src/shared/hostname-setup.c +++ b/src/shared/hostname-setup.c @@ -377,7 +377,7 @@ int pidref_gethostname_full(PidRef *pidref, GetHostnameFlags flags, char **ret) return -errno; _cleanup_(pidref_done_sigkill_wait) PidRef child = PIDREF_NULL; - r = pidref_safe_fork("(gethostname)", FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGKILL, &child); + r = pidref_safe_fork("(sd-gethostname)", FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGKILL, &child); if (r < 0) return r; if (r == 0) { From 1be6068c48946547fa2b136022382a09dbddb584 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 10 Nov 2025 03:02:47 +0100 Subject: [PATCH 3/3] notify: raise log level for safe_fork() --- src/notify/notify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/notify/notify.c b/src/notify/notify.c index 3035c9f6cf..270d1b1f9a 100644 --- a/src/notify/notify.c +++ b/src/notify/notify.c @@ -520,7 +520,7 @@ static int action_fork(char *const *_command) { /* stdio_fds= */ (const int[]) { -EBADF, -EBADF, STDERR_FILENO }, /* except_fds= */ NULL, /* n_except_fds= */ 0, - /* flags= */ FORK_REARRANGE_STDIO, + /* flags= */ FORK_REARRANGE_STDIO|FORK_LOG, &child); if (r < 0) return log_error_errno(r, "Failed to fork child in order to execute '%s': %m", c);