]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
process-util: add new FORK_NEW_MOUNTNS flag to safe_fork()
authorLennart Poettering <lennart@poettering.net>
Fri, 29 Dec 2017 17:52:20 +0000 (18:52 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 4 Jan 2018 12:27:27 +0000 (13:27 +0100)
That way we can move one more code location to use safe_fork()

src/basic/process-util.c
src/basic/process-util.h
src/shared/dissect-image.c

index 69f1d1e7b4e09f7eac0e7cde247fc083cf446217..d74813dada4276bc56a9e01495be72c561fd8804 100644 (file)
@@ -1199,7 +1199,10 @@ int safe_fork_full(
                 if (sigprocmask(SIG_SETMASK, &ss, &saved_ss) < 0)
                         return log_full_errno(prio, errno, "Failed to set signal mask: %m");
 
-        pid = fork();
+        if (flags & FORK_NEW_MOUNTNS)
+                pid = raw_clone(SIGCHLD|CLONE_NEWNS);
+        else
+                pid = fork();
         if (pid < 0) {
                 r = -errno;
 
index ba247a089d94562054d28e83873a91e6fde28fb2..fdb1790b2ecb65a188439905ad3047899542f39b 100644 (file)
@@ -168,6 +168,7 @@ typedef enum ForkFlags {
         FORK_REOPEN_LOG    = 1U << 4,
         FORK_LOG           = 1U << 5,
         FORK_WAIT          = 1U << 6,
+        FORK_NEW_MOUNTNS   = 1U << 7,
 } ForkFlags;
 
 int safe_fork_full(const char *name, const int except_fds[], size_t n_except_fds, ForkFlags flags, pid_t *ret_pid);
index 05a9f37da38e374d053572e1b3c4d00036022fbd..35b2c56555b307d7b13794a92b1ba6939004b9e0 100644 (file)
@@ -1259,18 +1259,10 @@ int dissected_image_acquire_metadata(DissectedImage *m) {
         if (r < 0)
                 goto finish;
 
-        child = raw_clone(SIGCHLD|CLONE_NEWNS);
-        if (child < 0) {
-                r = -errno;
+        r = safe_fork("(sd-dissect)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_NEW_MOUNTNS, &child);
+        if (r < 0)
                 goto finish;
-        }
-
-        if (child == 0) {
-
-                (void) reset_all_signal_handlers();
-                (void) reset_signal_mask();
-                assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0);
-
+        if (r == 0) {
                 /* Make sure we never propagate to the host */
                 if (mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL) < 0)
                         _exit(EXIT_FAILURE);