1 /* $OpenBSD: kqueue-fork.c,v 1.2 2003/07/31 21:48:08 deraadt Exp $ */ 2 /* 3 * Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain 4 */ 5 6 #include <stdlib.h> 7 #include <stdio.h> 8 #include <err.h> 9 #include <unistd.h> 10 11 #include <sys/types.h> 12 #include <sys/event.h> 13 #include <sys/wait.h> 14 15 int check_inheritance(void); 16 17 int 18 check_inheritance(void) 19 { 20 int kq, status; 21 22 if ((kq = kqueue()) < 0) { 23 warn("kqueue"); 24 return (1); 25 } 26 27 /* 28 * Check if the kqueue is properly closed on fork(). 29 */ 30 31 switch (fork()) { 32 case -1: 33 err(1, "fork"); 34 case 0: 35 if (close(kq) < 0) 36 _exit(0); 37 warnx("fork didn't close kqueue"); 38 _exit(1); 39 } 40 if (wait(&status) < 0) 41 err(1, "wait"); 42 43 if (!WIFEXITED(status)) 44 errx(1, "child didn't exit?"); 45 46 close(kq); 47 return (WEXITSTATUS(status) != 0); 48 } 49