Revert commit 2690, clone is needed for pid namespaces and on kernels <2.6.16.
[util-vserver.git] / src / vnamespace.c
index 076b4e4..c71cc9f 100644 (file)
@@ -21,7 +21,7 @@
 #endif
 
 #include "util.h"
-#include <lib_internal/sys_unshare.h>
+#include <lib_internal/sys_clone.h>
 
 #include <vserver.h>
 
@@ -88,14 +88,26 @@ showVersion()
 }
 
 static void
-newNamespace(void)
+newNamespace(char const *cmd)
 {
-  int          rc;
+  pid_t                pid;
 
-  rc = sys_unshare(CLONE_NEWNS);
-  if (rc!=0) {
-    perror("vnamespace: unshare()");
-    exit(wrapper_exit_code);
+  signal(SIGCHLD, SIG_DFL);
+  
+#ifdef NDEBUG    
+  pid = sys_clone(CLONE_NEWNS|CLONE_VFORK|SIGCHLD, 0);
+#else
+  pid = sys_clone(CLONE_NEWNS|SIGCHLD, 0);
+#endif
+
+  switch (pid) {
+    case -1    :
+      perror("vnamespace: clone()");
+      exit(wrapper_exit_code);
+    case 0     :
+      break;
+    default    :
+      exitLikeProcess(pid, cmd, wrapper_exit_code);
   }
 }
 
@@ -169,7 +181,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)     newNamespace();
+    if      (do_new)     newNamespace(argv[optind]);
     else if (do_set)     setNamespace(VC_SAMECTX, CLONE_NEWNS|CLONE_FS);
     else if (do_cleanup) cleanupNamespace();
     else if (do_enter)   enterNamespace(xid, CLONE_NEWNS|CLONE_FS);