1 /* Test of sigaction() function.
2 Copyright (C) 2008, 2009 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Eric Blake <ebb9@byu.net>, 2008. */
23 #include "signature.h"
24 SIGNATURE_CHECK (sigaction, int, (int, struct sigaction const *,
32 # define SA_NOCLDSTOP 0
41 # define SA_NOCLDWAIT 0
44 /* Define a mask of flags required by POSIX. Some implementations
45 provide other flags as extensions, such as SA_RESTORER, that we
46 must ignore in this test. */
47 #define MASK_SA_FLAGS (SA_NOCLDSTOP | SA_ONSTACK | SA_RESETHAND | SA_RESTART \
48 | SA_SIGINFO | SA_NOCLDWAIT | SA_NODEFER)
50 /* This test is unsafe in the presence of an asynchronous SIGABRT,
51 because we install a signal-handler that is intentionally not
52 async-safe. Hopefully, this does not lead to too many reports of
53 false failures, since people don't generally use 'kill -s SIGABRT'
54 to end a runaway program. */
59 static int entry_count;
61 ASSERT (sig == SIGABRT);
62 ASSERT (sigaction (SIGABRT, NULL, &sa) == 0);
63 ASSERT ((sa.sa_flags & SA_SIGINFO) == 0);
64 switch (entry_count++)
67 ASSERT ((sa.sa_flags & SA_RESETHAND) == 0);
68 ASSERT (sa.sa_handler == handler);
71 /* This assertion fails on glibc-2.3.6 systems with LinuxThreads,
72 when this program is linked with -lpthread, due to the sigaction()
73 override in libpthread.so. */
74 #if !defined __GLIBC__
75 ASSERT (sa.sa_handler == SIG_DFL);
87 struct sigaction old_sa;
88 sa.sa_handler = handler;
91 ASSERT (sigemptyset (&sa.sa_mask) == 0);
92 ASSERT (sigaction (SIGABRT, &sa, NULL) == 0);
93 ASSERT (raise (SIGABRT) == 0);
95 sa.sa_flags = SA_RESETHAND | SA_NODEFER;
96 ASSERT (sigaction (SIGABRT, &sa, &old_sa) == 0);
97 ASSERT ((old_sa.sa_flags & MASK_SA_FLAGS) == 0);
98 ASSERT (old_sa.sa_handler == handler);
99 ASSERT (raise (SIGABRT) == 0);
101 sa.sa_handler = SIG_DFL;
102 ASSERT (sigaction (SIGABRT, &sa, &old_sa) == 0);
103 ASSERT ((old_sa.sa_flags & SA_SIGINFO) == 0);
104 #if !defined __GLIBC__ /* see above */
105 ASSERT (old_sa.sa_handler == SIG_DFL);
108 sa.sa_handler = SIG_IGN;
109 ASSERT (sigaction (SIGABRT, &sa, NULL) == 0);
110 ASSERT (raise (SIGABRT) == 0);
111 ASSERT (sigaction (SIGABRT, NULL, &old_sa) == 0);
112 ASSERT (old_sa.sa_handler == SIG_IGN);
113 ASSERT (raise (SIGABRT) == 0);