summaryrefslogtreecommitdiff
path: root/regress/sys
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2002-02-17 05:58:52 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2002-02-17 05:58:52 +0000
commitd3080c0f4a2103fa928e860b19cc48a36d8b12e6 (patch)
tree67048cfb67e75883f251f21dfbd8eba8d48c733b /regress/sys
parentfc2e0e700ae1298557909c65c9fa9d5768fb9982 (diff)
Not really a test for rfork, but for the kernel fd handling.
But since it uses rfork a lot is will end up here. This is a few nasty operations in the right order that can cause serious confusion in the kernel if the file descriptor handling is not done right.
Diffstat (limited to 'regress/sys')
-rw-r--r--regress/sys/kern/rfork/madness/Makefile5
-rw-r--r--regress/sys/kern/rfork/madness/madness.c54
2 files changed, 59 insertions, 0 deletions
diff --git a/regress/sys/kern/rfork/madness/Makefile b/regress/sys/kern/rfork/madness/Makefile
new file mode 100644
index 00000000000..d44f5ff2b76
--- /dev/null
+++ b/regress/sys/kern/rfork/madness/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2002/02/17 05:58:51 art Exp $
+
+PROG=madness
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/kern/rfork/madness/madness.c b/regress/sys/kern/rfork/madness/madness.c
new file mode 100644
index 00000000000..b5002413eaf
--- /dev/null
+++ b/regress/sys/kern/rfork/madness/madness.c
@@ -0,0 +1,54 @@
+/* $OpenBSD: madness.c,v 1.1 2002/02/17 05:58:51 art Exp $ */
+/*
+ * Written by Artur Grabowski <art@openbsd.org>, 2002 Public Domain.
+ */
+#include <sys/param.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <err.h>
+
+volatile int step;
+
+int
+main()
+{
+ int fds[2], fd;
+ pid_t pid1, pid2, pid3;
+
+ if (pipe(fds) < 0)
+ err(1, "pipe");
+
+ fd = fds[0];
+
+ if ((pid1 = rfork(RFPROC|RFMEM|RFFDG|RFNOWAIT)) == 0) {
+ char foo[1024];
+ step = 1;
+ read(fd, foo, sizeof(foo));
+ _exit(0);
+ }
+
+ if ((pid2 = rfork(RFPROC|RFMEM|RFFDG|RFNOWAIT)) == 0) {
+ while (step < 1)
+ sleep(1);
+ sleep(1);
+ step = 2;
+ close(fd);
+ _exit(0);
+ }
+ if ((pid3 = rfork(RFPROC|RFMEM|RFFDG|RFNOWAIT)) == 0) {
+ while (step < 2)
+ sleep(1);
+ sleep(1);
+ step = 3;
+ dup2(0, fd);
+ _exit(0);
+ }
+ while (step < 3)
+ sleep(1);
+ sleep(1);
+ kill(pid1, SIGKILL);
+ kill(pid2, SIGKILL);
+ kill(pid3, SIGKILL);
+ return 0;
+}