summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--regress/lib/libpthread/Makefile5
-rw-r--r--regress/lib/libpthread/closefrom/Makefile5
-rw-r--r--regress/lib/libpthread/closefrom/closefrom.c47
3 files changed, 55 insertions, 2 deletions
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 <bsd.regress.mk>
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 <marc@snafu.org> */
+
+#include <errno.h>
+#include <pthread.h>
+#include <unistd.h>
+
+#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;
+}