From 876f8ff88fad4264d956d6a129d8eee8015ce5c0 Mon Sep 17 00:00:00 2001 From: Marco S Hyman Date: Thu, 15 Jan 2004 22:22:53 +0000 Subject: regression for pthread version of closefrom --- regress/lib/libpthread/Makefile | 5 +-- regress/lib/libpthread/closefrom/Makefile | 5 +++ regress/lib/libpthread/closefrom/closefrom.c | 47 ++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 regress/lib/libpthread/closefrom/Makefile create mode 100644 regress/lib/libpthread/closefrom/closefrom.c (limited to 'regress') diff --git a/regress/lib/libpthread/Makefile b/regress/lib/libpthread/Makefile index 45994392266..db3708ab336 100644 --- a/regress/lib/libpthread/Makefile +++ b/regress/lib/libpthread/Makefile @@ -1,6 +1,7 @@ -# $OpenBSD: Makefile,v 1.19 2003/07/10 21:02:44 marc Exp $ +# $OpenBSD: Makefile,v 1.20 2004/01/15 22:22:52 marc Exp $ -SUBDIR= cancel cancel2 close cwd execve fork group malloc_duel netdb pcap poll \ +SUBDIR= cancel cancel2 close closefrom cwd execve fork group \ + malloc_duel netdb pcap poll \ preemption preemption_float pthread_cond_timedwait pthread_create \ pthread_join pthread_kill pthread_mutex pthread_specific readdir \ select setjmp signal sigdeliver siginfo sigmask signodefer sigsuspend \ diff --git a/regress/lib/libpthread/closefrom/Makefile b/regress/lib/libpthread/closefrom/Makefile new file mode 100644 index 00000000000..8bc42fd76c9 --- /dev/null +++ b/regress/lib/libpthread/closefrom/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2004/01/15 22:22:52 marc Exp $ + +PROG= closefrom + +.include diff --git a/regress/lib/libpthread/closefrom/closefrom.c b/regress/lib/libpthread/closefrom/closefrom.c new file mode 100644 index 00000000000..3568e41a8a7 --- /dev/null +++ b/regress/lib/libpthread/closefrom/closefrom.c @@ -0,0 +1,47 @@ +/* $OpenBSD: closefrom.c,v 1.1 2004/01/15 22:22:52 marc Exp $ */ + +/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman */ + +#include +#include +#include + +#include "test.h" + +static void * +dummy_thread(void* arg) +{ + /* just exit */ + return NULL; +} + +/* + * Test that closefrom does the right thing in a threaded programs, + * specifically that it doesn't kill the thread kernel signal pipe. + */ +int +main(int argc, char *argv[]) +{ + pthread_t thread; + void *status; + int fd; + int result; + + /* close files above stderr. The kernel pipes shouldn't be touched */ + fd = STDERR_FILENO + 1; + result = closefrom(fd); + printf("closefrom(%d) == %d/%d\n", fd, result, errno); + + /* do it again: make sure that the result is -1/EBADF */ + result = closefrom(fd); + printf("closefrom(%d) == %d/%d\n", fd, result, errno); + ASSERT(result == -1 && errno == EBADF); + + /* start a thread to verify the thread kernel is working */ + CHECKr(pthread_create(&thread, NULL, dummy_thread, NULL)); + CHECKr(pthread_join(thread, &status)); + printf("dummy thread exited with status %p\n", status); + + SUCCEED; + return 0; +} -- cgit v1.2.3