Tar, by itself, could fail.
[oweals/busybox.git] / chroot.c
index 95aed3d177da790d3e58870e26d906a5523278e1..91d3407f2a37f6a5ee7e0470d68880af3be667da 100644 (file)
--- a/chroot.c
+++ b/chroot.c
  *
  */
 
-#include "internal.h"
+#include "busybox.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include <errno.h>
 
-
-static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n"
-#ifndef BB_FEATURE_TRIVIAL_HELP
-       "\nRun COMMAND with root directory set to NEWROOT.\n"
-#endif
-       ;
-
-
-
 int chroot_main(int argc, char **argv)
 {
        char *prog;
@@ -47,7 +38,7 @@ int chroot_main(int argc, char **argv)
        argv++;
 
        if (chroot(*argv) || (chdir("/"))) {
-               fatalError("cannot change root directory to %s: %s\n", *argv, strerror(errno));
+               perror_msg_and_die("cannot change root directory to %s", *argv);
        }
 
        argc--;
@@ -56,12 +47,17 @@ int chroot_main(int argc, char **argv)
                prog = *argv;
                execvp(*argv, argv);
        } else {
+#ifndef BB_SH
                prog = getenv("SHELL");
                if (!prog)
                        prog = "/bin/sh";
                execlp(prog, prog, NULL);
+#else
+               shell_main(argc, argv);
+               return EXIT_SUCCESS;
+#endif
        }
-       fatalError("cannot execute %s: %s\n", prog, strerror(errno));
+       perror_msg_and_die("cannot execute %s", prog);
 
 }