summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorFederico G. Schwindt <fgsch@cvs.openbsd.org>2011-09-18 16:36:59 +0000
committerFederico G. Schwindt <fgsch@cvs.openbsd.org>2011-09-18 16:36:59 +0000
commitb77ddf3835932d3da47ab73e8a65a9b0e810a5b0 (patch)
treecb5087018eeadc510e3234485fb7680a4a9e7414 /regress
parent0337c5ac54faf91532e88026ce56435641d4f390 (diff)
test for interrupted connect.
Diffstat (limited to 'regress')
-rw-r--r--regress/lib/libpthread/restart/connect/Makefile6
-rw-r--r--regress/lib/libpthread/restart/connect/connect.c59
2 files changed, 65 insertions, 0 deletions
diff --git a/regress/lib/libpthread/restart/connect/Makefile b/regress/lib/libpthread/restart/connect/Makefile
new file mode 100644
index 00000000000..4ce856466fc
--- /dev/null
+++ b/regress/lib/libpthread/restart/connect/Makefile
@@ -0,0 +1,6 @@
+# $OpenBSD: Makefile,v 1.1 2011/09/18 16:36:58 fgsch Exp $
+
+PROG = connect
+CFLAGS += -I${.CURDIR}/../../include
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libpthread/restart/connect/connect.c b/regress/lib/libpthread/restart/connect/connect.c
new file mode 100644
index 00000000000..dfa62040a47
--- /dev/null
+++ b/regress/lib/libpthread/restart/connect/connect.c
@@ -0,0 +1,59 @@
+/* $OpenBSD: connect.c,v 1.1 2011/09/18 16:36:58 fgsch Exp $ */
+/*
+ * Federico G. Schwindt <fgsch@openbsd.org>, 2011. Public Domain.
+ */
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <pthread.h>
+#include <signal.h>
+#include <unistd.h>
+#include "test.h"
+
+volatile sig_atomic_t hits = 0;
+
+void
+handler(int sig)
+{
+ hits++;
+}
+
+void *
+thr_connect(void *arg)
+{
+ struct sockaddr_in sa;
+ int s;
+
+ CHECKe(s = socket(AF_INET, SOCK_STREAM, 0));
+ bzero(&sa, sizeof(sa));
+ sa.sin_family = AF_INET;
+ sa.sin_port = htons(23);
+ sa.sin_addr.s_addr = htonl(0xc7b98903); /* cvs.openbsd.org */
+ ASSERT(connect(s, (struct sockaddr *)&sa, sizeof(sa)) == -1);
+ return ((caddr_t)NULL + errno);
+}
+
+int
+main(int argc, char **argv)
+{
+ struct sigaction sa;
+ pthread_t tid;
+ void *retval;
+
+ bzero(&sa, sizeof(sa));
+ sa.sa_handler = handler;
+ sa.sa_flags = SA_RESTART;
+ CHECKe(sigaction(SIGUSR1, &sa, NULL));
+
+ CHECKr(pthread_create(&tid, NULL, thr_connect, NULL));
+ sleep(2);
+
+ /* Should interrupt it. */
+ CHECKr(pthread_kill(tid, SIGUSR1));
+ sleep(1);
+
+ CHECKr(pthread_join(tid, &retval));
+ ASSERT(retval == (void *)EINTR);
+ ASSERT(hits == 1);
+ SUCCEED;
+}