diff options
Diffstat (limited to 'regress/sys')
-rw-r--r-- | regress/sys/kern/kqueue/Makefile | 14 | ||||
-rw-r--r-- | regress/sys/kern/kqueue/kqueue-fork.c | 46 | ||||
-rw-r--r-- | regress/sys/kern/kqueue/kqueue-pipe.c | 18 | ||||
-rw-r--r-- | regress/sys/kern/kqueue/main.c | 34 |
4 files changed, 101 insertions, 11 deletions
diff --git a/regress/sys/kern/kqueue/Makefile b/regress/sys/kern/kqueue/Makefile index 89252403a07..4755bc391ca 100644 --- a/regress/sys/kern/kqueue/Makefile +++ b/regress/sys/kern/kqueue/Makefile @@ -1,4 +1,14 @@ -# $OpenBSD: Makefile,v 1.1 2002/01/07 00:01:00 provos Exp $ +# $OpenBSD: Makefile,v 1.2 2002/02/27 17:11:51 art Exp $ + +PROG= kqueue-test +SRCS= kqueue-pipe.c kqueue-fork.c main.c + +kq-pipe: ${PROG} + ./${PROG} -p +kq-fork: ${PROG} + ./${PROG} -f + +REGRESSTARGETS=kq-pipe kq-fork +.PHONY: ${REGRESSTARGETS} -PROG= kqueue-pipe .include <bsd.regress.mk> diff --git a/regress/sys/kern/kqueue/kqueue-fork.c b/regress/sys/kern/kqueue/kqueue-fork.c new file mode 100644 index 00000000000..497ffbd90a5 --- /dev/null +++ b/regress/sys/kern/kqueue/kqueue-fork.c @@ -0,0 +1,46 @@ +/* $OpenBSD: kqueue-fork.c,v 1.1 2002/02/27 17:11:51 art Exp $ */ +/* + * Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain + */ + +#include <stdlib.h> +#include <stdio.h> +#include <err.h> +#include <unistd.h> + +#include <sys/types.h> +#include <sys/event.h> +#include <sys/wait.h> + +int +check_inheritance(void) +{ + int kq, status; + + if ((kq = kqueue()) < 0) { + warn("kqueue"); + return (1); + } + + /* + * Check if the kqueue is properly closed on fork(). + */ + + switch (fork()) { + case -1: + err(1, "fork"); + case 0: + if (close(kq) < 0) + _exit(0); + warnx("fork didn't close kqueue"); + _exit(1); + } + if (wait(&status) < 0) + err(1, "wait"); + + if (!WIFEXITED(status)) + errx(1, "child didn't exit?"); + + close(kq); + return (WEXITSTATUS(status) != 0); +} diff --git a/regress/sys/kern/kqueue/kqueue-pipe.c b/regress/sys/kern/kqueue/kqueue-pipe.c index c81ce296275..8995904be7c 100644 --- a/regress/sys/kern/kqueue/kqueue-pipe.c +++ b/regress/sys/kern/kqueue/kqueue-pipe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kqueue-pipe.c,v 1.2 2002/01/07 00:11:07 provos Exp $ */ +/* $OpenBSD: kqueue-pipe.c,v 1.3 2002/02/27 17:11:51 art Exp $ */ /* * Copyright 2001 Niels Provos <provos@citi.umich.edu> * All rights reserved. @@ -36,7 +36,7 @@ #include <fcntl.h> int -main(int argc, char **argv) +do_pipe(void) { int kq; int n; @@ -46,19 +46,19 @@ main(int argc, char **argv) char buf[8000]; if (pipe(fd) == -1) - exit(1); + return (1); if (fcntl(fd[1], F_SETFL, O_NONBLOCK) == -1) - exit(1); + return (1); if ((kq = kqueue()) == -1) - exit(1); + return (1); ev.ident = fd[1]; ev.filter = EVFILT_WRITE; ev.flags = EV_ADD | EV_ENABLE; n = kevent(kq, &ev, 1, NULL, 0, NULL); if (n == -1) - exit(1); + return (1); while ((n = write(fd[1], buf, sizeof(buf))) == sizeof(buf)) ; @@ -67,7 +67,7 @@ main(int argc, char **argv) ts.tv_nsec = 0; n = kevent(kq, NULL, 0, &ev, 1, &ts); if (n != 0) - exit(1); + return (1); read(fd[0], buf, sizeof(buf)); @@ -75,7 +75,7 @@ main(int argc, char **argv) ts.tv_nsec = 0; n = kevent(kq, NULL, 0, &ev, 1, &ts); if (n == -1 || n == 0) - exit(1); + return (1); - exit(0); + return (0); } diff --git a/regress/sys/kern/kqueue/main.c b/regress/sys/kern/kqueue/main.c new file mode 100644 index 00000000000..e6155bf4875 --- /dev/null +++ b/regress/sys/kern/kqueue/main.c @@ -0,0 +1,34 @@ +/* $OpenBSD: main.c,v 1.1 2002/02/27 17:11:51 art Exp $ */ +/* + * Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain + */ + +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> + +extern int do_pipe(void); +extern int check_inheritance(void); + +int +main(int argc, char **argv) +{ + int ret, c; + + ret = 0; + while ((c = getopt(argc, argv, "pf")) != -1) { + switch (c) { + case 'p': + ret |= do_pipe(); + break; + case 'f': + ret |= check_inheritance(); + break; + default: + fprintf(stderr, "Usage: kqtest -P|p\n"); + exit(1); + } + } + + return (ret); +} |