aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2000-06-02 17:56:45 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2000-06-02 17:56:45 +0000
commitc296b7eab6d41fa34da0c6ffed0743566ca1c1e9 (patch)
tree51eacc49fad57b2d4d0f63da4da31dd7a7384918
parent79a909120a817629d5b739fba7cedf2a5f2bff8b (diff)
downloadbusybox-w32-c296b7eab6d41fa34da0c6ffed0743566ca1c1e9.tar.gz
busybox-w32-c296b7eab6d41fa34da0c6ffed0743566ca1c1e9.tar.bz2
busybox-w32-c296b7eab6d41fa34da0c6ffed0743566ca1c1e9.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 git-svn-id: svn://busybox.net/trunk/busybox@601 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--chroot.c15
-rw-r--r--coreutils/chroot.c15
2 files changed, 14 insertions, 16 deletions
diff --git a/chroot.c b/chroot.c
index 34116a60e..1c64e08a9 100644
--- a/chroot.c
+++ b/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
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