1 /* vi: set sw=4 ts=4: */
3 * Mini chroot implementation for busybox
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
10 //config: bool "chroot (4 kb)"
13 //config: chroot is used to change the root directory and run a command.
14 //config: The default command is '/bin/sh'.
16 //applet:IF_CHROOT(APPLET_NOEXEC(chroot, chroot, BB_DIR_USR_SBIN, BB_SUID_DROP, chroot))
18 //kbuild:lib-$(CONFIG_CHROOT) += chroot.o
20 /* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
22 //usage:#define chroot_trivial_usage
23 //usage: "NEWROOT [PROG ARGS]"
24 //usage:#define chroot_full_usage "\n\n"
25 //usage: "Run PROG with root directory set to NEWROOT"
27 //usage:#define chroot_example_usage
28 //usage: "$ ls -l /bin/ls\n"
29 //usage: "lrwxrwxrwx 1 root root 12 Apr 13 00:46 /bin/ls -> /BusyBox\n"
30 //usage: "# mount /dev/hdc1 /mnt -t minix\n"
31 //usage: "# chroot /mnt\n"
32 //usage: "# ls -l /bin/ls\n"
33 //usage: "-rwxr-xr-x 1 root root 40816 Feb 5 07:45 /bin/ls*\n"
37 int chroot_main(int argc
, char **argv
) MAIN_EXTERNALLY_VISIBLE
;
38 int chroot_main(int argc UNUSED_PARAM
, char **argv
)
47 if (!*argv
) { /* no 2nd param (PROG), use shell */
49 argv
[0] = (char *) get_shell_name();
50 argv
[1] = (char *) "-i"; /* GNU coreutils 8.4 compat */
51 /*argv[2] = NULL; - already is */
54 BB_EXECVP_or_die(argv
);