summaryrefslogtreecommitdiff
path: root/signal
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-04-23 19:05:33 +0000
committerUlrich Drepper <drepper@redhat.com>2006-04-23 19:05:33 +0000
commit727a6832f033c711fe75c5f742b07087ef5b5133 (patch)
tree9662b191a016789a94526defe03297d48686e19f /signal
parent9055724a92433ffa4c36f93d918ee1b3dfa1d6f7 (diff)
[BZ #1951]
2006-04-23 Ulrich Drepper <drepper@redhat.com> [BZ #1951] * sysdeps/posix/sigset.c (sigset): Return correct value reflecting previous signal state. * signal/Makefile (tests): Add tst-sigset2. * signal/tst-sigset2.c: New file.
Diffstat (limited to 'signal')
-rw-r--r--signal/Makefile5
-rw-r--r--signal/tst-sigset2.c184
2 files changed, 186 insertions, 3 deletions
diff --git a/signal/Makefile b/signal/Makefile
index b5c18fef04..fa8d098da0 100644
--- a/signal/Makefile
+++ b/signal/Makefile
@@ -1,5 +1,4 @@
-# Copyright (C) 1991,1992,1993,1994,1995,1996,1997,1998,2003
-# Free Software Foundation, Inc.
+# Copyright (C) 1991-1998,2003,2006 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
@@ -38,7 +37,7 @@ routines := signal raise killpg \
allocrtsig sigtimedwait sigwaitinfo sigqueue \
sighold sigrelse sigignore sigset
-tests := tst-signal tst-sigset tst-sigsimple tst-raise
+tests := tst-signal tst-sigset tst-sigsimple tst-raise tst-sigset2
distribute := sigsetops.h testrtsig.h sigset-cvt-mask.h
diff --git a/signal/tst-sigset2.c b/signal/tst-sigset2.c
new file mode 100644
index 0000000000..f653323321
--- /dev/null
+++ b/signal/tst-sigset2.c
@@ -0,0 +1,184 @@
+/* sigset_SIG_HOLD_bug.c [BZ #1951] */
+#include <errno.h>
+#include <error.h>
+#include <inttypes.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#define TEST_SIG SIGINT
+
+
+/* Print mask of blocked signals for this process */
+static void
+printSigMask (const char *msg)
+{
+ sigset_t currMask;
+ int sig;
+ int cnt;
+
+ if (msg != NULL)
+ printf ("%s", msg);
+
+ if (sigprocmask (SIG_BLOCK, NULL, &currMask) == -1)
+ error (1, errno, "sigaction");
+
+ cnt = 0;
+ for (sig = 1; sig < NSIG; sig++)
+ {
+ if (sigismember (&currMask, sig))
+ {
+ cnt++;
+ printf ("\t\t%d (%s)\n", sig, strsignal (sig));
+ }
+ }
+
+ if (cnt == 0)
+ printf ("\t\t<empty signal set>\n");
+} /* printSigMask */
+
+static void
+handler (int sig)
+{
+ printf ("Caught signal %d\n", sig);
+ printSigMask ("Signal mask in handler\n");
+ printf ("Handler returning\n");
+ _exit (1);
+} /* handler */
+
+static void
+printDisposition (sighandler_t disp)
+{
+ if (disp == SIG_HOLD)
+ printf ("SIG_HOLD");
+ else if (disp == SIG_DFL)
+ printf ("SIG_DFL");
+ else if (disp == SIG_IGN)
+ printf ("SIG_IGN");
+ else
+ printf ("handled at %" PRIxPTR, (uintptr_t) disp);
+} /* printDisposition */
+
+static int
+returnTest1 (void)
+{
+ sighandler_t prev;
+
+ printf ("===== TEST 1 =====\n");
+ printf ("Blocking signal with sighold()\n");
+ if (sighold (TEST_SIG) == -1)
+ error (1, errno, "sighold");
+ printSigMask ("Signal mask after sighold()\n");
+
+ printf ("About to use sigset() to establish handler\n");
+ prev = sigset (TEST_SIG, handler);
+ if (prev == SIG_ERR)
+ error(1, errno, "sigset");
+
+ printf ("Previous disposition: ");
+ printDisposition (prev);
+ printf (" (should be SIG_HOLD)\n");
+ if (prev != SIG_HOLD)
+ {
+ printf("TEST FAILED!!!\n");
+ return 1;
+ }
+ return 0;
+} /* returnTest1 */
+
+static int
+returnTest2 (void)
+{
+ sighandler_t prev;
+
+ printf ("\n===== TEST 2 =====\n");
+
+ printf ("About to use sigset() to set SIG_HOLD\n");
+ prev = sigset (TEST_SIG, SIG_HOLD);
+ if (prev == SIG_ERR)
+ error (1, errno, "sigset");
+
+ printf ("Previous disposition: ");
+ printDisposition (prev);
+ printf (" (should be SIG_DFL)\n");
+ if (prev != SIG_DFL)
+ {
+ printf("TEST FAILED!!!\n");
+ return 1;
+ }
+ return 0;
+} /* returnTest2 */
+
+static int
+returnTest3 (void)
+{
+ sighandler_t prev;
+
+ printf ("\n===== TEST 3 =====\n");
+
+ printf ("About to use sigset() to set SIG_HOLD\n");
+ prev = sigset (TEST_SIG, SIG_HOLD);
+ if (prev == SIG_ERR)
+ error (1, errno, "sigset");
+
+ printf ("About to use sigset() to set SIG_HOLD (again)\n");
+ prev = sigset (TEST_SIG, SIG_HOLD);
+ if (prev == SIG_ERR)
+ error (1, errno, "sigset");
+
+ printf ("Previous disposition: ");
+ printDisposition (prev);
+ printf (" (should be SIG_HOLD)\n");
+ if (prev != SIG_HOLD)
+ {
+ printf("TEST FAILED!!!\n");
+ return 1;
+ }
+ return 0;
+} /* returnTest3 */
+
+int
+main (int argc, char *argv[])
+{
+ pid_t childPid;
+
+ childPid = fork();
+ if (childPid == -1)
+ error (1, errno, "fork");
+
+ if (childPid == 0)
+ exit (returnTest1 ());
+
+ int status;
+ if (TEMP_FAILURE_RETRY (waitpid (childPid, &status, 0)) != childPid)
+ error (1, errno, "waitpid");
+ int result = !WIFEXITED (status) || WEXITSTATUS (status) != 0;
+
+ childPid = fork();
+ if (childPid == -1)
+ error (1, errno, "fork");
+
+ if (childPid == 0)
+ exit (returnTest2 ());
+
+ if (TEMP_FAILURE_RETRY (waitpid (childPid, &status, 0)) != childPid)
+ error (1, errno, "waitpid");
+ result |= !WIFEXITED (status) || WEXITSTATUS (status) != 0;
+
+ childPid = fork();
+ if (childPid == -1)
+ error (1, errno, "fork");
+
+ if (childPid == 0)
+ exit (returnTest3 ());
+
+ if (TEMP_FAILURE_RETRY (waitpid (childPid, &status, 0)) != childPid)
+ error (1, errno, "waitpid");
+ result |= !WIFEXITED (status) || WEXITSTATUS (status) != 0;
+
+ return result;
+} /* main */