]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
process-util: add option for cloning with CLONE_NEWUSER
authorLennart Poettering <lennart@poettering.net>
Tue, 27 Apr 2021 15:00:07 +0000 (17:00 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 7 May 2021 20:43:42 +0000 (22:43 +0200)
This is useful for allocating a userns fd later on for use in idmapped
mounts.

src/basic/process-util.c
src/basic/process-util.h

index 1b8e663efea51456ef504b4516d722e13120f482..4cd8287bb004d25744064c25aa0a939a05d6981d 100644 (file)
@@ -1306,8 +1306,10 @@ int safe_fork_full(
                 saved_ssp = &saved_ss;
         }
 
-        if (flags & FORK_NEW_MOUNTNS)
-                pid = raw_clone(SIGCHLD|CLONE_NEWNS);
+        if ((flags & (FORK_NEW_MOUNTNS|FORK_NEW_USERNS)) != 0)
+                pid = raw_clone(SIGCHLD|
+                                (FLAGS_SET(flags, FORK_NEW_MOUNTNS) ? CLONE_NEWNS : 0) |
+                                (FLAGS_SET(flags, FORK_NEW_USERNS) ? CLONE_NEWUSER : 0));
         else
                 pid = fork();
         if (pid < 0)
index 8ce6d60f39b066330217ea7eecfd36df15a81dcb..0e064de85e838572a277f081f98b65d83a18399f 100644 (file)
@@ -165,6 +165,7 @@ typedef enum ForkFlags {
         FORK_RLIMIT_NOFILE_SAFE = 1 << 10, /* Set RLIMIT_NOFILE soft limit to 1K for select() compat */
         FORK_STDOUT_TO_STDERR   = 1 << 11, /* Make stdout a copy of stderr */
         FORK_FLUSH_STDIO        = 1 << 12, /* fflush() stdout (and stderr) before forking */
+        FORK_NEW_USERNS         = 1 << 13, /* Run child in its own user namespace */
 } ForkFlags;
 
 int safe_fork_full(const char *name, const int except_fds[], size_t n_except_fds, ForkFlags flags, pid_t *ret_pid);