diff options
author | Giuseppe Scrivano <gscrivan@redhat.com> | 2018-08-29 10:01:45 +0200 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-08-29 16:25:20 +0000 |
commit | 1789242933ddbc3e4a29662f5218b5b94ee30863 (patch) | |
tree | cf9a0b2106f66446bef638fb1fc7860fd27c2972 /pkg/rootless/rootless_linux.c | |
parent | eb5fdebc84e59f8645218f8fdfd6e6a8136cfa43 (diff) | |
download | podman-1789242933ddbc3e4a29662f5218b5b94ee30863.tar.gz podman-1789242933ddbc3e4a29662f5218b5b94ee30863.tar.bz2 podman-1789242933ddbc3e4a29662f5218b5b94ee30863.zip |
rootless: add new function to join existing namespace
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Closes: #1371
Approved by: rhatdan
Diffstat (limited to 'pkg/rootless/rootless_linux.c')
-rw-r--r-- | pkg/rootless/rootless_linux.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/pkg/rootless/rootless_linux.c b/pkg/rootless/rootless_linux.c index 1b98f76eb..e894328ce 100644 --- a/pkg/rootless/rootless_linux.c +++ b/pkg/rootless/rootless_linux.c @@ -83,7 +83,37 @@ get_cmd_line_args (pid_t pid) } int -reexec_in_user_namespace(int ready) +reexec_userns_join (int userns) +{ + pid_t ppid = getpid (); + char uid[16]; + char **argv; + int pid; + + sprintf (uid, "%d", geteuid ()); + + argv = get_cmd_line_args (ppid); + if (argv == NULL) + _exit (EXIT_FAILURE); + + pid = fork (); + if (pid) + return pid; + + setenv ("_LIBPOD_USERNS_CONFIGURED", "init", 1); + setenv ("_LIBPOD_ROOTLESS_UID", uid, 1); + + if (setns (userns, 0) < 0) + _exit (EXIT_FAILURE); + close (userns); + + execvp (argv[0], argv); + + _exit (EXIT_FAILURE); +} + +int +reexec_in_user_namespace (int ready) { int ret; pid_t pid; |