diff options
author | Rob Landley <rob@landley.net> | 2013-06-18 18:13:06 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2013-06-18 18:13:06 -0500 |
commit | 50b2625145f4919c3752c9e974f88a5666cac476 (patch) | |
tree | 99925b61aa7f95ac2df9cb8ec6b21efa1e95d370 /toys/other | |
parent | 55ec010efa77fe10cf4b7eaa480bc52008ef7a54 (diff) | |
download | toybox-50b2625145f4919c3752c9e974f88a5666cac476.tar.gz |
Add pivot_root.
Diffstat (limited to 'toys/other')
-rw-r--r-- | toys/other/pivot_root.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/toys/other/pivot_root.c b/toys/other/pivot_root.c new file mode 100644 index 00000000..3e4beacb --- /dev/null +++ b/toys/other/pivot_root.c @@ -0,0 +1,31 @@ +/* pivot_root.c - edit system mount tree + * + * Copyright 2012 Rob Landley <rob@landley.net> + +USE_PIVOT_ROOT(NEWTOY(pivot_root, "<2>2", TOYFLAG_USR|TOYFLAG_BIN)) + +config PIVOT_ROOT + bool "pivot_root" + default y + help + usage: pivot_root OLD NEW + + Swap OLD and NEW filesystems (as if by simultaneous mount --move), and + move all processes with chdir or chroot under OLD into NEW (including + kernel threads) so OLD may be unmounted. + + The directory NEW must exist under OLD. This doesn't work on initramfs, + which can't be moved (about the same way PID 1 can't be killed; see + switch_root instead). +*/ + +#define FOR_pivot_root +#include "toys.h" + +#include <linux/unistd.h> + +void pivot_root_main(void) +{ + if (syscall(__NR_pivot_root, toys.optargs[0], toys.optargs[1])) + perror_exit("'%s' -> '%s'", toys.optargs[0], toys.optargs[1]); +} |