summaryrefslogtreecommitdiff
path: root/chroot.c
diff options
context:
space:
mode:
authorEric Andersen1999-10-12 15:42:48 +0000
committerEric Andersen1999-10-12 15:42:48 +0000
commit2ce1edcf544ac675e6762c9861a6b918401ea716 (patch)
tree34245558cd448f01969679fc420de4dfd246dc13 /chroot.c
parentf811e07b072600a3784a92e5a1dc8a93dac477eb (diff)
downloadbusybox-2ce1edcf544ac675e6762c9861a6b918401ea716.zip
busybox-2ce1edcf544ac675e6762c9861a6b918401ea716.tar.gz
Latest and greatest.
-Erik
Diffstat (limited to 'chroot.c')
-rw-r--r--chroot.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/chroot.c b/chroot.c
index d395494..3b6fdae 100644
--- a/chroot.c
+++ b/chroot.c
@@ -20,8 +20,9 @@
*/
#include "internal.h"
+#include <stdlib.h>
#include <stdio.h>
-#include <unistd.h>
+#include <errno.h>
static const char chroot_usage[] = "NEWROOT [COMMAND...]\n"
@@ -31,18 +32,17 @@ static const char chroot_usage[] = "NEWROOT [COMMAND...]\n"
int chroot_main(int argc, char **argv)
{
- if (argc < 2) {
+ if ( (argc < 2) || (**(argv+1) == '-') ) {
fprintf(stderr, "Usage: %s %s", *argv, chroot_usage);
- return( FALSE);
+ exit( FALSE);
}
argc--;
argv++;
- fprintf(stderr, "new root: %s\n", *argv);
-
if (chroot (*argv) || (chdir ("/"))) {
- perror("cannot chroot");
- return( FALSE);
+ fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
+ *argv, strerror(errno));
+ exit( FALSE);
}
argc--;
@@ -56,10 +56,10 @@ int chroot_main(int argc, char **argv)
prog = getenv ("SHELL");
if (!prog)
prog = "/bin/sh";
- fprintf(stderr, "no command. running: %s\n", prog);
execlp (prog, prog, NULL);
}
- perror("cannot exec");
- return(FALSE);
+ fprintf(stderr, "chroot: cannot execute %s: %s\n",
+ *argv, strerror(errno));
+ exit( FALSE);
}