1 /* chroot.c - Run command in new root directory. 2 * 3 * Copyright 2007 Rob Landley <rob@landley.net> 4 5 USE_CHROOT(NEWTOY(chroot, "^<1", TOYFLAG_USR|TOYFLAG_SBIN)) 6 7 config CHROOT 8 bool "chroot" 9 default y 10 help 11 usage: chroot NEWPATH [commandline...] 12 13 Run command within a new root directory. If no command, run /bin/sh. 14 */ 15 16 #include "toys.h" 17 chroot_main(void)18void chroot_main(void) 19 { 20 char *binsh[] = {"/bin/sh", "-i", 0}; 21 22 if (chdir(*toys.optargs) || chroot(".")) perror_exit("%s", *toys.optargs); 23 if (toys.optargs[1]) xexec(toys.optargs+1); 24 else xexec(binsh); 25 } 26