Commit | Line | Data |
---|---|---|
94a602c5 | 1 | /* |
9bfc7c75 KB |
2 | * Copyright (c) 1988, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
94a602c5 | 4 | * |
32ce521f | 5 | * %sccs.include.redist.c% |
94a602c5 KB |
6 | */ |
7 | ||
8 | #ifndef lint | |
9bfc7c75 KB |
9 | static char copyright[] = |
10 | "@(#) Copyright (c) 1988, 1993\n\ | |
11 | The Regents of the University of California. All rights reserved.\n"; | |
94a602c5 KB |
12 | #endif /* not lint */ |
13 | ||
14 | #ifndef lint | |
9bfc7c75 | 15 | static char sccsid[] = "@(#)chroot.c 8.1 (Berkeley) %G%"; |
94a602c5 KB |
16 | #endif /* not lint */ |
17 | ||
53a143fe KB |
18 | #include <sys/types.h> |
19 | ||
d04e07d5 | 20 | #include <err.h> |
53a143fe | 21 | #include <errno.h> |
7abf8d65 | 22 | #include <paths.h> |
53a143fe KB |
23 | #include <stdio.h> |
24 | #include <stdlib.h> | |
25 | #include <string.h> | |
26 | #include <unistd.h> | |
94a602c5 | 27 | |
53a143fe KB |
28 | void usage __P((void)); |
29 | ||
30 | int | |
94a602c5 KB |
31 | main(argc, argv) |
32 | int argc; | |
53a143fe | 33 | char *argv[]; |
397de7ad | 34 | { |
53a143fe KB |
35 | int ch; |
36 | char *shell; | |
37 | ||
38 | while ((ch = getopt(argc, argv, "")) != EOF) | |
39 | switch(ch) { | |
40 | case '?': | |
41 | default: | |
42 | usage(); | |
43 | } | |
44 | argc -= optind; | |
45 | argv += optind; | |
46 | ||
d04e07d5 | 47 | if (argc < 1) |
53a143fe | 48 | usage(); |
94a602c5 | 49 | |
d04e07d5 KB |
50 | if (chdir(argv[0]) || chroot(".")) |
51 | err(1, "%s", argv[0]); | |
52 | ||
53 | if (argv[1]) { | |
54 | execvp(argv[1], &argv[1]); | |
55 | err(1, "%s", argv[1]); | |
d4f5e936 | 56 | } |
d4f5e936 | 57 | |
d04e07d5 KB |
58 | if (!(shell = getenv("SHELL"))) |
59 | shell = _PATH_BSHELL; | |
60 | execlp(shell, shell, "-i", NULL); | |
61 | err(1, "%s", shell); | |
62 | /* NOTREACHED */ | |
397de7ad | 63 | } |
53a143fe KB |
64 | |
65 | void | |
66 | usage() | |
67 | { | |
68 | (void)fprintf(stderr, "usage: chroot newroot [command]\n"); | |
69 | exit(1); | |
70 | } |