Mercurial > hg > toybox
annotate toys/other/unshare.c @ 656:6df4ccc0acbe
Regularize command headers, update links to standards documents.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 25 Aug 2012 18:08:51 -0500 |
parents | 2986aa63a021 |
children | 786841fdb1e0 |
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 USE_UNSHARE(NEWTOY(unshare, "<1^nium", TOYFLAG_USR|TOYFLAG_BIN)) | |
8 | |
9 config UNSHARE | |
10 bool "unshare" | |
11 default y | |
426
8b0487639db9
Add autodetect for container support.
Rob Landley <rob@landley.net>
parents:
398
diff
changeset
|
12 depends on TOYBOX_CONTAINER |
398 | 13 help |
14 usage: unshare [-muin] COMMAND... | |
15 | |
16 Create new namespace(s) for this process and its children, so some | |
17 attribute is not shared with the parent process. This is part of | |
18 Linux Containers. Each process can have its own: | |
19 | |
20 -m Mount/unmount tree | |
21 -u Host and domain names | |
22 -i SysV IPC (message queues, semaphores, shared memory) | |
23 -n Network address, sockets, routing, iptables | |
24 */ | |
25 | |
26 #include "toys.h" | |
537
f70187762108
Work around glibc regression by including Linux header directly.
Rob Landley <rob@landley.net>
parents:
533
diff
changeset
|
27 #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
|
28 extern int unshare (int __flags); |
398 | 29 |
30 void unshare_main(void) | |
31 { | |
32 unsigned flags[]={CLONE_NEWNS, CLONE_NEWUTS, CLONE_NEWIPC, CLONE_NEWNET,0}; | |
33 unsigned f=0; | |
34 int i; | |
35 | |
36 for (i=0; flags[i]; i++) | |
37 if (toys.optflags & (1<<i)) | |
38 f |= flags[i]; | |
39 | |
40 if(unshare(f)) perror_exit("failed"); | |
41 | |
42 xexec(toys.optargs); | |
43 } |