summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-07-23 11:34:00 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-07-23 11:39:45 +0200
commit45a68ed3073a006c44703acf2928be156805ef9f (patch)
tree47b390e17dab2415bf3525b71d1f5ab31bc37a07
parent3e24e8cd647478b3d161f1887785132e334e5df5 (diff)
downloadsystemd-45a68ed3073a006c44703acf2928be156805ef9f.tar.gz
Move freeze() into shared/
Library code should not call freeze(), this is something that should only be done by "application code", so moving it into shared/ is appropriate. The fallback to call _exit() is dropped: let's trust that the infinite loop is infinite.
-rw-r--r--src/basic/process-util.c24
-rw-r--r--src/basic/process-util.h2
-rw-r--r--src/libsystemd/sd-event/test-event.c1
-rw-r--r--src/shared/exec-util.c23
-rw-r--r--src/shared/exec-util.h2
-rw-r--r--src/shared/mount-util.c5
6 files changed, 28 insertions, 29 deletions
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index e325820584..ce4bfb783d 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -1037,30 +1037,6 @@ bool is_main_thread(void) {
return cached > 0;
}
-_noreturn_ void freeze(void) {
-
- log_close();
-
- /* Make sure nobody waits for us on a socket anymore */
- (void) close_all_fds(NULL, 0);
-
- 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();
-}
-
unsigned long personality_from_string(const char *p) {
int architecture;
diff --git a/src/basic/process-util.h b/src/basic/process-util.h
index b130c5ae02..a591fc32a4 100644
--- a/src/basic/process-util.h
+++ b/src/basic/process-util.h
@@ -82,8 +82,6 @@ int pid_from_same_root_fs(pid_t pid);
bool is_main_thread(void);
-_noreturn_ void freeze(void);
-
#ifndef PERSONALITY_INVALID
/* personality(7) documents that 0xffffffffUL is used for querying the
* current personality, hence let's use that here as error
diff --git a/src/libsystemd/sd-event/test-event.c b/src/libsystemd/sd-event/test-event.c
index 7ff1452e08..9b92dac650 100644
--- a/src/libsystemd/sd-event/test-event.c
+++ b/src/libsystemd/sd-event/test-event.c
@@ -5,6 +5,7 @@
#include "sd-event.h"
#include "alloc-util.h"
+#include "exec-util.h"
#include "fd-util.h"
#include "fs-util.h"
#include "log.h"
diff --git a/src/shared/exec-util.c b/src/shared/exec-util.c
index 68e896a8fa..42f6c4d75a 100644
--- a/src/shared/exec-util.c
+++ b/src/shared/exec-util.c
@@ -448,6 +448,29 @@ 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(NULL, 0);
+
+ 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 21d28608f9..05f8e1af83 100644
--- a/src/shared/exec-util.h
+++ b/src/shared/exec-util.h
@@ -47,6 +47,8 @@ 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_;
diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c
index 594efea989..cf8ca8d9d3 100644
--- a/src/shared/mount-util.c
+++ b/src/shared/mount-util.c
@@ -11,6 +11,7 @@
#include "alloc-util.h"
#include "dissect-image.h"
+#include "exec-util.h"
#include "extract-word.h"
#include "fd-util.h"
#include "fileio.h"
@@ -1010,11 +1011,9 @@ static int make_userns(uid_t uid_shift, uid_t uid_range) {
r = safe_fork("(sd-mkuserns)", FORK_CLOSE_ALL_FDS|FORK_DEATHSIG|FORK_NEW_USERNS, &pid);
if (r < 0)
return r;
- if (r == 0) {
+ if (r == 0)
/* Child. We do nothing here, just freeze until somebody kills us. */
freeze();
- _exit(EXIT_FAILURE);
- }
xsprintf(line, UID_FMT " " UID_FMT " " UID_FMT "\n", 0, uid_shift, uid_range);