allow null defaults in $( ... $) lookups
[unix-history] / usr / src / usr.sbin / chroot / chroot.c
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* %sccs.include.redist.c%
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1988, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)chroot.c 8.1 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
#include <err.h>
#include <errno.h>
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
void usage __P((void));
int
main(argc, argv)
int argc;
char *argv[];
{
int ch;
char *shell;
while ((ch = getopt(argc, argv, "")) != EOF)
switch(ch) {
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
if (argc < 1)
usage();
if (chdir(argv[0]) || chroot("."))
err(1, "%s", argv[0]);
if (argv[1]) {
execvp(argv[1], &argv[1]);
err(1, "%s", argv[1]);
}
if (!(shell = getenv("SHELL")))
shell = _PATH_BSHELL;
execlp(shell, shell, "-i", NULL);
err(1, "%s", shell);
/* NOTREACHED */
}
void
usage()
{
(void)fprintf(stderr, "usage: chroot newroot [command]\n");
exit(1);
}