gentoo: use /var/run for new /run compatibility
[util-vserver.git] / src / vspace.c
index a6aeb83..37ac2c3 100644 (file)
@@ -49,6 +49,7 @@ CMDLINE_OPTIONS[] = {
   { "new",        no_argument,       0, 'n' },
   { "enter",      required_argument, 0, 'e' },
   { "set",        no_argument,       0, 's' },
+  { "index",      required_argument, 0, 'i' },
   { "mask",       required_argument, 0, 'm' },
   { "default",    no_argument,       0, 'd' },
   { "~default",   no_argument,       0, 'd' | 0x10000 },
@@ -85,6 +86,7 @@ showHelp(int fd, char const *cmd, int res)
            "                           <program> there; <program> is mandatory in this\n"
            "                           case\n"
            "    --set|-s          ...  assign the current spaces to the current context\n"
+           "    --index|-i <idx>  ...  work with the namespaces for <idx>\n"
            "\n"
            "<spaces>* specifies the spaces to manipulate.\n"
            "It can be any combination of:\n"
@@ -142,18 +144,18 @@ newSpaces(uint_least64_t mask)
 }
 
 static void
-enterSpaces(xid_t xid, uint_least64_t mask)
+enterSpaces(xid_t xid, uint_least64_t mask, uint32_t index)
 {
-  if (vc_enter_namespace(xid, mask)==-1) {
+  if (vc_enter_namespace(xid, mask, index)==-1) {
     perror(ENSC_WRAPPERS_PREFIX "vc_enter_namespace()");
     exit(wrapper_exit_code);
   }
 }
 
 static void
-setSpaces(xid_t xid, uint_least64_t mask)
+setSpaces(xid_t xid, uint_least64_t mask, uint32_t index)
 {
-  if (vc_set_namespace(xid, mask)==-1) {
+  if (vc_set_namespace(xid, mask, index)==-1) {
     perror(ENSC_WRAPPERS_PREFIX "vc_set_namespace()");
     exit(wrapper_exit_code);
   }
@@ -165,11 +167,12 @@ int main(int argc, char *argv[])
   bool                 do_enter   = false;
   bool                 do_set     = false;
   uint_least64_t       mask       = 0;
+  uint32_t             index      = 0;
   xid_t                        xid        = VC_NOCTX;
   int                  sum        = 0;
   
   while (1) {
-    int                        c = getopt_long(argc, argv, "+nsce:m:" "MFIUSPN", CMDLINE_OPTIONS, 0);
+    int                        c = getopt_long(argc, argv, "+nsce:m:i:" "MFIUSPN", CMDLINE_OPTIONS, 0);
     uint_least64_t     thisbit = 0;
     if (c==-1) break;
 
@@ -182,6 +185,17 @@ int main(int argc, char *argv[])
        do_enter = true;
        xid      = Evc_xidopt2xid(optarg,true);
        break;
+      case 'i'         :  {
+       unsigned long   index_l;
+       if (!isNumberUnsigned(optarg, &index_l, true)) {
+         WRITE_MSG(2, "Invalid index '");
+         WRITE_STR(2, optarg);
+         WRITE_MSG(2, "'; try '--help' for more information\n");
+         return wrapper_exit_code;
+       }
+       index = (uint32_t)index_l;
+       break;
+      }
       case 'm'         :  {
        unsigned long   mask_l;
        if (!isNumberUnsigned(optarg, &mask_l, true)) {
@@ -234,8 +248,8 @@ int main(int argc, char *argv[])
     WRITE_MSG(2, "No command specified; try '--help' for more information\n");
   else {
     if      (do_new)     newSpaces(mask);
-    else if (do_set)     setSpaces(VC_SAMECTX, mask);
-    else if (do_enter)   enterSpaces(xid, mask);
+    else if (do_set)     setSpaces(VC_SAMECTX, mask, index);
+    else if (do_enter)   enterSpaces(xid, mask, index);
 
     if (optind<argc)
       EexecvpD(argv[optind], argv+optind);