From 808d03ec19e0c8f0c06d9a9defb85fc9a1100441 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Fri, 2 Jun 2000 17:56:45 +0000 Subject: 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 --- chroot.c | 15 +++++++-------- coreutils/chroot.c | 15 +++++++-------- 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" int chroot_main(int argc, char **argv) { + char *prog; + if ((argc < 2) || (**(argv + 1) == '-')) { usage(chroot_usage); } @@ -45,27 +47,24 @@ int chroot_main(int argc, char **argv) argv++; if (chroot(*argv) || (chdir("/"))) { - fprintf(stderr, "chroot: cannot change root directory to %s: %s\n", + fatalError("chroot: cannot change root directory to %s: %s\n", *argv, strerror(errno)); - exit(FALSE); } argc--; argv++; if (argc >= 1) { - fprintf(stderr, "command: %s\n", *argv); + prog = *argv; execvp(*argv, argv); } else { - char *prog; - prog = getenv("SHELL"); if (!prog) prog = "/bin/sh"; execlp(prog, prog, NULL); } - fprintf(stderr, "chroot: cannot execute %s: %s\n", - *argv, strerror(errno)); - exit(FALSE); + fatalError("chroot: cannot execute %s: %s\n", + prog, strerror(errno)); + } 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" int chroot_main(int argc, char **argv) { + char *prog; + if ((argc < 2) || (**(argv + 1) == '-')) { usage(chroot_usage); } @@ -45,27 +47,24 @@ int chroot_main(int argc, char **argv) argv++; if (chroot(*argv) || (chdir("/"))) { - fprintf(stderr, "chroot: cannot change root directory to %s: %s\n", + fatalError("chroot: cannot change root directory to %s: %s\n", *argv, strerror(errno)); - exit(FALSE); } argc--; argv++; if (argc >= 1) { - fprintf(stderr, "command: %s\n", *argv); + prog = *argv; execvp(*argv, argv); } else { - char *prog; - prog = getenv("SHELL"); if (!prog) prog = "/bin/sh"; execlp(prog, prog, NULL); } - fprintf(stderr, "chroot: cannot execute %s: %s\n", - *argv, strerror(errno)); - exit(FALSE); + fatalError("chroot: cannot execute %s: %s\n", + prog, strerror(errno)); + } -- cgit v1.2.3