Mercurial > hg > toybox
annotate toys/unshare.c @ 636:42ae383499c5
Add date -r, make -u work even when /etc/localtime set, and lots of cleanup/refactoring.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 21 Jul 2012 18:37:26 -0500 |
parents | 99cb6ad605ee |
children |
rev | line source |
---|---|
398 | 1 /* vi: set sw=4 ts=4: |
2 * | |
3 * unshare.c - run command in new context | |
4 * | |
5 * Copyright 2011 Rob Landley <rob@landley.net> | |
6 * | |
7 * Not in SUSv4. | |
8 | |
9 USE_UNSHARE(NEWTOY(unshare, "<1^nium", TOYFLAG_USR|TOYFLAG_BIN)) | |
10 | |
11 config UNSHARE | |
12 bool "unshare" | |
13 default y | |
426
8b0487639db9
Add autodetect for container support.
Rob Landley <rob@landley.net>
parents:
398
diff
changeset
|
14 depends on TOYBOX_CONTAINER |
398 | 15 help |
16 usage: unshare [-muin] COMMAND... | |
17 | |
18 Create new namespace(s) for this process and its children, so some | |
19 attribute is not shared with the parent process. This is part of | |
20 Linux Containers. Each process can have its own: | |
21 | |
22 -m Mount/unmount tree | |
23 -u Host and domain names | |
24 -i SysV IPC (message queues, semaphores, shared memory) | |
25 -n Network address, sockets, routing, iptables | |
26 */ | |
27 | |
28 #include "toys.h" | |
537
f70187762108
Work around glibc regression by including Linux header directly.
Rob Landley <rob@landley.net>
parents:
533
diff
changeset
|
29 #include <linux/sched.h> |
548
99cb6ad605ee
The linux header doesn't prototype unshare, and the glibc header introduced a regression in recent versions inexplicably crediting a linux feature to the FSF, so add the prototype ourselves.
Rob Landley <rob@landley.net>
parents:
537
diff
changeset
|
30 extern int unshare (int __flags); |
398 | 31 |
32 void unshare_main(void) | |
33 { | |
34 unsigned flags[]={CLONE_NEWNS, CLONE_NEWUTS, CLONE_NEWIPC, CLONE_NEWNET,0}; | |
35 unsigned f=0; | |
36 int i; | |
37 | |
38 for (i=0; flags[i]; i++) | |
39 if (toys.optflags & (1<<i)) | |
40 f |= flags[i]; | |
41 | |
42 if(unshare(f)) perror_exit("failed"); | |
43 | |
44 xexec(toys.optargs); | |
45 } |