summaryrefslogtreecommitdiff
path: root/regress/sys/kern
diff options
context:
space:
mode:
authorJoshua Elsasser <joshe@cvs.openbsd.org>2011-11-22 23:06:50 +0000
committerJoshua Elsasser <joshe@cvs.openbsd.org>2011-11-22 23:06:50 +0000
commit6919b95f5992c9aefd39fddbacb3761523f50098 (patch)
tree54ab31df777ee9990f57db3fe8703207273e7084 /regress/sys/kern
parente4ec26f0e2b58c6d24ed72b18ed6ad64ad7fbf22 (diff)
Add a test for forked processes inheriting their parent's signal stack.
ok guenther@
Diffstat (limited to 'regress/sys/kern')
-rw-r--r--regress/sys/kern/signal/Makefile4
-rw-r--r--regress/sys/kern/signal/sigaltstack_fork/Makefile6
-rw-r--r--regress/sys/kern/signal/sigaltstack_fork/sigaltstack_fork.c67
3 files changed, 75 insertions, 2 deletions
diff --git a/regress/sys/kern/signal/Makefile b/regress/sys/kern/signal/Makefile
index 65193ab4315..bcfd293e8ed 100644
--- a/regress/sys/kern/signal/Makefile
+++ b/regress/sys/kern/signal/Makefile
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile,v 1.4 2008/06/10 18:04:31 hshoexer Exp $
+# $OpenBSD: Makefile,v 1.5 2011/11/22 23:06:48 joshe Exp $
-SUBDIR+= sigfpe siginfo_addr fpsig earlysig cansig
+SUBDIR+= sigfpe siginfo_addr fpsig earlysig cansig sigaltstack_fork
install:
diff --git a/regress/sys/kern/signal/sigaltstack_fork/Makefile b/regress/sys/kern/signal/sigaltstack_fork/Makefile
new file mode 100644
index 00000000000..f3510145632
--- /dev/null
+++ b/regress/sys/kern/signal/sigaltstack_fork/Makefile
@@ -0,0 +1,6 @@
+
+# $OpenBSD: Makefile,v 1.1 2011/11/22 23:06:49 joshe Exp $
+
+PROG= sigaltstack_fork
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/kern/signal/sigaltstack_fork/sigaltstack_fork.c b/regress/sys/kern/signal/sigaltstack_fork/sigaltstack_fork.c
new file mode 100644
index 00000000000..8b6237bdf9b
--- /dev/null
+++ b/regress/sys/kern/signal/sigaltstack_fork/sigaltstack_fork.c
@@ -0,0 +1,67 @@
+/* $OpenBSD: sigaltstack_fork.c,v 1.1 2011/11/22 23:06:49 joshe Exp $ */
+
+/*
+ * Public domain. 2011, Joshua Elsasser
+ *
+ * Test if child processes inherit an alternate signal stack.
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <err.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+void
+check_stack(void *buf, const char *label)
+{
+ struct sigaltstack ss;
+
+ bzero(&ss, sizeof(ss));
+ if (sigaltstack(NULL, &ss) != 0)
+ err(1, "failed to get sigaltstack in parent");
+ if (ss.ss_sp != buf ||
+ ss.ss_size != SIGSTKSZ ||
+ ss.ss_flags != 0)
+ errx(1, "bad sigaltstack value in %s: "
+ "buf=%p ss_sp=%p ss_size=%zu ss_flags=0x%x",
+ label, buf, ss.ss_sp, ss.ss_size, ss.ss_flags);
+}
+
+int
+main(int argc, char *argv[])
+{
+ struct sigaltstack ss;
+ int status;
+ pid_t kid;
+ void *buf;
+
+ if ((buf = malloc(SIGSTKSZ)) == NULL)
+ err(1, "malloc failed");
+
+ bzero(&ss, sizeof(ss));
+ ss.ss_sp = buf;
+ ss.ss_size = SIGSTKSZ;
+ if (sigaltstack(&ss, NULL) != 0)
+ err(1, "failed to set sigaltstack");
+
+ check_stack(buf, "parent");
+
+ if ((kid = fork()) == -1)
+ err(1, "fork failed");
+
+ if (kid == 0) {
+ check_stack(buf, "child");
+ _exit(0);
+ }
+
+ if (waitpid(kid, &status, 0) != kid)
+ err(1, "waitpid failed");
+ if (!WIFEXITED(status))
+ errx(1, "child did not exit normally");
+
+ return (WEXITSTATUS(status));
+}