diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 5e7ed06ea5..fce96dd5eb 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -1618,6 +1618,27 @@ bool invoked_as(char *argv[], const char *token) { return strstr(last_path_component(argv[0]), token); } +_noreturn_ void freeze(void) { + log_close(); + + /* Make sure nobody waits for us on a socket anymore */ + (void) close_all_fds_full(NULL, 0, false); + + sync(); + + /* Let's not freeze right away, but keep reaping zombies. */ + for (;;) { + siginfo_t si = {}; + + if (waitid(P_ALL, 0, &si, WEXITED) < 0 && errno != EINTR) + break; + } + + /* waitid() failed with an unexpected error, things are really borked. Freeze now! */ + for (;;) + pause(); +} + static const char *const ioprio_class_table[] = { [IOPRIO_CLASS_NONE] = "none", [IOPRIO_CLASS_RT] = "realtime", diff --git a/src/basic/process-util.h b/src/basic/process-util.h index 7e87f5a17c..451d0a5ff4 100644 --- a/src/basic/process-util.h +++ b/src/basic/process-util.h @@ -202,3 +202,5 @@ int pidfd_get_pid(int fd, pid_t *ret); int setpriority_closest(int priority); bool invoked_as(char *argv[], const char *token); + +_noreturn_ void freeze(void); diff --git a/src/shared/exec-util.c b/src/shared/exec-util.c index 042db7db3f..fd0d95c530 100644 --- a/src/shared/exec-util.c +++ b/src/shared/exec-util.c @@ -448,29 +448,6 @@ ExecCommandFlags exec_command_flags_from_string(const char *s) { return 1 << idx; } -_noreturn_ void freeze(void) { - log_close(); - - /* Make sure nobody waits for us on a socket anymore */ - (void) close_all_fds_full(NULL, 0, false); - - sync(); - - /* Let's not freeze right away, but keep reaping zombies. */ - for (;;) { - int r; - siginfo_t si = {}; - - r = waitid(P_ALL, 0, &si, WEXITED); - if (r < 0 && errno != EINTR) - break; - } - - /* waitid() failed with an unexpected error, things are really borked. Freeze now! */ - for (;;) - pause(); -} - int fexecve_or_execve(int executable_fd, const char *executable, char *const argv[], char *const envp[]) { #if ENABLE_FEXECVE execveat(executable_fd, "", argv, envp, AT_EMPTY_PATH); diff --git a/src/shared/exec-util.h b/src/shared/exec-util.h index 05f8e1af83..21d28608f9 100644 --- a/src/shared/exec-util.h +++ b/src/shared/exec-util.h @@ -47,8 +47,6 @@ extern const gather_stdout_callback_t gather_environment[_STDOUT_CONSUME_MAX]; const char* exec_command_flags_to_string(ExecCommandFlags i); ExecCommandFlags exec_command_flags_from_string(const char *s); -_noreturn_ void freeze(void); - int fexecve_or_execve(int executable_fd, const char *executable, char *const argv[], char *const envp[]); int fork_agent(const char *name, int except[], size_t n_except, pid_t *ret_pid, const char *path, ...) _sentinel_;