diff options
Diffstat (limited to 'chroot.c')
-rw-r--r-- | chroot.c | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -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)); + } |