1 /* $OpenBSD: main.c,v 1.1.1.1 2018/04/10 23:00:53 bluhm Exp $ */
2 /*
3 * Copyright (c) 2018 Alexander Bluhm <bluhm@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 #include <err.h>
19 #include <fcntl.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23
24 #include "header.h"
25
26 int
main(int argc,char * argv[])27 main(int argc, char *argv[])
28 {
29 char *cmd;
30 pid_t self;
31 int fdpre, fdpost, ret;
32
33 if ((fdpre = open("/dev/null", O_RDONLY)) == -1)
34 err(1, "open pre");
35 if (pledge("exec stdio proc recvfd rpath sendfd", NULL) == -1)
36 err(1, "pledge");
37 if ((fdpost = open("/dev/null", O_RDONLY)) == -1)
38 err(1, "open post");
39
40 fdops(fdpre, fdpost);
41
42 self = getpid();
43 if (asprintf(&cmd, "/usr/bin/fstat -p %d", self) == -1)
44 err(1, "asprintf");
45 ret = system(cmd);
46 switch (ret) {
47 case -1:
48 err(1, "system");
49 case 0:
50 break;
51 default:
52 errx(1, "'%s' failed: %d", cmd, ret);
53 }
54 free(cmd);
55
56 return 0;
57 }
58