X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=coreutils%2Fchroot.c;h=fcd70f21a8bcfe9e07f3f449c592cde17ba96527;hb=ec1a4b5a521b5adf295bc757c25231910f8c854b;hp=ca0bfcf3fbc6c58a3506b5c2f36b8049f1273b83;hpb=cc8ed39b240180b58810784f844e253263594ac3;p=oweals%2Fbusybox.git diff --git a/coreutils/chroot.c b/coreutils/chroot.c index ca0bfcf3f..fcd70f21a 100644 --- a/coreutils/chroot.c +++ b/coreutils/chroot.c @@ -1,32 +1,38 @@ -#include "internal.h" -#include -#include +/* vi: set sw=4 ts=4: */ +/* + * Mini chroot implementation for busybox + * + * Copyright (C) 1999-2004 by Erik Andersen + * + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. + */ +/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */ -const char chroot_usage[] = "chroot directory [command]\n" - "Run a command with special root directory.\n"; +#include "busybox.h" -extern int -chroot_main (struct FileInfo *i, int argc, char **argv) +int chroot_main(int argc, char **argv); +int chroot_main(int argc, char **argv) { - char *prog; + if (argc < 2) { + bb_show_usage(); + } - if (chroot (argv[1])) - { - name_and_error ("cannot chroot to that directory"); - return 1; - } - if (argc > 2) - { - execvp (argv[2], argv + 2); - } - else - { - prog = getenv ("SHELL"); - if (!prog) - prog = "/bin/sh"; - execlp (prog, prog, NULL); - } - name_and_error ("cannot exec"); - return 1; + ++argv; + if (chroot(*argv)) { + bb_perror_msg_and_die("cannot change root directory to %s", *argv); + } + xchdir("/"); + + ++argv; + if (argc == 2) { + argv -= 2; + if (!(*argv = getenv("SHELL"))) { + *argv = (char *) DEFAULT_SHELL; + } + argv[1] = (char *) "-i"; + } + + BB_EXECVP(*argv, argv); + bb_perror_msg_and_die("cannot execute %s", *argv); }