From: Christian Brauner Date: Thu, 9 May 2019 15:09:51 +0000 (+0200) Subject: namespace: support CLONE_PIDFD with lxc_clone() X-Git-Tag: lxc-3.2.0~62^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=33258b95fc1573b68b3dfae7a1d41696293b828d;p=thirdparty%2Flxc.git namespace: support CLONE_PIDFD with lxc_clone() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 2515c881e..0fbbbfa79 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -4419,7 +4419,7 @@ int userns_exec_full(struct lxc_conf *conf, int (*fn)(void *), void *data, d.p[1] = p[1]; /* Clone child in new user namespace. */ - pid = lxc_clone(run_userns_fn, &d, CLONE_NEWUSER); + pid = lxc_clone(run_userns_fn, &d, CLONE_NEWUSER, NULL); if (pid < 0) { ERROR("Failed to clone process in new user namespace"); goto on_error; diff --git a/src/lxc/namespace.c b/src/lxc/namespace.c index e22d9a4bf..59fba412d 100644 --- a/src/lxc/namespace.c +++ b/src/lxc/namespace.c @@ -54,7 +54,7 @@ static int do_clone(void *arg) } #define __LXC_STACK_SIZE 4096 -pid_t lxc_clone(int (*fn)(void *), void *arg, int flags) +pid_t lxc_clone(int (*fn)(void *), void *arg, int flags, int *pidfd) { size_t stack_size; pid_t ret; @@ -66,9 +66,9 @@ pid_t lxc_clone(int (*fn)(void *), void *arg, int flags) stack_size = __LXC_STACK_SIZE; #ifdef __ia64__ - ret = __clone2(do_clone, stack, stack_size, flags | SIGCHLD, &clone_arg); + ret = __clone2(do_clone, stack, stack_size, flags | SIGCHLD, &clone_arg, pidfd); #else - ret = clone(do_clone, stack + stack_size, flags | SIGCHLD, &clone_arg); + ret = clone(do_clone, stack + stack_size, flags | SIGCHLD, &clone_arg, pidfd); #endif if (ret < 0) SYSERROR("Failed to clone (%#x)", flags); diff --git a/src/lxc/namespace.h b/src/lxc/namespace.h index ab583da76..f2c2ad82c 100644 --- a/src/lxc/namespace.h +++ b/src/lxc/namespace.h @@ -133,7 +133,7 @@ int clone(int (*fn)(void *), void *child_stack, * - should call lxc_raw_getpid(): * The child should use lxc_raw_getpid() to retrieve its pid. */ -extern pid_t lxc_clone(int (*fn)(void *), void *arg, int flags); +extern pid_t lxc_clone(int (*fn)(void *), void *arg, int flags, int *pidfd); extern int lxc_namespace_2_cloneflag(const char *namespace); extern int lxc_namespace_2_ns_idx(const char *namespace); diff --git a/src/lxc/start.c b/src/lxc/start.c index 34798292c..48ba2b424 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -1735,7 +1735,7 @@ static int lxc_spawn(struct lxc_handler *handler) pid_t attacher_pid; attacher_pid = lxc_clone(do_share_ns, handler, - CLONE_VFORK | CLONE_VM | CLONE_FILES); + CLONE_VFORK | CLONE_VM | CLONE_FILES, NULL); if (attacher_pid < 0) { SYSERROR(LXC_CLONE_ERROR); goto out_delete_net; diff --git a/src/lxc/storage/nbd.c b/src/lxc/storage/nbd.c index ab4f752c9..dc68ee623 100644 --- a/src/lxc/storage/nbd.c +++ b/src/lxc/storage/nbd.c @@ -266,7 +266,7 @@ static bool clone_attach_nbd(const char *nbd, const char *path) data.nbd = nbd; data.path = path; - pid = lxc_clone(do_attach_nbd, &data, CLONE_NEWPID); + pid = lxc_clone(do_attach_nbd, &data, CLONE_NEWPID, NULL); if (pid < 0) return false; diff --git a/src/lxc/tools/lxc_unshare.c b/src/lxc/tools/lxc_unshare.c index 1bc04ce92..421d92c2a 100644 --- a/src/lxc/tools/lxc_unshare.c +++ b/src/lxc/tools/lxc_unshare.c @@ -388,7 +388,7 @@ int main(int argc, char *argv[]) start_arg.want_hostname = my_args.want_hostname; start_arg.want_default_mounts = my_args.want_default_mounts; - pid = lxc_clone(do_start, &start_arg, my_args.flags); + pid = lxc_clone(do_start, &start_arg, my_args.flags, NULL); if (pid < 0) { ERROR("Failed to clone"); free_ifname_list();