summaryrefslogtreecommitdiff
path: root/chroot.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-05 16:24:54 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-05 16:24:54 +0000
commitcc8ed39b240180b58810784f844e253263594ac3 (patch)
tree15feebbb4be9a9168209609f48f0b100f9364420 /chroot.c
downloadbusybox-w32-0_29alpha2.tar.gz
busybox-w32-0_29alpha2.tar.bz2
busybox-w32-0_29alpha2.zip
Initial revision0_29alpha2
Diffstat (limited to 'chroot.c')
-rw-r--r--chroot.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/chroot.c b/chroot.c
new file mode 100644
index 000000000..ca0bfcf3f
--- /dev/null
+++ b/chroot.c
@@ -0,0 +1,32 @@
1#include "internal.h"
2#include <stdio.h>
3#include <unistd.h>
4
5
6const char chroot_usage[] = "chroot directory [command]\n"
7 "Run a command with special root directory.\n";
8
9extern int
10chroot_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}