1 /* 2 * Copyright (c) 1988 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 char copyright[] = 10 "@(#) Copyright (c) 1988 The Regents of the University of California.\n\ 11 All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)chroot.c 5.8 (Berkeley) 06/01/90"; 16 #endif /* not lint */ 17 18 #include <stdio.h> 19 #include <paths.h> 20 21 main(argc, argv) 22 int argc; 23 char **argv; 24 { 25 extern int errno; 26 char *shell, *getenv(), *strerror(); 27 28 if (argc < 2) { 29 (void)fprintf(stderr, "usage: chroot newroot [command]\n"); 30 exit(1); 31 } 32 if (chdir(argv[1]) || chroot(".")) 33 fatal(argv[1]); 34 if (argv[2]) { 35 execvp(argv[2], &argv[2]); 36 fatal(argv[2]); 37 } else { 38 if (!(shell = getenv("SHELL"))) 39 shell = _PATH_BSHELL; 40 execlp(shell, shell, "-i", (char *)NULL); 41 fatal(shell); 42 } 43 /* NOTREACHED */ 44 } 45 46 fatal(msg) 47 char *msg; 48 { 49 extern int errno; 50 51 (void)fprintf(stderr, "chroot: %s: %s\n", msg, strerror(errno)); 52 exit(1); 53 } 54