diff options
Diffstat (limited to 'toys')
-rw-r--r-- | toys/Config.in | 8 | ||||
-rw-r--r-- | toys/chroot.c | 14 | ||||
-rw-r--r-- | toys/toylist.h | 1 |
3 files changed, 23 insertions, 0 deletions
diff --git a/toys/Config.in b/toys/Config.in index a53c11f1..ba2bbf32 100644 --- a/toys/Config.in +++ b/toys/Config.in @@ -40,6 +40,14 @@ config CATV -t Show tabs as ^I -v Don't use ^x or M-x escapes. +config CHROOT + bool "chroot" + default y + help + usage: chroot NEWPATH [commandline...] + + Run command within a new root directory. If no command, run /bin/sh. + config COUNT bool "count" default y diff --git a/toys/chroot.c b/toys/chroot.c new file mode 100644 index 00000000..0126d968 --- /dev/null +++ b/toys/chroot.c @@ -0,0 +1,14 @@ +/* vi: set sw=4 ts=4: */ +/* + * chroot.c - Run command in new root directory. + */ + +#include "toys.h" + +void chroot_main(void) +{ + char *binsh[] = {"/bin/sh", 0}; + if (chdir(*toys.optargs) || chroot(".")) + perror_exit("%s", *toys.optargs); + xexec(toys.optargs[1] ? toys.optargs+1 : binsh); +} diff --git a/toys/toylist.h b/toys/toylist.h index 360efa8a..f24266bb 100644 --- a/toys/toylist.h +++ b/toys/toylist.h @@ -119,6 +119,7 @@ NEWTOY(toybox, NULL, 0) USE_BASENAME(NEWTOY(basename, "<1>2", TOYFLAG_BIN)) USE_BZCAT(NEWTOY(bzcat, "", TOYFLAG_USR|TOYFLAG_BIN)) USE_CATV(NEWTOY(catv, "vte", TOYFLAG_USR|TOYFLAG_BIN)) +USE_CHROOT(NEWTOY(chroot, "<1", TOYFLAG_USR|TOYFLAG_SBIN)) USE_COUNT(NEWTOY(count, "", TOYFLAG_USR|TOYFLAG_BIN)) USE_TOYSH(NEWTOY(cd, NULL, TOYFLAG_NOFORK)) USE_DF(NEWTOY(df, "Pkt*a", TOYFLAG_USR|TOYFLAG_SBIN)) |