1bbf12e6fSEnji Cooper /* $NetBSD: doexec.c,v 1.8 2003/07/26 19:38:48 salo Exp $ */
2bbf12e6fSEnji Cooper
3bbf12e6fSEnji Cooper /*
4bbf12e6fSEnji Cooper * Copyright (c) 1993 Christopher G. Demetriou
5bbf12e6fSEnji Cooper * All rights reserved.
6bbf12e6fSEnji Cooper *
7bbf12e6fSEnji Cooper * Redistribution and use in source and binary forms, with or without
8bbf12e6fSEnji Cooper * modification, are permitted provided that the following conditions
9bbf12e6fSEnji Cooper * are met:
10bbf12e6fSEnji Cooper * 1. Redistributions of source code must retain the above copyright
11bbf12e6fSEnji Cooper * notice, this list of conditions and the following disclaimer.
12bbf12e6fSEnji Cooper * 2. Redistributions in binary form must reproduce the above copyright
13bbf12e6fSEnji Cooper * notice, this list of conditions and the following disclaimer in the
14bbf12e6fSEnji Cooper * documentation and/or other materials provided with the distribution.
15bbf12e6fSEnji Cooper * 3. All advertising materials mentioning features or use of this software
16bbf12e6fSEnji Cooper * must display the following acknowledgement:
17bbf12e6fSEnji Cooper * This product includes software developed for the
18bbf12e6fSEnji Cooper * NetBSD Project. See http://www.NetBSD.org/ for
19bbf12e6fSEnji Cooper * information about NetBSD.
20bbf12e6fSEnji Cooper * 4. The name of the author may not be used to endorse or promote products
21bbf12e6fSEnji Cooper * derived from this software without specific prior written permission.
22bbf12e6fSEnji Cooper *
23bbf12e6fSEnji Cooper * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24bbf12e6fSEnji Cooper * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25bbf12e6fSEnji Cooper * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26bbf12e6fSEnji Cooper * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27bbf12e6fSEnji Cooper * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28bbf12e6fSEnji Cooper * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29bbf12e6fSEnji Cooper * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30bbf12e6fSEnji Cooper * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31bbf12e6fSEnji Cooper * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32bbf12e6fSEnji Cooper * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33bbf12e6fSEnji Cooper */
34bbf12e6fSEnji Cooper
35bbf12e6fSEnji Cooper #include <err.h>
36bbf12e6fSEnji Cooper #include <errno.h>
37bbf12e6fSEnji Cooper #include <stdio.h>
38bbf12e6fSEnji Cooper #include <stdlib.h>
39*e5b431fcSKyle Evans #include <string.h>
40bbf12e6fSEnji Cooper #include <unistd.h>
41bbf12e6fSEnji Cooper
42*e5b431fcSKyle Evans /* Passing -n == null_argv */
43*e5b431fcSKyle Evans static char * const null_argv[] = { NULL };
44*e5b431fcSKyle Evans
45bbf12e6fSEnji Cooper int
main(int argc,char ** argv)46bbf12e6fSEnji Cooper main(int argc, char **argv)
47bbf12e6fSEnji Cooper {
48bbf12e6fSEnji Cooper
49*e5b431fcSKyle Evans if (argc == 2) {
50*e5b431fcSKyle Evans execve(argv[1], &argv[1], NULL);
51*e5b431fcSKyle Evans } else if (argc == 3 && strcmp(argv[1], "-n") == 0) {
52*e5b431fcSKyle Evans execve(argv[2], null_argv, NULL);
53*e5b431fcSKyle Evans } else {
54*e5b431fcSKyle Evans fprintf(stderr, "usage: %s [-n] <progname>\n", argv[0]);
55bbf12e6fSEnji Cooper exit(2);
56bbf12e6fSEnji Cooper }
57bbf12e6fSEnji Cooper
58dcdb30d8SEnji Cooper err(1, "execve failed");
59bbf12e6fSEnji Cooper }
60