Initial revision
[platform/upstream/busybox.git] / chroot.c
1 #include "internal.h"
2 #include <stdio.h>
3 #include <unistd.h>
4
5
6 const char chroot_usage[] = "chroot directory [command]\n"
7   "Run a command with special root directory.\n";
8
9 extern int
10 chroot_main (struct FileInfo *i, int argc, char **argv)
11 {
12   char *prog;
13
14   if (chroot (argv[1]))
15     {
16       name_and_error ("cannot chroot to that directory");
17       return 1;
18     }
19   if (argc > 2)
20     {
21       execvp (argv[2], argv + 2);
22     }
23   else
24     {
25       prog = getenv ("SHELL");
26       if (!prog)
27         prog = "/bin/sh";
28       execlp (prog, prog, NULL);
29     }
30   name_and_error ("cannot exec");
31   return 1;
32 }