aboutsummaryrefslogtreecommitdiff
path: root/toys/other/unshare.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-08-25 14:25:22 -0500
committerRob Landley <rob@landley.net>2012-08-25 14:25:22 -0500
commit3a9241add947cb6d24b5de7a8927517426a78795 (patch)
treed122ab6570439cd6b17c7d73ed8d4e085e0b8a95 /toys/other/unshare.c
parent689f095bc976417bf50810fe59a3b3ac32b21105 (diff)
downloadtoybox-3a9241add947cb6d24b5de7a8927517426a78795.tar.gz
Move commands into "posix", "lsb", and "other" menus/directories.
Diffstat (limited to 'toys/other/unshare.c')
-rw-r--r--toys/other/unshare.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/toys/other/unshare.c b/toys/other/unshare.c
new file mode 100644
index 00000000..1df9b758
--- /dev/null
+++ b/toys/other/unshare.c
@@ -0,0 +1,45 @@
+/* vi: set sw=4 ts=4:
+ *
+ * unshare.c - run command in new context
+ *
+ * Copyright 2011 Rob Landley <rob@landley.net>
+ *
+ * Not in SUSv4.
+
+USE_UNSHARE(NEWTOY(unshare, "<1^nium", TOYFLAG_USR|TOYFLAG_BIN))
+
+config UNSHARE
+ bool "unshare"
+ default y
+ depends on TOYBOX_CONTAINER
+ help
+ usage: unshare [-muin] COMMAND...
+
+ Create new namespace(s) for this process and its children, so some
+ attribute is not shared with the parent process. This is part of
+ Linux Containers. Each process can have its own:
+
+ -m Mount/unmount tree
+ -u Host and domain names
+ -i SysV IPC (message queues, semaphores, shared memory)
+ -n Network address, sockets, routing, iptables
+*/
+
+#include "toys.h"
+#include <linux/sched.h>
+extern int unshare (int __flags);
+
+void unshare_main(void)
+{
+ unsigned flags[]={CLONE_NEWNS, CLONE_NEWUTS, CLONE_NEWIPC, CLONE_NEWNET,0};
+ unsigned f=0;
+ int i;
+
+ for (i=0; flags[i]; i++)
+ if (toys.optflags & (1<<i))
+ f |= flags[i];
+
+ if(unshare(f)) perror_exit("failed");
+
+ xexec(toys.optargs);
+}