hexdump: accept hex numbers in -n, closes 16195
[busybox-git.git] / coreutils / chroot.c
blob0b45aa80cb45d6ae15ef169d0150c50572b317e2
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 */
9 //config:config CHROOT
10 //config: bool "chroot (4 kb)"
11 //config: default y
12 //config: help
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"
26 //usage:
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"
35 #include "libbb.h"
37 int chroot_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
38 int chroot_main(int argc UNUSED_PARAM, char **argv)
40 ++argv;
41 if (!*argv)
42 bb_show_usage();
44 xchroot(*argv);
46 ++argv;
47 if (!*argv) { /* no 2nd param (PROG), use shell */
48 argv -= 2;
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);