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