annotate toys/unshare.c @ 562:4d802d438983

Match uint64_t with PRIu64 to avoid warnings on 64 bit builds.
author Rob Landley <rob@landley.net>
date Sat, 14 Apr 2012 21:27:00 -0500
parents 99cb6ad605ee
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
398
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* vi: set sw=4 ts=4:
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
2 *
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * unshare.c - run command in new context
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 * Copyright 2011 Rob Landley <rob@landley.net>
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
6 *
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
7 * Not in SUSv4.
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
8
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
9 USE_UNSHARE(NEWTOY(unshare, "<1^nium", TOYFLAG_USR|TOYFLAG_BIN))
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
10
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
11 config UNSHARE
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
12 bool "unshare"
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
15 help
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
16 usage: unshare [-muin] COMMAND...
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
17
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
18 Create new namespace(s) for this process and its children, so some
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
19 attribute is not shared with the parent process. This is part of
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 Linux Containers. Each process can have its own:
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
21
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 -m Mount/unmount tree
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
23 -u Host and domain names
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
24 -i SysV IPC (message queues, semaphores, shared memory)
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
25 -n Network address, sockets, routing, iptables
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
26 */
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
27
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
31
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
32 void unshare_main(void)
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
33 {
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
34 unsigned flags[]={CLONE_NEWNS, CLONE_NEWUTS, CLONE_NEWIPC, CLONE_NEWNET,0};
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
35 unsigned f=0;
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
36 int i;
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
37
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
38 for (i=0; flags[i]; i++)
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
39 if (toys.optflags & (1<<i))
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
40 f |= flags[i];
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
41
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
42 if(unshare(f)) perror_exit("failed");
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
43
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
44 xexec(toys.optargs);
a4dcbad4f92a Implement unshare.
Rob Landley <rob@landley.net>
parents:
diff changeset
45 }