Regression test for the recent rfork+kqueue fix
authorguenther <guenther@openbsd.org>
Wed, 4 Aug 2010 06:05:26 +0000 (06:05 +0000)
committerguenther <guenther@openbsd.org>
Wed, 4 Aug 2010 06:05:26 +0000 (06:05 +0000)
regress/sys/kern/rfork/kqueue/Makefile [new file with mode: 0644]
regress/sys/kern/rfork/kqueue/kqueue.c [new file with mode: 0644]

diff --git a/regress/sys/kern/rfork/kqueue/Makefile b/regress/sys/kern/rfork/kqueue/Makefile
new file mode 100644 (file)
index 0000000..7a3dcf6
--- /dev/null
@@ -0,0 +1,5 @@
+#      $OpenBSD: Makefile,v 1.1 2010/08/04 06:05:26 guenther Exp $
+
+PROG=kqueue
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/kern/rfork/kqueue/kqueue.c b/regress/sys/kern/rfork/kqueue/kqueue.c
new file mode 100644 (file)
index 0000000..f21fadc
--- /dev/null
@@ -0,0 +1,50 @@
+/*     $OpenBSD: kqueue.c,v 1.1 2010/08/04 06:05:26 guenther Exp $     */
+/*
+ * Written by Philip Guenther <guenther@openbsd.org>, 2010 Public Domain.
+ *
+ * Verify that having a process exit while it has knotes attached to it
+ * that are from a kqueue that is open in another process doesn't cause
+ * problems.
+ */
+#include <sys/param.h>
+#include <sys/event.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <err.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int
+main(int argc, char *argv[])
+{
+       struct kevent ev;
+       int status;
+       int kq;
+
+       if ((kq = kqueue()) < 0)
+               err(1, "kqueue");
+
+       signal(SIGINT, SIG_IGN);
+       EV_SET(&ev, SIGINT, EVFILT_SIGNAL, EV_ADD|EV_ENABLE, 0, 0, 0);
+
+       switch(rfork(RFPROC)) {
+       case -1:
+               err(1, "rfork");
+       case 0:
+               if (kevent(kq, &ev, 1, NULL, 0, NULL))
+                       err(1, "kevent");
+               raise(SIGINT);
+               _exit(0);
+       }
+
+       if (wait(&status) < 0)
+               err(1, "wait");
+
+       if (!WIFEXITED(status))
+               err(1, "child error");
+
+       return WEXITSTATUS(status) != 0;
+}