summaryrefslogtreecommitdiff
path: root/regress/sys/kern/kqueue/kqueue-fork.c
blob: 497ffbd90a5728833f2b2df8c7536b9b75ff0a5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*	$OpenBSD: kqueue-fork.c,v 1.1 2002/02/27 17:11:51 art Exp $	*/
/*
 *	Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain
 */

#include <stdlib.h>
#include <stdio.h>
#include <err.h>
#include <unistd.h>

#include <sys/types.h>
#include <sys/event.h>
#include <sys/wait.h>

int
check_inheritance(void)
{
	int kq, status;

	if ((kq = kqueue()) < 0) {
		warn("kqueue");
		return (1);
	}

	/*
	 * Check if the kqueue is properly closed on fork().
	 */

	switch (fork()) {
	case -1:
		err(1, "fork");
	case 0:
		if (close(kq) < 0)
			_exit(0);
		warnx("fork didn't close kqueue");
		_exit(1);
	}
	if (wait(&status) < 0)
		err(1, "wait");

	if (!WIFEXITED(status))
		errx(1, "child didn't exit?");

	close(kq);
	return (WEXITSTATUS(status) != 0);
}