summaryrefslogtreecommitdiff
path: root/regress/lib/libc
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2015-10-22 05:30:19 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2015-10-22 05:30:19 +0000
commit59cb98a82ed7c9c81e8223c2f2cef6a3e71aeb0a (patch)
tree07d74f8eecbe67cdeb9feab9a12e14eb047386ef /regress/lib/libc
parent0eb9d4d3603c7569d7b7537c9c8feef639b147a4 (diff)
Add a regress for libc handling of SIGTHR
Diffstat (limited to 'regress/lib/libc')
-rw-r--r--regress/lib/libc/sigthr/Makefile5
-rw-r--r--regress/lib/libc/sigthr/sigthr_test.c66
2 files changed, 71 insertions, 0 deletions
diff --git a/regress/lib/libc/sigthr/Makefile b/regress/lib/libc/sigthr/Makefile
new file mode 100644
index 00000000000..8ae4643e1e7
--- /dev/null
+++ b/regress/lib/libc/sigthr/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2015/10/22 05:30:18 guenther Exp $
+
+PROG=sigthr_test
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libc/sigthr/sigthr_test.c b/regress/lib/libc/sigthr/sigthr_test.c
new file mode 100644
index 00000000000..c2eaa1f7796
--- /dev/null
+++ b/regress/lib/libc/sigthr/sigthr_test.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
+ *
+ * Public domain.
+ *
+ * Verify that SIGTHR can't be blocked or caught by applications.
+ */
+
+#include <err.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+
+void sighandler(int sig) { }
+
+int
+main(void)
+{
+ struct sigaction sa;
+ sigset_t set, oset;
+
+ /*
+ * check sigprocmask
+ */
+ if (sigprocmask(SIG_BLOCK, NULL, &set))
+ err(1, "sigprocmask");
+ if (sigismember(&set, SIGTHR))
+ errx(1, "SIGTHR already blocked");
+ sigaddset(&set, SIGTHR);
+ if (sigprocmask(SIG_BLOCK, &set, NULL))
+ err(1, "sigprocmask");
+ if (sigprocmask(SIG_SETMASK, &set, &oset))
+ err(1, "sigprocmask");
+ if (sigismember(&oset, SIGTHR))
+ errx(1, "SIGTHR blocked with SIG_BLOCK");
+ if (sigprocmask(SIG_BLOCK, NULL, &oset))
+ err(1, "sigprocmask");
+ if (sigismember(&oset, SIGTHR))
+ errx(1, "SIGTHR blocked with SIG_SETMASK");
+
+ /*
+ * check sigaction
+ */
+ if (sigaction(SIGTHR, NULL, &sa) == 0)
+ errx(1, "sigaction(SIGTHR) succeeded");
+ else if (errno != EINVAL)
+ err(1, "sigaction(SIGTHR) didn't fail with EINVAL");
+ memset(&sa, 0, sizeof sa);
+ sa.sa_handler = sighandler;
+ sigfillset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ if (sigaction(SIGTHR, &sa, NULL) == 0)
+ errx(1, "sigaction(SIGTHR) succeeded");
+ else if (errno != EINVAL)
+ err(1, "sigaction(SIGTHR) didn't fail with EINVAL");
+ if (sigaction(SIGUSR1, &sa, NULL))
+ err(1, "sigaction(SIGUSR1)");
+ if (sigaction(SIGUSR1, NULL, &sa))
+ err(1, "sigaction(SIGUSR1)");
+ if (sigismember(&sa.sa_mask, SIGTHR))
+ errx(1, "SIGTHR blocked with sigaction");
+
+ return 0;
+}