summaryrefslogtreecommitdiffstats
path: root/regress/lib/libpthread/restart/recvmsg
diff options
context:
space:
mode:
authorfgsch <fgsch@openbsd.org>2011-09-13 23:50:17 +0000
committerfgsch <fgsch@openbsd.org>2011-09-13 23:50:17 +0000
commitd13be5d47e4149db2549a9828e244d59dbc43f15 (patch)
tree24654cab1dc6977bb362e8b14917c0d71534ad8b /regress/lib/libpthread/restart/recvmsg
parentOn KA43: (diff)
downloadwireguard-openbsd-d13be5d47e4149db2549a9828e244d59dbc43f15.tar.xz
wireguard-openbsd-d13be5d47e4149db2549a9828e244d59dbc43f15.zip
first round of tests to check system calls restarting with pthreads.
guenther@ ok
Diffstat (limited to 'regress/lib/libpthread/restart/recvmsg')
-rw-r--r--regress/lib/libpthread/restart/recvmsg/Makefile6
-rw-r--r--regress/lib/libpthread/restart/recvmsg/recvmsg.c73
2 files changed, 79 insertions, 0 deletions
diff --git a/regress/lib/libpthread/restart/recvmsg/Makefile b/regress/lib/libpthread/restart/recvmsg/Makefile
new file mode 100644
index 00000000000..c8f8335b8bb
--- /dev/null
+++ b/regress/lib/libpthread/restart/recvmsg/Makefile
@@ -0,0 +1,6 @@
+# $OpenBSD: Makefile,v 1.1 2011/09/13 23:50:17 fgsch Exp $
+
+PROG = recvmsg
+CFLAGS += -I${.CURDIR}/../../include
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libpthread/restart/recvmsg/recvmsg.c b/regress/lib/libpthread/restart/recvmsg/recvmsg.c
new file mode 100644
index 00000000000..e1fd7b64d65
--- /dev/null
+++ b/regress/lib/libpthread/restart/recvmsg/recvmsg.c
@@ -0,0 +1,73 @@
+/* $OpenBSD: recvmsg.c,v 1.1 2011/09/13 23:50:17 fgsch Exp $ */
+/*
+ * Federico G. Schwindt <fgsch@openbsd.org>, 2011. Public Domain.
+ */
+#include <sys/types.h>
+#include <sys/uio.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_recvmsg(void *arg)
+{
+ struct sockaddr_in sa;
+ struct msghdr msg;
+ struct iovec iov;
+ char buf;
+ int s;
+
+ CHECKe(s = socket(AF_INET, SOCK_DGRAM, 0));
+ bzero(&sa, sizeof(sa));
+ sa.sin_port = htons(6543);
+ CHECKe(bind(s, (const void*)&sa, sizeof(sa)));
+ bzero(&msg, sizeof(msg));
+ iov.iov_base = &buf;
+ iov.iov_len = 1;
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ ASSERT(recvmsg(s, &msg, 0) == -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));
+ sa.sa_flags = 0;
+ CHECKe(sigaction(SIGUSR2, &sa, NULL));
+
+ CHECKr(pthread_create(&tid, NULL, thr_recvmsg, NULL));
+ sleep(2);
+
+ /* Should restart it. */
+ CHECKr(pthread_kill(tid, SIGUSR1));
+ sleep(1);
+
+ /* Should interrupt it. */
+ CHECKr(pthread_kill(tid, SIGUSR2));
+ sleep(1);
+
+ CHECKr(pthread_join(tid, &retval));
+ ASSERT(retval == (void *)EINTR);
+ ASSERT(hits == 2);
+ SUCCEED;
+}