aboutsummaryrefslogtreecommitdiff
path: root/coreutils/chroot.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-06-02 17:56:45 +0000
committerEric Andersen <andersen@codepoet.org>2000-06-02 17:56:45 +0000
commit808d03ec19e0c8f0c06d9a9defb85fc9a1100441 (patch)
tree51eacc49fad57b2d4d0f63da4da31dd7a7384918 /coreutils/chroot.c
parent9c8ffa02f4ecd6029233de9d5cdc695fc82fc6df (diff)
downloadbusybox-w32-808d03ec19e0c8f0c06d9a9defb85fc9a1100441.tar.gz
busybox-w32-808d03ec19e0c8f0c06d9a9defb85fc9a1100441.tar.bz2
busybox-w32-808d03ec19e0c8f0c06d9a9defb85fc9a1100441.zip
This is a fix for chroot
- Fixed error message when the command is not specified (possibly crash on libc5 systems!) - Debugging output removed - Using fatalError() whenever appropriate Regards, Pavel Roskin
Diffstat (limited to 'coreutils/chroot.c')
-rw-r--r--coreutils/chroot.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/coreutils/chroot.c b/coreutils/chroot.c
index 34116a60e..1c64e08a9 100644
--- a/coreutils/chroot.c
+++ b/coreutils/chroot.c
@@ -38,6 +38,8 @@ static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n"
38 38
39int chroot_main(int argc, char **argv) 39int chroot_main(int argc, char **argv)
40{ 40{
41 char *prog;
42
41 if ((argc < 2) || (**(argv + 1) == '-')) { 43 if ((argc < 2) || (**(argv + 1) == '-')) {
42 usage(chroot_usage); 44 usage(chroot_usage);
43 } 45 }
@@ -45,27 +47,24 @@ int chroot_main(int argc, char **argv)
45 argv++; 47 argv++;
46 48
47 if (chroot(*argv) || (chdir("/"))) { 49 if (chroot(*argv) || (chdir("/"))) {
48 fprintf(stderr, "chroot: cannot change root directory to %s: %s\n", 50 fatalError("chroot: cannot change root directory to %s: %s\n",
49 *argv, strerror(errno)); 51 *argv, strerror(errno));
50 exit(FALSE);
51 } 52 }
52 53
53 argc--; 54 argc--;
54 argv++; 55 argv++;
55 if (argc >= 1) { 56 if (argc >= 1) {
56 fprintf(stderr, "command: %s\n", *argv); 57 prog = *argv;
57 execvp(*argv, argv); 58 execvp(*argv, argv);
58 } else { 59 } else {
59 char *prog;
60
61 prog = getenv("SHELL"); 60 prog = getenv("SHELL");
62 if (!prog) 61 if (!prog)
63 prog = "/bin/sh"; 62 prog = "/bin/sh";
64 execlp(prog, prog, NULL); 63 execlp(prog, prog, NULL);
65 } 64 }
66 fprintf(stderr, "chroot: cannot execute %s: %s\n", 65 fatalError("chroot: cannot execute %s: %s\n",
67 *argv, strerror(errno)); 66 prog, strerror(errno));
68 exit(FALSE); 67
69} 68}
70 69
71 70