1 /* $NetBSD: not.c,v 1.1.1.1 2009/02/18 11:17:34 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 /* did not exit correctly */ 31 return FAILURE; 32 } 33 /* return the opposite */ 34 return !WEXITSTATUS(status); 35 } 36 /* not accessible */ 37 return FAILURE; 38 } 39