diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2002-02-17 05:44:08 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2002-02-17 05:44:08 +0000 |
commit | 6e7c01afd33f3207ec5849170599032a7c97b339 (patch) | |
tree | a8d0751ee2da6372ff23ad603974b9de81772932 /regress/sys/kern/rfork | |
parent | 669d2fad1a0efa0f35d046395351d3e1dcb73ffe (diff) |
test rfork with shared fds
Diffstat (limited to 'regress/sys/kern/rfork')
-rw-r--r-- | regress/sys/kern/rfork/rfsharefd/Makefile | 5 | ||||
-rw-r--r-- | regress/sys/kern/rfork/rfsharefd/rfsharefd.c | 41 |
2 files changed, 46 insertions, 0 deletions
diff --git a/regress/sys/kern/rfork/rfsharefd/Makefile b/regress/sys/kern/rfork/rfsharefd/Makefile new file mode 100644 index 00000000000..a6246575273 --- /dev/null +++ b/regress/sys/kern/rfork/rfsharefd/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2002/02/17 05:44:07 art Exp $ + +PROG=rfsharefd + +.include <bsd.regress.mk> diff --git a/regress/sys/kern/rfork/rfsharefd/rfsharefd.c b/regress/sys/kern/rfork/rfsharefd/rfsharefd.c new file mode 100644 index 00000000000..fdd6655ee7d --- /dev/null +++ b/regress/sys/kern/rfork/rfsharefd/rfsharefd.c @@ -0,0 +1,41 @@ +/* $OpenBSD: rfsharefd.c,v 1.1 2002/02/17 05:44:07 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(RFPROC)) { + case -1: + err(1, "fork"); + case 0: + if (close(0) < 0) + _exit(1); + _exit(0); + } + + if (wait(&status) < 0) + err(1, "wait"); + + if (!WIFEXITED(status)) + err(1, "child error"); + + if (close(0) == 0) + errx(1, "fd 0 not closed"); + + return WEXITSTATUS(status) != 0; +}
\ No newline at end of file |