xref: /dragonfly/contrib/lvm2/dist/test/not.c (revision ef2b2b9d)
1 /*	$NetBSD: not.c,v 1.1.1.2 2009/12/02 00:25:58 haad Exp $	*/
2 
3 #include <unistd.h>
4 #include <stdio.h>
5 #include <stdarg.h>
6 #include <sys/types.h>
7 #include <sys/wait.h>
8 
9 int main(int args, char **argv) {
10 	pid_t pid;
11 	int status;
12 	int FAILURE = 6;
13 
14 	if (args < 2) {
15 		fprintf(stderr, "Need args\n");
16 		return FAILURE;
17 	}
18 
19 	pid = fork();
20 	if (pid == -1) {
21 		fprintf(stderr, "Could not fork\n");
22 		return FAILURE;
23 	} else if (pid == 0) { 	/* child */
24 		execvp(argv[1], &argv[1]);
25 		/* should not be accessible */
26 		return FAILURE;
27 	} else {		/* parent */
28 		waitpid(pid, &status, 0);
29 		if (!WIFEXITED(status)) {
30 			if (WIFSIGNALED(status))
31 				fprintf(stderr,
32 					"Process %d died of signal %d.\n",
33 					pid, WTERMSIG(status));
34 			/* did not exit correctly */
35 			return FAILURE;
36 		}
37 		/* return the opposite */
38 		return !WEXITSTATUS(status);
39 	}
40 	/* not accessible */
41 	return FAILURE;
42 }
43