From: Lennart Poettering Date: Wed, 20 Oct 2021 11:14:11 +0000 (+0200) Subject: basic: move freeze() from shared/exec-util.h to basic/process-util.h X-Git-Tag: v250-rc1~446^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8ddefb8eef412f888b230588ebde832fc50dc781;p=thirdparty%2Fsystemd.git basic: move freeze() from shared/exec-util.h to basic/process-util.h That way we can use it in other code from basic/. It fits into both headers equally well or badly, hence let's just move this one function. --- diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 5e7ed06ea55..fce96dd5ebd 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 7e87f5a17c7..451d0a5ff40 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 042db7db3f5..fd0d95c5301 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 05f8e1af835..21d28608f99 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_;