namespace: support CLONE_PIDFD with lxc_clone()

parent ded425a6
...@@ -4348,7 +4348,7 @@ int userns_exec_full(struct lxc_conf *conf, int (*fn)(void *), void *data, ...@@ -4348,7 +4348,7 @@ int userns_exec_full(struct lxc_conf *conf, int (*fn)(void *), void *data,
d.p[1] = p[1]; d.p[1] = p[1];
/* Clone child in new user namespace. */ /* 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) { if (pid < 0) {
ERROR("Failed to clone process in new user namespace"); ERROR("Failed to clone process in new user namespace");
goto on_error; goto on_error;
......
...@@ -54,7 +54,7 @@ static int do_clone(void *arg) ...@@ -54,7 +54,7 @@ static int do_clone(void *arg)
} }
#define __LXC_STACK_SIZE 4096 #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; size_t stack_size;
pid_t ret; pid_t ret;
...@@ -66,9 +66,9 @@ pid_t lxc_clone(int (*fn)(void *), void *arg, int flags) ...@@ -66,9 +66,9 @@ pid_t lxc_clone(int (*fn)(void *), void *arg, int flags)
stack_size = __LXC_STACK_SIZE; stack_size = __LXC_STACK_SIZE;
#ifdef __ia64__ #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 #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 #endif
if (ret < 0) if (ret < 0)
SYSERROR("Failed to clone (%#x)", flags); SYSERROR("Failed to clone (%#x)", flags);
......
...@@ -133,7 +133,7 @@ int clone(int (*fn)(void *), void *child_stack, ...@@ -133,7 +133,7 @@ int clone(int (*fn)(void *), void *child_stack,
* - should call lxc_raw_getpid(): * - should call lxc_raw_getpid():
* The child should use lxc_raw_getpid() to retrieve its pid. * 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_cloneflag(const char *namespace);
extern int lxc_namespace_2_ns_idx(const char *namespace); extern int lxc_namespace_2_ns_idx(const char *namespace);
......
...@@ -1705,7 +1705,7 @@ static int lxc_spawn(struct lxc_handler *handler) ...@@ -1705,7 +1705,7 @@ static int lxc_spawn(struct lxc_handler *handler)
pid_t attacher_pid; pid_t attacher_pid;
attacher_pid = lxc_clone(do_share_ns, handler, 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) { if (attacher_pid < 0) {
SYSERROR(LXC_CLONE_ERROR); SYSERROR(LXC_CLONE_ERROR);
goto out_delete_net; goto out_delete_net;
......
...@@ -266,7 +266,7 @@ static bool clone_attach_nbd(const char *nbd, const char *path) ...@@ -266,7 +266,7 @@ static bool clone_attach_nbd(const char *nbd, const char *path)
data.nbd = nbd; data.nbd = nbd;
data.path = path; 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) if (pid < 0)
return false; return false;
......
...@@ -388,7 +388,7 @@ int main(int argc, char *argv[]) ...@@ -388,7 +388,7 @@ int main(int argc, char *argv[])
start_arg.want_hostname = my_args.want_hostname; start_arg.want_hostname = my_args.want_hostname;
start_arg.want_default_mounts = my_args.want_default_mounts; 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) { if (pid < 0) {
ERROR("Failed to clone"); ERROR("Failed to clone");
free_ifname_list(); free_ifname_list();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment