diff --git a/libcontainer/nsenter/nsexec.c b/libcontainer/nsenter/nsexec.c index 3338108e..a52b7dc3 100644 --- a/libcontainer/nsenter/nsexec.c +++ b/libcontainer/nsenter/nsexec.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -84,6 +85,14 @@ static int clone_parent(jmp_buf *env, int flags) ca.env = env; child = clone(child_func, ca.stack_ptr, CLONE_PARENT | SIGCHLD | flags, &ca); + if (child == -1 && errno == EINVAL) { + if (unshare(flags)) { + pr_perror("Unable to unshare namespaces"); + return -1; + } + child = clone(child_func, ca.stack_ptr, SIGCHLD | CLONE_PARENT, + &ca); + } return child; }