1 #include <sys/types.h> 2 #include <sys/socket.h> 3 #include <sys/un.h> 4 #include <sys/wait.h> 5 6 #include <err.h> 7 #include <errno.h> 8 #include <stdio.h> 9 #include <stdlib.h> 10 #include <unistd.h> 11 12 #define CHECKFD_CMD "checkfd" 13 #define CHECKFD_PATH "/usr/local/bin/" CHECKFD_CMD 14 15 int 16 main(void) 17 { 18 pid_t pid; 19 int s[2], status, ecode; 20 21 if (socketpair(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0, s) < 0) 22 err(1, "socketpair failed"); 23 24 pid = fork(); 25 if (pid < 0) { 26 err(1, "fork failed"); 27 } else if (pid == 0) { 28 char fd1[8], fd2[8]; 29 30 snprintf(fd1, sizeof(fd1), "%d", s[0]); 31 snprintf(fd2, sizeof(fd2), "%d", s[1]); 32 if (execl(CHECKFD_PATH, CHECKFD_CMD, fd1, fd2, NULL) < 0) 33 err(3, "execl failed"); 34 } 35 36 if (waitpid(pid, &status, 0) < 0) 37 err(1, "waitpid failed"); 38 39 if (!WIFEXITED(status)) 40 errx(1, CHECKFD_CMD " did not exit"); 41 42 ecode = WEXITSTATUS(status); 43 if (ecode != 0) { 44 warnx("exit code %d", ecode); 45 abort(); 46 } 47 48 fprintf(stderr, "passed\n"); 49 exit(0); 50 } 51