diff options
-rw-r--r-- | regress/sys/kern/rfork/rfcfdg/Makefile | 5 | ||||
-rw-r--r-- | regress/sys/kern/rfork/rfcfdg/rfcfdg.c | 38 |
2 files changed, 43 insertions, 0 deletions
diff --git a/regress/sys/kern/rfork/rfcfdg/Makefile b/regress/sys/kern/rfork/rfcfdg/Makefile new file mode 100644 index 00000000000..d0fd9ab703b --- /dev/null +++ b/regress/sys/kern/rfork/rfcfdg/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2002/02/17 05:16:41 art Exp $ + +PROG=rfcfdg + +.include <bsd.regress.mk> diff --git a/regress/sys/kern/rfork/rfcfdg/rfcfdg.c b/regress/sys/kern/rfork/rfcfdg/rfcfdg.c new file mode 100644 index 00000000000..922f48f0050 --- /dev/null +++ b/regress/sys/kern/rfork/rfcfdg/rfcfdg.c @@ -0,0 +1,38 @@ +/* $OpenBSD: rfcfdg.c,v 1.1 2002/02/17 05:16:41 art Exp $ */ +/* + * Written by Artur Grabowski <art@openbsd.org>, 2002 Public Domain. + */ +#include <sys/param.h> +#include <sys/wait.h> +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <err.h> +#include <fcntl.h> + +int +main() +{ + int status; + + /* Make sure that at least fd 0 is allocated. */ + if (open("/dev/null", O_RDONLY) < 0) + err(1, "open(/dev/null)"); + + switch(rfork(RFCFDG|RFPROC)) { + case -1: + err(1, "fork"); + case 0: + if (open("/dev/null", O_RDONLY) != 0) + _exit(1); /* pretty hard to print to stderr */ + _exit(0); + } + + if (wait(&status) < 0) + err(1, "wait"); + + if (!WIFEXITED(status)) + err(1, "child error"); + + return WEXITSTATUS(status) != 0; +}
\ No newline at end of file |