Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/fatal-signal.c @ 12518:b5e42ef33b49
update nearly all FSF copyright year lists to include 2009
The files named by the following are exempted:
grep -v '^#' config/srclist.txt|grep -v '^$' \
| while read src dst; do
test -f "$dst" && { echo "$dst"; continue; }
test -d "$dst" || continue
echo "$dst"/$(basename "$src")
done > exempt
git ls-files tests/unictype >> exempt
In the remaining files, convert to all-interval notation if
- there is already at least one year interval like 2000-2003
- the file is maintained by me
- the file is in lib/uni*/, where that style already prevails
Otherwise, use update-copyright's default.
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Mon, 28 Dec 2009 10:50:36 +0100 |
parents | e8d2c6fc33ad |
children | c2cbabec01dd |
rev | line source |
---|---|
4770 | 1 /* Emergency actions in case of a fatal signal. |
12518
b5e42ef33b49
update nearly all FSF copyright year lists to include 2009
Jim Meyering <meyering@redhat.com>
parents:
12421
diff
changeset
|
2 Copyright (C) 2003-2004, 2006-2009 Free Software Foundation, Inc. |
4770 | 3 Written by Bruno Haible <bruno@clisp.org>, 2003. |
4 | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8783
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
4770 | 6 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8783
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8783
diff
changeset
|
8 (at your option) any later version. |
4770 | 9 |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8783
diff
changeset
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
4770 | 17 |
18 | |
7304
1c4ed7637c24
Include <config.h> unconditionally.
Bruno Haible <bruno@clisp.org>
parents:
7014
diff
changeset
|
19 #include <config.h> |
4770 | 20 |
21 /* Specification. */ | |
22 #include "fatal-signal.h" | |
23 | |
24 #include <stdbool.h> | |
25 #include <stdlib.h> | |
26 #include <signal.h> | |
6751
1b0092424a44
Include <unistd.h> unconditionally.
Bruno Haible <bruno@clisp.org>
parents:
6259
diff
changeset
|
27 #include <unistd.h> |
4770 | 28 |
10230
54813304edd2
Use sigaction module rather than signal().
Eric Blake <ebb9@byu.net>
parents:
10221
diff
changeset
|
29 #include "sig-handler.h" |
4770 | 30 #include "xalloc.h" |
31 | |
32 #define SIZEOF(a) (sizeof(a) / sizeof(a[0])) | |
33 | |
34 /* ========================================================================= */ | |
35 | |
36 | |
37 /* The list of fatal signals. | |
38 These are those signals whose default action is to terminate the process | |
39 without a core dump, except | |
40 SIGKILL - because it cannot be caught, | |
41 SIGALRM SIGUSR1 SIGUSR2 SIGPOLL SIGIO SIGLOST - because applications | |
42 often use them for their own purpose, | |
43 SIGPROF SIGVTALRM - because they are used for profiling, | |
44 SIGSTKFLT - because it is more similar to SIGFPE, SIGSEGV, SIGBUS, | |
45 SIGSYS - because it is more similar to SIGABRT, SIGSEGV, | |
46 SIGPWR - because it of too special use, | |
4786
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
47 SIGRTMIN...SIGRTMAX - because they are reserved for application use. |
4770 | 48 plus |
49 SIGXCPU, SIGXFSZ - because they are quite similar to SIGTERM. */ | |
50 | |
5536
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
51 static int fatal_signals[] = |
4770 | 52 { |
53 /* ISO C 99 signals. */ | |
54 #ifdef SIGINT | |
55 SIGINT, | |
56 #endif | |
57 #ifdef SIGTERM | |
58 SIGTERM, | |
59 #endif | |
60 /* POSIX:2001 signals. */ | |
61 #ifdef SIGHUP | |
62 SIGHUP, | |
63 #endif | |
64 #ifdef SIGPIPE | |
65 SIGPIPE, | |
66 #endif | |
67 /* BSD signals. */ | |
68 #ifdef SIGXCPU | |
69 SIGXCPU, | |
70 #endif | |
71 #ifdef SIGXFSZ | |
72 SIGXFSZ, | |
73 #endif | |
7404
71b958155bb9
Handle the Woe32 SIGBREAK too.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
74 /* Woe32 signals. */ |
71b958155bb9
Handle the Woe32 SIGBREAK too.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
75 #ifdef SIGBREAK |
71b958155bb9
Handle the Woe32 SIGBREAK too.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
76 SIGBREAK, |
71b958155bb9
Handle the Woe32 SIGBREAK too.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
77 #endif |
4770 | 78 0 |
79 }; | |
80 | |
81 #define num_fatal_signals (SIZEOF (fatal_signals) - 1) | |
82 | |
5536
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
83 /* Eliminate signals whose signal handler is SIG_IGN. */ |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
84 |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
85 static void |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
86 init_fatal_signals (void) |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
87 { |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
88 static bool fatal_signals_initialized = false; |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
89 if (!fatal_signals_initialized) |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
90 { |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
91 size_t i; |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
92 |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
93 for (i = 0; i < num_fatal_signals; i++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
94 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
95 struct sigaction action; |
5536
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
96 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
97 if (sigaction (fatal_signals[i], NULL, &action) >= 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
98 && get_handler (&action) == SIG_IGN) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
99 fatal_signals[i] = -1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
100 } |
5536
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
101 |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
102 fatal_signals_initialized = true; |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
103 } |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
104 } |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
105 |
4770 | 106 |
107 /* ========================================================================= */ | |
108 | |
109 | |
4786
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
110 typedef void (*action_t) (void); |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
111 |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
112 /* Type of an entry in the actions array. |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
113 The 'action' field is accessed from within the fatal_signal_handler(), |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
114 therefore we mark it as 'volatile'. */ |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
115 typedef struct |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
116 { |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
117 volatile action_t action; |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
118 } |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
119 actions_entry_t; |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
120 |
4770 | 121 /* The registered cleanup actions. */ |
4786
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
122 static actions_entry_t static_actions[32]; |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
123 static actions_entry_t * volatile actions = static_actions; |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
124 static sig_atomic_t volatile actions_count = 0; |
4770 | 125 static size_t actions_allocated = SIZEOF (static_actions); |
126 | |
127 | |
10381
31614a69f913
Don't override previously installed signal handlers.
Bruno Haible <bruno@clisp.org>
parents:
10244
diff
changeset
|
128 /* The saved signal handlers. |
31614a69f913
Don't override previously installed signal handlers.
Bruno Haible <bruno@clisp.org>
parents:
10244
diff
changeset
|
129 Size 32 would not be sufficient: On HP-UX, SIGXCPU = 33, SIGXFSZ = 34. */ |
31614a69f913
Don't override previously installed signal handlers.
Bruno Haible <bruno@clisp.org>
parents:
10244
diff
changeset
|
130 static struct sigaction saved_sigactions[64]; |
31614a69f913
Don't override previously installed signal handlers.
Bruno Haible <bruno@clisp.org>
parents:
10244
diff
changeset
|
131 |
31614a69f913
Don't override previously installed signal handlers.
Bruno Haible <bruno@clisp.org>
parents:
10244
diff
changeset
|
132 |
4770 | 133 /* Uninstall the handlers. */ |
134 static inline void | |
135 uninstall_handlers () | |
136 { | |
137 size_t i; | |
138 | |
139 for (i = 0; i < num_fatal_signals; i++) | |
5536
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
140 if (fatal_signals[i] >= 0) |
10381
31614a69f913
Don't override previously installed signal handlers.
Bruno Haible <bruno@clisp.org>
parents:
10244
diff
changeset
|
141 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
142 int sig = fatal_signals[i]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
143 if (saved_sigactions[sig].sa_handler == SIG_IGN) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
144 saved_sigactions[sig].sa_handler = SIG_DFL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
145 sigaction (sig, &saved_sigactions[sig], NULL); |
10381
31614a69f913
Don't override previously installed signal handlers.
Bruno Haible <bruno@clisp.org>
parents:
10244
diff
changeset
|
146 } |
4770 | 147 } |
148 | |
149 | |
150 /* The signal handler. It gets called asynchronously. */ | |
151 static void | |
152 fatal_signal_handler (int sig) | |
153 { | |
154 for (;;) | |
155 { | |
156 /* Get the last registered cleanup action, in a reentrant way. */ | |
157 action_t action; | |
158 size_t n = actions_count; | |
159 if (n == 0) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
160 break; |
4770 | 161 n--; |
162 actions_count = n; | |
4786
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
163 action = actions[n].action; |
4770 | 164 /* Execute the action. */ |
165 action (); | |
166 } | |
167 | |
4786
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
168 /* Now execute the signal's default action. |
10244
478a8cd21855
Reenter the fatal_signal_handler in case of nested signal.
Bruno Haible <bruno@clisp.org>
parents:
10230
diff
changeset
|
169 If the signal being delivered was blocked, the re-raised signal would be |
478a8cd21855
Reenter the fatal_signal_handler in case of nested signal.
Bruno Haible <bruno@clisp.org>
parents:
10230
diff
changeset
|
170 delivered when this handler returns. But the way we install this handler, |
478a8cd21855
Reenter the fatal_signal_handler in case of nested signal.
Bruno Haible <bruno@clisp.org>
parents:
10230
diff
changeset
|
171 no signal is blocked, and the re-raised signal is delivered already |
478a8cd21855
Reenter the fatal_signal_handler in case of nested signal.
Bruno Haible <bruno@clisp.org>
parents:
10230
diff
changeset
|
172 during raise(). */ |
4770 | 173 uninstall_handlers (); |
174 raise (sig); | |
175 } | |
176 | |
177 | |
178 /* Install the handlers. */ | |
179 static inline void | |
180 install_handlers () | |
181 { | |
182 size_t i; | |
10230
54813304edd2
Use sigaction module rather than signal().
Eric Blake <ebb9@byu.net>
parents:
10221
diff
changeset
|
183 struct sigaction action; |
4770 | 184 |
10230
54813304edd2
Use sigaction module rather than signal().
Eric Blake <ebb9@byu.net>
parents:
10221
diff
changeset
|
185 action.sa_handler = &fatal_signal_handler; |
10244
478a8cd21855
Reenter the fatal_signal_handler in case of nested signal.
Bruno Haible <bruno@clisp.org>
parents:
10230
diff
changeset
|
186 /* If we get a fatal signal while executing fatal_signal_handler, enter |
478a8cd21855
Reenter the fatal_signal_handler in case of nested signal.
Bruno Haible <bruno@clisp.org>
parents:
10230
diff
changeset
|
187 fatal_signal_handler recursively, since it is reentrant. Hence no |
478a8cd21855
Reenter the fatal_signal_handler in case of nested signal.
Bruno Haible <bruno@clisp.org>
parents:
10230
diff
changeset
|
188 SA_RESETHAND. */ |
478a8cd21855
Reenter the fatal_signal_handler in case of nested signal.
Bruno Haible <bruno@clisp.org>
parents:
10230
diff
changeset
|
189 action.sa_flags = SA_NODEFER; |
10230
54813304edd2
Use sigaction module rather than signal().
Eric Blake <ebb9@byu.net>
parents:
10221
diff
changeset
|
190 sigemptyset (&action.sa_mask); |
4770 | 191 for (i = 0; i < num_fatal_signals; i++) |
5536
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
192 if (fatal_signals[i] >= 0) |
10381
31614a69f913
Don't override previously installed signal handlers.
Bruno Haible <bruno@clisp.org>
parents:
10244
diff
changeset
|
193 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
194 int sig = fatal_signals[i]; |
10381
31614a69f913
Don't override previously installed signal handlers.
Bruno Haible <bruno@clisp.org>
parents:
10244
diff
changeset
|
195 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
196 if (!(sig < sizeof (saved_sigactions) / sizeof (saved_sigactions[0]))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
197 abort (); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
198 sigaction (sig, &action, &saved_sigactions[sig]); |
10381
31614a69f913
Don't override previously installed signal handlers.
Bruno Haible <bruno@clisp.org>
parents:
10244
diff
changeset
|
199 } |
4770 | 200 } |
201 | |
202 | |
203 /* Register a cleanup function to be executed when a catchable fatal signal | |
204 occurs. */ | |
205 void | |
206 at_fatal_signal (action_t action) | |
207 { | |
208 static bool cleanup_initialized = false; | |
209 if (!cleanup_initialized) | |
210 { | |
5536
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
211 init_fatal_signals (); |
4770 | 212 install_handlers (); |
213 cleanup_initialized = true; | |
214 } | |
215 | |
216 if (actions_count == actions_allocated) | |
217 { | |
218 /* Extend the actions array. Note that we cannot use xrealloc(), | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
219 because then the cleanup() function could access an already |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
220 deallocated array. */ |
4786
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
221 actions_entry_t *old_actions = actions; |
7014
43bb3848f1c7
Merge from gettext 0.15: Be more careful to use 'volatile'.
Bruno Haible <bruno@clisp.org>
parents:
6751
diff
changeset
|
222 size_t old_actions_allocated = actions_allocated; |
4770 | 223 size_t new_actions_allocated = 2 * actions_allocated; |
4786
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
224 actions_entry_t *new_actions = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
225 XNMALLOC (new_actions_allocated, actions_entry_t); |
7014
43bb3848f1c7
Merge from gettext 0.15: Be more careful to use 'volatile'.
Bruno Haible <bruno@clisp.org>
parents:
6751
diff
changeset
|
226 size_t k; |
4770 | 227 |
7014
43bb3848f1c7
Merge from gettext 0.15: Be more careful to use 'volatile'.
Bruno Haible <bruno@clisp.org>
parents:
6751
diff
changeset
|
228 /* Don't use memcpy() here, because memcpy takes non-volatile arguments |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
229 and is therefore not guaranteed to complete all memory stores before |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
230 the next statement. */ |
7014
43bb3848f1c7
Merge from gettext 0.15: Be more careful to use 'volatile'.
Bruno Haible <bruno@clisp.org>
parents:
6751
diff
changeset
|
231 for (k = 0; k < old_actions_allocated; k++) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
232 new_actions[k] = old_actions[k]; |
4770 | 233 actions = new_actions; |
234 actions_allocated = new_actions_allocated; | |
235 /* Now we can free the old actions array. */ | |
236 if (old_actions != static_actions) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
237 free (old_actions); |
4770 | 238 } |
4786
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
239 /* The two uses of 'volatile' in the types above (and ISO C 99 section |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
240 5.1.2.3.(5)) ensure that we increment the actions_count only after |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
241 the new action has been written to the memory location |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
242 actions[actions_count]. */ |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
243 actions[actions_count].action = action; |
4770 | 244 actions_count++; |
245 } | |
246 | |
247 | |
248 /* ========================================================================= */ | |
249 | |
250 | |
251 static sigset_t fatal_signal_set; | |
252 | |
253 static void | |
254 init_fatal_signal_set () | |
255 { | |
256 static bool fatal_signal_set_initialized = false; | |
257 if (!fatal_signal_set_initialized) | |
258 { | |
259 size_t i; | |
260 | |
5536
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
261 init_fatal_signals (); |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
262 |
4770 | 263 sigemptyset (&fatal_signal_set); |
264 for (i = 0; i < num_fatal_signals; i++) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
265 if (fatal_signals[i] >= 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10383
diff
changeset
|
266 sigaddset (&fatal_signal_set, fatal_signals[i]); |
4770 | 267 |
268 fatal_signal_set_initialized = true; | |
269 } | |
270 } | |
271 | |
4786
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
272 /* Temporarily delay the catchable fatal signals. */ |
4770 | 273 void |
274 block_fatal_signals () | |
275 { | |
276 init_fatal_signal_set (); | |
277 sigprocmask (SIG_BLOCK, &fatal_signal_set, NULL); | |
278 } | |
279 | |
4786
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
280 /* Stop delaying the catchable fatal signals. */ |
4770 | 281 void |
282 unblock_fatal_signals () | |
283 { | |
284 init_fatal_signal_set (); | |
285 sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL); | |
286 } |