aboutsummaryrefslogtreecommitdiff
path: root/chroot.c
diff options
context:
space:
mode:
Diffstat (limited to 'chroot.c')
-rw-r--r--chroot.c73
1 files changed, 53 insertions, 20 deletions
diff --git a/chroot.c b/chroot.c
index ca0bfcf3f..d39549496 100644
--- a/chroot.c
+++ b/chroot.c
@@ -1,32 +1,65 @@
1/*
2 * Mini chroot implementation for busybox
3 *
4 * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
1#include "internal.h" 22#include "internal.h"
2#include <stdio.h> 23#include <stdio.h>
3#include <unistd.h> 24#include <unistd.h>
4 25
5 26
6const char chroot_usage[] = "chroot directory [command]\n" 27static const char chroot_usage[] = "NEWROOT [COMMAND...]\n"
7 "Run a command with special root directory.\n"; 28"Run COMMAND with root directory set to NEWROOT.\n";
29
30
8 31
9extern int 32int chroot_main(int argc, char **argv)
10chroot_main (struct FileInfo *i, int argc, char **argv)
11{ 33{
12 char *prog; 34 if (argc < 2) {
35 fprintf(stderr, "Usage: %s %s", *argv, chroot_usage);
36 return( FALSE);
37 }
38 argc--;
39 argv++;
13 40
14 if (chroot (argv[1])) 41 fprintf(stderr, "new root: %s\n", *argv);
15 { 42
16 name_and_error ("cannot chroot to that directory"); 43 if (chroot (*argv) || (chdir ("/"))) {
17 return 1; 44 perror("cannot chroot");
45 return( FALSE);
18 } 46 }
19 if (argc > 2) 47
20 { 48 argc--;
21 execvp (argv[2], argv + 2); 49 argv++;
50 if (argc >= 1) {
51 fprintf(stderr, "command: %s\n", *argv);
52 execvp (*argv, argv);
22 } 53 }
23 else 54 else {
24 { 55 char *prog;
25 prog = getenv ("SHELL"); 56 prog = getenv ("SHELL");
26 if (!prog) 57 if (!prog)
27 prog = "/bin/sh"; 58 prog = "/bin/sh";
28 execlp (prog, prog, NULL); 59 fprintf(stderr, "no command. running: %s\n", prog);
60 execlp (prog, prog, NULL);
29 } 61 }
30 name_and_error ("cannot exec"); 62 perror("cannot exec");
31 return 1; 63 return(FALSE);
32} 64}
65