Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/regress/lib/libpthread/sigmask2 Add a test for proper signal...



details:   https://anonhg.NetBSD.org/src/rev/3b0525bc2f45
branches:  trunk
changeset: 574323:3b0525bc2f45
user:      nathanw <nathanw%NetBSD.org@localhost>
date:      Sat Feb 26 20:03:25 2005 +0000

description:
Add a test for proper signal mask handling when threads are not yet started.

diffstat:

 regress/lib/libpthread/sigmask2/Makefile   |  14 ++++++
 regress/lib/libpthread/sigmask2/sigmask2.c |  63 ++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+), 0 deletions(-)

diffs (85 lines):

diff -r 3039b2bee488 -r 3b0525bc2f45 regress/lib/libpthread/sigmask2/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libpthread/sigmask2/Makefile  Sat Feb 26 20:03:25 2005 +0000
@@ -0,0 +1,14 @@
+#      $NetBSD: Makefile,v 1.1 2005/02/26 20:03:25 nathanw Exp $
+
+WARNS=2
+
+PROG=   sigmask2
+
+LDADD= -lpthread
+
+NOMAN=
+
+regress:
+       ./sigmask2
+
+.include <bsd.prog.mk>
diff -r 3039b2bee488 -r 3b0525bc2f45 regress/lib/libpthread/sigmask2/sigmask2.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libpthread/sigmask2/sigmask2.c        Sat Feb 26 20:03:25 2005 +0000
@@ -0,0 +1,63 @@
+#include <stdio.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+/* Test that signal masks are respected before threads are started */
+volatile sig_atomic_t flag;
+
+void handler1(int sig, siginfo_t *info, void *ctx);
+void handler2(int sig, siginfo_t *info, void *ctx);
+
+void
+handler1(int sig, siginfo_t *info, void *ctx)
+{
+
+       kill(getpid(), SIGUSR2);
+       /*
+        * If the mask is properly set, SIGUSR2 will not be handled
+        * until this handler returns.
+        */
+       flag = 1;
+}
+
+void
+handler2(int sig, siginfo_t *info, void *ctx)
+{
+       if (flag == 1)
+               flag = 2;
+}
+
+int
+main(void)
+{
+       struct sigaction act;
+       int ret;
+
+       act.sa_sigaction = handler1;
+       sigemptyset(&act.sa_mask);
+       sigaddset(&act.sa_mask, SIGUSR2);
+       act.sa_flags = SA_SIGINFO;
+
+       ret = sigaction(SIGUSR1, &act, NULL);
+       if (ret) {
+               printf("sigaction: %d\n", ret);
+               exit(1);
+       }
+
+       act.sa_sigaction = handler2;
+       sigemptyset(&act.sa_mask);
+       act.sa_flags = SA_SIGINFO;
+       ret = sigaction(SIGUSR2, &act, NULL);
+
+       kill(getpid(), SIGUSR1);
+
+       if (flag == 2)
+               printf("Success: Both handlers ran in order\n");
+       else {
+               printf("Failure: flag was %d\n", flag);
+               exit(1);
+       }
+
+       return 0;
+}



Home | Main Index | Thread Index | Old Index