1*7d2cda35Schristos /* $NetBSD: h_fexecve.c,v 1.1 2019/09/15 16:53:58 christos Exp $ */
2*7d2cda35Schristos
3*7d2cda35Schristos /*-
4*7d2cda35Schristos * Copyright (c) 2019 The NetBSD Foundation, Inc.
5*7d2cda35Schristos * All rights reserved.
6*7d2cda35Schristos *
7*7d2cda35Schristos * This code is derived from software contributed to The NetBSD Foundation
8*7d2cda35Schristos * by Christos Zoulas.
9*7d2cda35Schristos *
10*7d2cda35Schristos * Redistribution and use in source and binary forms, with or without
11*7d2cda35Schristos * modification, are permitted provided that the following conditions
12*7d2cda35Schristos * are met:
13*7d2cda35Schristos * 1. Redistributions of source code must retain the above copyright
14*7d2cda35Schristos * notice, this list of conditions and the following disclaimer.
15*7d2cda35Schristos * 2. Redistributions in binary form must reproduce the above copyright
16*7d2cda35Schristos * notice, this list of conditions and the following disclaimer in the
17*7d2cda35Schristos * documentation and/or other materials provided with the distribution.
18*7d2cda35Schristos *
19*7d2cda35Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*7d2cda35Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*7d2cda35Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*7d2cda35Schristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*7d2cda35Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*7d2cda35Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*7d2cda35Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*7d2cda35Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*7d2cda35Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*7d2cda35Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*7d2cda35Schristos * POSSIBILITY OF SUCH DAMAGE.
30*7d2cda35Schristos */
31*7d2cda35Schristos #include <sys/cdefs.h>
32*7d2cda35Schristos __RCSID("$NetBSD: h_fexecve.c,v 1.1 2019/09/15 16:53:58 christos Exp $");
33*7d2cda35Schristos
34*7d2cda35Schristos #include <unistd.h>
35*7d2cda35Schristos #include <fcntl.h>
36*7d2cda35Schristos #include <stdlib.h>
37*7d2cda35Schristos #include <err.h>
38*7d2cda35Schristos
39*7d2cda35Schristos int
main(int argc,char * argv[])40*7d2cda35Schristos main(int argc, char *argv[])
41*7d2cda35Schristos {
42*7d2cda35Schristos char *args[] = { argv[1], NULL };
43*7d2cda35Schristos int fd = open(args[0], O_RDONLY);
44*7d2cda35Schristos if (fd == -1)
45*7d2cda35Schristos err(EXIT_FAILURE, "open %s", args[0]);
46*7d2cda35Schristos if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
47*7d2cda35Schristos err(EXIT_FAILURE, "fcntl");
48*7d2cda35Schristos if (fexecve(fd, args, NULL) == -1)
49*7d2cda35Schristos err(EXIT_FAILURE, "fexecve");
50*7d2cda35Schristos return EXIT_SUCCESS;
51*7d2cda35Schristos }
52