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
This commit is contained in:
Eric Andersen 2000-06-02 17:56:45 +00:00
parent 9c8ffa02f4
commit 808d03ec19
2 changed files with 14 additions and 16 deletions

View File

@ -38,6 +38,8 @@ static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n"
int chroot_main(int argc, char **argv) int chroot_main(int argc, char **argv)
{ {
char *prog;
if ((argc < 2) || (**(argv + 1) == '-')) { if ((argc < 2) || (**(argv + 1) == '-')) {
usage(chroot_usage); usage(chroot_usage);
} }
@ -45,27 +47,24 @@ int chroot_main(int argc, char **argv)
argv++; argv++;
if (chroot(*argv) || (chdir("/"))) { 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)); *argv, strerror(errno));
exit(FALSE);
} }
argc--; argc--;
argv++; argv++;
if (argc >= 1) { if (argc >= 1) {
fprintf(stderr, "command: %s\n", *argv); prog = *argv;
execvp(*argv, argv); execvp(*argv, argv);
} else { } else {
char *prog;
prog = getenv("SHELL"); prog = getenv("SHELL");
if (!prog) if (!prog)
prog = "/bin/sh"; prog = "/bin/sh";
execlp(prog, prog, NULL); execlp(prog, prog, NULL);
} }
fprintf(stderr, "chroot: cannot execute %s: %s\n", fatalError("chroot: cannot execute %s: %s\n",
*argv, strerror(errno)); prog, strerror(errno));
exit(FALSE);
} }

View File

@ -38,6 +38,8 @@ static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n"
int chroot_main(int argc, char **argv) int chroot_main(int argc, char **argv)
{ {
char *prog;
if ((argc < 2) || (**(argv + 1) == '-')) { if ((argc < 2) || (**(argv + 1) == '-')) {
usage(chroot_usage); usage(chroot_usage);
} }
@ -45,27 +47,24 @@ int chroot_main(int argc, char **argv)
argv++; argv++;
if (chroot(*argv) || (chdir("/"))) { 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)); *argv, strerror(errno));
exit(FALSE);
} }
argc--; argc--;
argv++; argv++;
if (argc >= 1) { if (argc >= 1) {
fprintf(stderr, "command: %s\n", *argv); prog = *argv;
execvp(*argv, argv); execvp(*argv, argv);
} else { } else {
char *prog;
prog = getenv("SHELL"); prog = getenv("SHELL");
if (!prog) if (!prog)
prog = "/bin/sh"; prog = "/bin/sh";
execlp(prog, prog, NULL); execlp(prog, prog, NULL);
} }
fprintf(stderr, "chroot: cannot execute %s: %s\n", fatalError("chroot: cannot execute %s: %s\n",
*argv, strerror(errno)); prog, strerror(errno));
exit(FALSE);
} }