Changes for kernel and Busybox
[tomato.git] / release / src / router / busybox / coreutils / chroot.c
blob633e66b383e4c23a726b4200d27af4d3b213ac4a
1 /* vi: set sw=4 ts=4: */
2 /*
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.
8 */
10 /* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
12 //usage:#define chroot_trivial_usage
13 //usage: "NEWROOT [PROG ARGS]"
14 //usage:#define chroot_full_usage "\n\n"
15 //usage: "Run PROG with root directory set to NEWROOT"
16 //usage:
17 //usage:#define chroot_example_usage
18 //usage: "$ ls -l /bin/ls\n"
19 //usage: "lrwxrwxrwx 1 root root 12 Apr 13 00:46 /bin/ls -> /BusyBox\n"
20 //usage: "# mount /dev/hdc1 /mnt -t minix\n"
21 //usage: "# chroot /mnt\n"
22 //usage: "# ls -l /bin/ls\n"
23 //usage: "-rwxr-xr-x 1 root root 40816 Feb 5 07:45 /bin/ls*\n"
25 #include "libbb.h"
27 int chroot_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
28 int chroot_main(int argc UNUSED_PARAM, char **argv)
30 ++argv;
31 if (!*argv)
32 bb_show_usage();
33 xchroot(*argv);
35 ++argv;
36 if (!*argv) { /* no 2nd param (PROG), use shell */
37 argv -= 2;
38 argv[0] = (char *) get_shell_name();
39 argv[1] = (char *) "-i"; /* GNU coreutils 8.4 compat */
40 /*argv[2] = NULL; - already is */
43 BB_EXECVP_or_die(argv);