[Toybox] [PATCH] unshare: Fix help and option parsing

Andy Lutomirski luto at amacapital.net
Fri Oct 17 18:47:18 PDT 2014


# HG changeset patch
# User Andy Lutomirski <luto at amacapital.net>
# Date 1413596403 25200
#      Fri Oct 17 18:40:03 2014 -0700
# Node ID 5330d3f88fa344a7eb9fada28944394663cd3562
# Parent  2ce0f52103a9fa4a59d33d8107d82d0b77f4d212
unshare: Fix help and option parsing

The help text was inconsistent, and option parsing was completely broken
(the options mostly did the wrong thing).

diff -r 2ce0f52103a9 -r 5330d3f88fa3 toys/other/unshare.c
--- a/toys/other/unshare.c	Thu Oct 16 05:58:35 2014 -0500
+++ b/toys/other/unshare.c	Fri Oct 17 18:40:03 2014 -0700
@@ -2,14 +2,14 @@
  *
  * Copyright 2011 Rob Landley <rob at landley.net>
 
-USE_UNSHARE(NEWTOY(unshare, "<1^niumpU", TOYFLAG_USR|TOYFLAG_BIN))
+USE_UNSHARE(NEWTOY(unshare, "<1^imnpuU", TOYFLAG_USR|TOYFLAG_BIN))
 
 config UNSHARE
   bool "unshare"
   default y
   depends on TOYBOX_CONTAINER
   help
-    usage: unshare [-muin] COMMAND...
+    usage: unshare [-imnpuU] COMMAND...
 
     Create new namespace(s) for this process and its children, so some
     attribute is not shared with the parent process.  This is part of
@@ -20,7 +20,7 @@
     -n	Network address, sockets, routing, iptables
     -p	Process IDs and init
     -u	Host and domain names
-    -U  UIDs, GIDs, capabilities
+    -U	UIDs, GIDs, capabilities
 */
 
 #include "toys.h"
@@ -29,14 +29,14 @@
 
 void unshare_main(void)
 {
-  unsigned flags[]={CLONE_NEWNS, CLONE_NEWUTS, CLONE_NEWIPC, CLONE_NEWNET,
-                    CLONE_NEWPID, CLONE_NEWUSER, 0};
+  unsigned flags[]={CLONE_NEWUSER, CLONE_NEWUTS, CLONE_NEWPID, CLONE_NEWNET,
+                    CLONE_NEWNS, CLONE_NEWIPC, 0};
   unsigned f=0;
   int i;
 
   for (i=0; flags[i]; i++) if (toys.optflags & (1<<i)) f |= flags[i];
 
-  if(unshare(f)) perror_exit("failed");
+  if (unshare(f)) perror_exit("failed");
 
   xexec_optargs(0);
 }


More information about the Toybox mailing list