From 9ed0a7c2a5258bc441bb35a3c9f10b7676232e24 Mon Sep 17 00:00:00 2001 From: guenther Date: Wed, 4 Aug 2010 06:05:26 +0000 Subject: [PATCH] Regression test for the recent rfork+kqueue fix --- regress/sys/kern/rfork/kqueue/Makefile | 5 +++ regress/sys/kern/rfork/kqueue/kqueue.c | 50 ++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 regress/sys/kern/rfork/kqueue/Makefile create mode 100644 regress/sys/kern/rfork/kqueue/kqueue.c diff --git a/regress/sys/kern/rfork/kqueue/Makefile b/regress/sys/kern/rfork/kqueue/Makefile new file mode 100644 index 00000000000..7a3dcf68cc5 --- /dev/null +++ b/regress/sys/kern/rfork/kqueue/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2010/08/04 06:05:26 guenther Exp $ + +PROG=kqueue + +.include diff --git a/regress/sys/kern/rfork/kqueue/kqueue.c b/regress/sys/kern/rfork/kqueue/kqueue.c new file mode 100644 index 00000000000..f21fadc5798 --- /dev/null +++ b/regress/sys/kern/rfork/kqueue/kqueue.c @@ -0,0 +1,50 @@ +/* $OpenBSD: kqueue.c,v 1.1 2010/08/04 06:05:26 guenther Exp $ */ +/* + * Written by Philip Guenther , 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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; +} -- 2.20.1