summaryrefslogtreecommitdiffstats
path: root/regress/lib/libpthread/siginterrupt
diff options
context:
space:
mode:
Diffstat (limited to 'regress/lib/libpthread/siginterrupt')
-rw-r--r--regress/lib/libpthread/siginterrupt/Makefile5
-rw-r--r--regress/lib/libpthread/siginterrupt/siginterrupt.c58
2 files changed, 63 insertions, 0 deletions
diff --git a/regress/lib/libpthread/siginterrupt/Makefile b/regress/lib/libpthread/siginterrupt/Makefile
new file mode 100644
index 00000000000..e8f4f5422ec
--- /dev/null
+++ b/regress/lib/libpthread/siginterrupt/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2011/09/13 23:50:17 fgsch Exp $
+
+PROG = siginterrupt
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libpthread/siginterrupt/siginterrupt.c b/regress/lib/libpthread/siginterrupt/siginterrupt.c
new file mode 100644
index 00000000000..82aae9f45d4
--- /dev/null
+++ b/regress/lib/libpthread/siginterrupt/siginterrupt.c
@@ -0,0 +1,58 @@
+/* $OpenBSD: siginterrupt.c,v 1.1 2011/09/13 23:50:17 fgsch Exp $ */
+/*
+ * Federico G. Schwindt <fgsch@openbsd.org>, 2011. Public Domain.
+ */
+#include <pthread.h>
+#include <signal.h>
+#include <unistd.h>
+#include "test.h"
+
+volatile sig_atomic_t hits = 0;
+
+void
+handler(int sig)
+{
+ hits++;
+}
+
+void *
+blocker(void *arg)
+{
+ int fds[2];
+ char buf;
+
+ CHECKe(pipe(fds));
+ ASSERT(read(fds[0], &buf, 1) == -1);
+ return ((caddr_t)NULL + errno);
+}
+
+int
+main(int argc, char **argv)
+{
+ pthread_t tid;
+ void *retval;
+
+ ASSERT(signal(SIGUSR1, handler) != SIG_ERR);
+
+ CHECKr(pthread_create(&tid, NULL, blocker, NULL));
+ sleep(1);
+
+ /* With signal(3) system calls will be restarted. */
+ CHECKr(pthread_kill(tid, SIGUSR1));
+ sleep(1);
+
+ /* Same as default with signal(3). */
+ CHECKe(siginterrupt(SIGUSR1, 0));
+ CHECKr(pthread_kill(tid, SIGUSR1));
+ sleep(1);
+
+ /* Should interrupt the call now. */
+ CHECKe(siginterrupt(SIGUSR1, 1));
+ CHECKr(pthread_kill(tid, SIGUSR1));
+ sleep(1);
+
+ CHECKr(pthread_join(tid, &retval));
+ ASSERT(retval == (void *)EINTR);
+ ASSERT(hits == 3);
+ SUCCEED;
+}