Pid namespaces require clone.
authorDaniel Hokka Zakrisson <daniel@hozac.com>
Sat, 12 Jan 2008 15:48:04 +0000 (15:48 +0000)
committerDaniel Hokka Zakrisson <daniel@hozac.com>
Sat, 12 Jan 2008 15:48:04 +0000 (15:48 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2658 94cd875c-1c1d-0410-91d2-eb244daf1a30

src/vspace.c

index 30f0dda..ce57879 100644 (file)
@@ -22,7 +22,7 @@
 #endif
 
 #include "util.h"
-#include <lib_internal/sys_unshare.h>
+#include <lib_internal/sys_clone.h>
 
 #include <vserver.h>
 
@@ -102,11 +102,26 @@ showVersion()
 }
 
 static void
-newSpaces(uint_least64_t mask)
+newSpaces(uint_least64_t mask, const char *cmd)
 {
-  if (sys_unshare((int) mask) == -1) {
-    perror(ENSC_WRAPPERS_PREFIX "unshare()");
-    exit(wrapper_exit_code);
+  pid_t pid;
+
+  signal(SIGCHLD, SIG_DFL);
+
+#ifdef NDEBUG
+  pid = sys_clone((int) mask | CLONE_VFORK|SIGCHLD, 0);
+#else
+  pid = sys_clone((int) mask | SIGCHLD, 0);
+#endif
+
+  switch (pid) {
+    case -1    :
+      perror(ENSC_WRAPPERS_PREFIX "clone()");
+      exit(wrapper_exit_code);
+    case 0     :
+      break;
+    default    :
+      exitLikeProcess(pid, cmd, wrapper_exit_code);
   }
 }
 
@@ -185,7 +200,7 @@ int main(int argc, char *argv[])
   else if (optind==argc && (do_new || do_enter))
     WRITE_MSG(2, "No command specified; try '--help' for more information\n");
   else {
-    if      (do_new)     newSpaces(mask);
+    if      (do_new)     newSpaces(mask, argv[optind]);
     else if (do_set)     setSpaces(VC_SAMECTX, mask);
     else if (do_enter)   enterSpaces(xid, mask);