summaryrefslogtreecommitdiffstats
path: root/regress/sys/kern/kqueue/kqueue-fork.c
diff options
context:
space:
mode:
authorart <art@openbsd.org>2002-02-27 17:11:51 +0000
committerart <art@openbsd.org>2002-02-27 17:11:51 +0000
commit5a789c51c16dd34f9133b9f4591f84df7c95fc62 (patch)
tree3eb3a8f3dce93985222b8b7703ba160cd8174a24 /regress/sys/kern/kqueue/kqueue-fork.c
parentCorrect plural/singular in one sentence, omitting protocol specification (diff)
downloadwireguard-openbsd-5a789c51c16dd34f9133b9f4591f84df7c95fc62.tar.xz
wireguard-openbsd-5a789c51c16dd34f9133b9f4591f84df7c95fc62.zip
Add a test for inheriting kqueue descriptors on fork.
Diffstat (limited to 'regress/sys/kern/kqueue/kqueue-fork.c')
-rw-r--r--regress/sys/kern/kqueue/kqueue-fork.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/regress/sys/kern/kqueue/kqueue-fork.c b/regress/sys/kern/kqueue/kqueue-fork.c
new file mode 100644
index 00000000000..497ffbd90a5
--- /dev/null
+++ b/regress/sys/kern/kqueue/kqueue-fork.c
@@ -0,0 +1,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);
+}