From 770c6cd40718fc4d63d12dce4e750030d8d70057 Mon Sep 17 00:00:00 2001 From: Artur Grabowski Date: Sun, 17 Feb 2002 05:10:41 +0000 Subject: Test rfork(RFMEM) --- regress/sys/kern/rfork/rfmem/Makefile | 5 ++++ regress/sys/kern/rfork/rfmem/rfmem.c | 49 +++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 regress/sys/kern/rfork/rfmem/Makefile create mode 100644 regress/sys/kern/rfork/rfmem/rfmem.c (limited to 'regress/sys/kern/rfork') 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 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 , 2002 Public Domain. + */ +#include +#include +#include + +#include +#include +#include +#include + +#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 -- cgit v1.2.3