summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2002-02-17 05:10:41 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2002-02-17 05:10:41 +0000
commit770c6cd40718fc4d63d12dce4e750030d8d70057 (patch)
tree8aba5f9b813f7e87b48955875759214f98a3d0c0
parentf3fa53eb6d27bd26edde5be900b5bf620297b4bf (diff)
Test rfork(RFMEM)
-rw-r--r--regress/sys/kern/rfork/rfmem/Makefile5
-rw-r--r--regress/sys/kern/rfork/rfmem/rfmem.c49
2 files changed, 54 insertions, 0 deletions
diff --git a/regress/sys/kern/rfork/rfmem/Makefile b/regress/sys/kern/rfork/rfmem/Makefile
new file mode 100644
index 00000000000..3e2df82ce58
--- /dev/null
+++ b/regress/sys/kern/rfork/rfmem/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2002/02/17 05:10:40 art Exp $
+
+PROG=rfmem
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/kern/rfork/rfmem/rfmem.c b/regress/sys/kern/rfork/rfmem/rfmem.c
new file mode 100644
index 00000000000..5dbf96f7921
--- /dev/null
+++ b/regress/sys/kern/rfork/rfmem/rfmem.c
@@ -0,0 +1,49 @@
+/* $OpenBSD: rfmem.c,v 1.1 2002/02/17 05:10:40 art Exp $ */
+/*
+ * Written by Artur Grabowski <art@openbsd.org>, 2002 Public Domain.
+ */
+#include <sys/param.h>
+#include <sys/wait.h>
+#include <sys/mman.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <err.h>
+
+#define MAGIC "inherited"
+
+int
+main()
+{
+ void *map;
+ int page_size;
+ int status;
+
+ page_size = getpagesize();
+
+ if ((map = mmap(NULL, page_size, PROT_READ|PROT_WRITE, MAP_ANON,
+ -1, 0)) == MAP_FAILED)
+ err(1, "mmap");
+
+ memset(map, 0, sizeof(MAGIC));
+
+ switch(rfork(RFFDG|RFPROC|RFMEM)) {
+ case -1:
+ err(1, "fork");
+ case 0:
+ memcpy(map, MAGIC, sizeof(MAGIC));
+ _exit(0);
+ }
+
+ if (wait(&status) < 0)
+ err(1, "wait");
+
+ if (!WIFEXITED(status))
+ err(1, "child error");
+
+ if (memcmp(map, MAGIC, sizeof(MAGIC)) != 0)
+ return 1;
+
+ return WEXITSTATUS(status) != 0;
+} \ No newline at end of file