comparison toys/other/unshare.c @ 1526:33b3b5f9e6c6 draft

unshare: Fix help and option parsing The help text was inconsistent, and option parsing was completely broken (the options mostly did the wrong thing).
author Andy Lutomirski <luto@amacapital.net>
date Fri, 17 Oct 2014 18:40:03 -0700
parents 0d0c01ac5c63
children
comparison
equal deleted inserted replaced
1525:95cb37adb024 1526:33b3b5f9e6c6
1 /* unshare.c - run command in new context 1 /* unshare.c - run command in new context
2 * 2 *
3 * Copyright 2011 Rob Landley <rob@landley.net> 3 * Copyright 2011 Rob Landley <rob@landley.net>
4 4
5 USE_UNSHARE(NEWTOY(unshare, "<1^niumpU", TOYFLAG_USR|TOYFLAG_BIN)) 5 USE_UNSHARE(NEWTOY(unshare, "<1^imnpuU", TOYFLAG_USR|TOYFLAG_BIN))
6 6
7 config UNSHARE 7 config UNSHARE
8 bool "unshare" 8 bool "unshare"
9 default y 9 default y
10 depends on TOYBOX_CONTAINER 10 depends on TOYBOX_CONTAINER
11 help 11 help
12 usage: unshare [-muin] COMMAND... 12 usage: unshare [-imnpuU] COMMAND...
13 13
14 Create new namespace(s) for this process and its children, so some 14 Create new namespace(s) for this process and its children, so some
15 attribute is not shared with the parent process. This is part of 15 attribute is not shared with the parent process. This is part of
16 Linux Containers. Each process can have its own: 16 Linux Containers. Each process can have its own:
17 17
18 -i SysV IPC (message queues, semaphores, shared memory) 18 -i SysV IPC (message queues, semaphores, shared memory)
19 -m Mount/unmount tree 19 -m Mount/unmount tree
20 -n Network address, sockets, routing, iptables 20 -n Network address, sockets, routing, iptables
21 -p Process IDs and init 21 -p Process IDs and init
22 -u Host and domain names 22 -u Host and domain names
23 -U UIDs, GIDs, capabilities 23 -U UIDs, GIDs, capabilities
24 */ 24 */
25 25
26 #include "toys.h" 26 #include "toys.h"
27 #include <linux/sched.h> 27 #include <linux/sched.h>
28 extern int unshare (int __flags); 28 extern int unshare (int __flags);
29 29
30 void unshare_main(void) 30 void unshare_main(void)
31 { 31 {
32 unsigned flags[]={CLONE_NEWNS, CLONE_NEWUTS, CLONE_NEWIPC, CLONE_NEWNET, 32 unsigned flags[]={CLONE_NEWUSER, CLONE_NEWUTS, CLONE_NEWPID, CLONE_NEWNET,
33 CLONE_NEWPID, CLONE_NEWUSER, 0}; 33 CLONE_NEWNS, CLONE_NEWIPC, 0};
34 unsigned f=0; 34 unsigned f=0;
35 int i; 35 int i;
36 36
37 for (i=0; flags[i]; i++) if (toys.optflags & (1<<i)) f |= flags[i]; 37 for (i=0; flags[i]; i++) if (toys.optflags & (1<<i)) f |= flags[i];
38 38
39 if(unshare(f)) perror_exit("failed"); 39 if (unshare(f)) perror_exit("failed");
40 40
41 xexec_optargs(0); 41 xexec_optargs(0);
42 } 42 }