aboutsummaryrefslogtreecommitdiff
path: root/chroot.c
diff options
context:
space:
mode:
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 d39549496..3b6fdae3b 100644
--- a/chroot.c
+++ b/chroot.c
@@ -20,8 +20,9 @@
20 */ 20 */
21 21
22#include "internal.h" 22#include "internal.h"
23#include <stdlib.h>
23#include <stdio.h> 24#include <stdio.h>
24#include <unistd.h> 25#include <errno.h>
25 26
26 27
27static const char chroot_usage[] = "NEWROOT [COMMAND...]\n" 28static const char chroot_usage[] = "NEWROOT [COMMAND...]\n"
@@ -31,18 +32,17 @@ static const char chroot_usage[] = "NEWROOT [COMMAND...]\n"
31 32
32int chroot_main(int argc, char **argv) 33int chroot_main(int argc, char **argv)
33{ 34{
34 if (argc < 2) { 35 if ( (argc < 2) || (**(argv+1) == '-') ) {
35 fprintf(stderr, "Usage: %s %s", *argv, chroot_usage); 36 fprintf(stderr, "Usage: %s %s", *argv, chroot_usage);
36 return( FALSE); 37 exit( FALSE);
37 } 38 }
38 argc--; 39 argc--;
39 argv++; 40 argv++;
40 41
41 fprintf(stderr, "new root: %s\n", *argv);
42
43 if (chroot (*argv) || (chdir ("/"))) { 42 if (chroot (*argv) || (chdir ("/"))) {
44 perror("cannot chroot"); 43 fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
45 return( FALSE); 44 *argv, strerror(errno));
45 exit( FALSE);
46 } 46 }
47 47
48 argc--; 48 argc--;
@@ -56,10 +56,10 @@ int chroot_main(int argc, char **argv)
56 prog = getenv ("SHELL"); 56 prog = getenv ("SHELL");
57 if (!prog) 57 if (!prog)
58 prog = "/bin/sh"; 58 prog = "/bin/sh";
59 fprintf(stderr, "no command. running: %s\n", prog);
60 execlp (prog, prog, NULL); 59 execlp (prog, prog, NULL);
61 } 60 }
62 perror("cannot exec"); 61 fprintf(stderr, "chroot: cannot execute %s: %s\n",
63 return(FALSE); 62 *argv, strerror(errno));
63 exit( FALSE);
64} 64}
65 65