prctl does not work as well as this. Revert changeset 2731.
[util-vserver.git] / src / vspace.c
index ce57879..202012b 100644 (file)
@@ -56,6 +56,8 @@ CMDLINE_OPTIONS[] = {
   { "ipc",        no_argument,       0, 'I' },
   { "uts",        no_argument,       0, 'U' },
   { "user",       no_argument,       0, 'S' },
+  { "pid",        no_argument,       0, 'P' },
+  { "net",        no_argument,       0, 'N' },
   {0,0,0,0}
 };
 
@@ -83,6 +85,8 @@ showHelp(int fd, char const *cmd, int res)
            "    --ipc             ...  the IPC namespace\n"
            "    --uts             ...  the uts namespace\n"
            "    --user            ...  the user namespace\n"
+           "    --pid             ...  the pid namespace\n"
+           "    --net             ...  the network namespace\n"
            "\n"
            "Please report bugs to " PACKAGE_BUGREPORT "\n");
 
@@ -106,6 +110,12 @@ newSpaces(uint_least64_t mask, const char *cmd)
 {
   pid_t pid;
 
+  /* optimize default case */
+  if (mask == 0)
+    return;
+
+  mask &= ~CLONE_FS;
+
   signal(SIGCHLD, SIG_DFL);
 
 #ifdef NDEBUG
@@ -153,7 +163,7 @@ int main(int argc, char *argv[])
   int                  sum        = 0;
   
   while (1) {
-    int                c = getopt_long(argc, argv, "+nsce:m:" "MFIUS", CMDLINE_OPTIONS, 0);
+    int                c = getopt_long(argc, argv, "+nsce:m:" "MFIUSPN", CMDLINE_OPTIONS, 0);
     if (c==-1) break;
 
     switch (c) {
@@ -165,19 +175,24 @@ int main(int argc, char *argv[])
        do_enter = true;
        xid      = Evc_xidopt2xid(optarg,true);
        break;
-      case 'm'         :
-       if (!isNumberUnsigned(optarg, &mask, true)) {
+      case 'm'         :  {
+       unsigned long   mask_l;
+       if (!isNumberUnsigned(optarg, &mask_l, true)) {
          WRITE_MSG(2, "Invalid mask '");
          WRITE_STR(2, optarg);
          WRITE_MSG(2, "'; try '--help' for more information\n");
          return wrapper_exit_code;
        }
+       mask = mask_l;
        break;
+      }
       case 'M'         :  mask |= CLONE_NEWNS;         break;
       case 'F'         :  mask |= CLONE_FS;            break;
       case 'I'         :  mask |= CLONE_NEWIPC;        break;
       case 'U'         :  mask |= CLONE_NEWUTS;        break;
       case 'S'         :  mask |= CLONE_NEWUSER;       break;
+      case 'P'         :  mask |= CLONE_NEWPID;        break;
+      case 'N'         :  mask |= CLONE_NEWNET;        break;
 
       default          :
        WRITE_MSG(2, "Try '");
@@ -195,8 +210,6 @@ int main(int argc, char *argv[])
     WRITE_MSG(2, "No operation was specified; try '--help' for more information\n");
   else if (sum>1)
     WRITE_MSG(2, "Can not specify multiple operations; try '--help' for more information\n");
-  else if (mask==0)
-    WRITE_MSG(2, "Must specify at least one space; try '--help' for more information\n");
   else if (optind==argc && (do_new || do_enter))
     WRITE_MSG(2, "No command specified; try '--help' for more information\n");
   else {