Mercurial > hg > toybox
annotate toys/other/unshare.c @ 1322:b91284c2e569 draft
Make "losetup /dev/loop0 filename" work.
Sigh. Implement the complex cases and you screw up the simple cases you already tested...
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 29 May 2014 06:29:12 -0500 |
parents | 0d0c01ac5c63 |
children | 33b3b5f9e6c6 |
rev | line source |
---|---|
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
1 /* unshare.c - run command in new context |
398 | 2 * |
3 * Copyright 2011 Rob Landley <rob@landley.net> | |
4 | |
1031
0d0c01ac5c63
PID and UID namespaces for unshare, pointed out by heehooman@gmail.com.
Rob Landley <rob@landley.net>
parents:
955
diff
changeset
|
5 USE_UNSHARE(NEWTOY(unshare, "<1^niumpU", TOYFLAG_USR|TOYFLAG_BIN)) |
398 | 6 |
7 config UNSHARE | |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
8 bool "unshare" |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
9 default y |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
10 depends on TOYBOX_CONTAINER |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
11 help |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
12 usage: unshare [-muin] COMMAND... |
398 | 13 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
14 Create new namespace(s) for this process and its children, so some |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
15 attribute is not shared with the parent process. This is part of |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
16 Linux Containers. Each process can have its own: |
398 | 17 |
1031
0d0c01ac5c63
PID and UID namespaces for unshare, pointed out by heehooman@gmail.com.
Rob Landley <rob@landley.net>
parents:
955
diff
changeset
|
18 -i SysV IPC (message queues, semaphores, shared memory) |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
19 -m Mount/unmount tree |
1031
0d0c01ac5c63
PID and UID namespaces for unshare, pointed out by heehooman@gmail.com.
Rob Landley <rob@landley.net>
parents:
955
diff
changeset
|
20 -n Network address, sockets, routing, iptables |
0d0c01ac5c63
PID and UID namespaces for unshare, pointed out by heehooman@gmail.com.
Rob Landley <rob@landley.net>
parents:
955
diff
changeset
|
21 -p Process IDs and init |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
22 -u Host and domain names |
1031
0d0c01ac5c63
PID and UID namespaces for unshare, pointed out by heehooman@gmail.com.
Rob Landley <rob@landley.net>
parents:
955
diff
changeset
|
23 -U UIDs, GIDs, capabilities |
398 | 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 { | |
1031
0d0c01ac5c63
PID and UID namespaces for unshare, pointed out by heehooman@gmail.com.
Rob Landley <rob@landley.net>
parents:
955
diff
changeset
|
32 unsigned flags[]={CLONE_NEWNS, CLONE_NEWUTS, CLONE_NEWIPC, CLONE_NEWNET, |
0d0c01ac5c63
PID and UID namespaces for unshare, pointed out by heehooman@gmail.com.
Rob Landley <rob@landley.net>
parents:
955
diff
changeset
|
33 CLONE_NEWPID, CLONE_NEWUSER, 0}; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
34 unsigned f=0; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
35 int i; |
398 | 36 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
37 for (i=0; flags[i]; i++) if (toys.optflags & (1<<i)) f |= flags[i]; |
398 | 38 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
39 if(unshare(f)) perror_exit("failed"); |
398 | 40 |
955
144d5ba7d410
Replace users of xexec(toys.optargs) with xexec_optargs(0) to avoid free/reuse bug during argument parsing.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
41 xexec_optargs(0); |
398 | 42 } |