Mercurial > gnulib
annotate lib/fatal-signal.h @ 40237:b1386ce84ff5
fatal-signal: Add function that lists the fatal signals.
* lib/fatal-signal.h (get_fatal_signals): New declaration.
* lib/fatal-signal.c (get_fatal_signals): New function.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 16 Mar 2019 17:48:06 +0100 |
parents | b06060465f09 |
children | 3ac749aa0041 |
rev | line source |
---|---|
4770 | 1 /* Emergency actions in case of a fatal signal. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 2003-2004, 2009-2019 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:
5848
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:
5848
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:
5848
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 | |
19190 | 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
4770 | 17 |
18 | |
19 #ifdef __cplusplus | |
20 extern "C" { | |
21 #endif | |
22 | |
23 | |
24 /* It is often useful to do some cleanup action when a usually fatal signal | |
25 terminates the process, like removing a temporary file or killing a | |
26 subprocess that may be stuck waiting for a device, pipe or network input. | |
27 Such signals are SIGHUP, SIGINT, SIGPIPE, SIGTERM, and possibly others. | |
5536
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
28 The limitation of this facility is that it cannot work for SIGKILL. |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
29 |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
30 Signals with a SIG_IGN handler are considered to be non-fatal. The |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
31 functions in this file assume that when a SIG_IGN handler is installed |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
32 for a signal, it was installed before any functions in this file were |
f64f1da7e350
Signals whose handler is set to SIG_IGN are not fatal.
Bruno Haible <bruno@clisp.org>
parents:
4786
diff
changeset
|
33 called and it stays so for the whole lifetime of the process. */ |
4770 | 34 |
35 /* Register a cleanup function to be executed when a catchable fatal signal | |
4786
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
36 occurs. |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
37 |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
38 Restrictions for the cleanup function: |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
39 - The cleanup function can do all kinds of system calls. |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
40 - It can also access application dependent memory locations and data |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
41 structures provided they are in a consistent state. One way to ensure |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
42 this is through block_fatal_signals()/unblock_fatal_signals(), see |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
43 below. Another - more tricky - way to ensure this is the careful use |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
44 of 'volatile'. |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
45 However, |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
46 - malloc() and similarly complex facilities are not safe to be called |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
47 because they are not guaranteed to be in a consistent state. |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
48 - Also, the cleanup function must not block the catchable fatal signals |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
49 and leave them blocked upon return. |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
50 |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
51 The cleanup function is executed asynchronously. It is unspecified |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
52 whether during its execution the catchable fatal signals are blocked |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
53 or not. */ |
4770 | 54 extern void at_fatal_signal (void (*function) (void)); |
55 | |
56 | |
57 /* Sometimes it is necessary to block the usually fatal signals while the | |
58 data structures being accessed by the cleanup action are being built or | |
59 reorganized. This is the case, for example, when a temporary file or | |
60 directory is created through mkstemp() or mkdtemp(), because these | |
61 functions create the temporary file or directory _before_ returning its | |
62 name to the application. */ | |
63 | |
4786
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
64 /* Temporarily delay the catchable fatal signals. |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
65 The signals will be blocked (= delayed) until the next call to |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
66 unblock_fatal_signals(). If the signals are already blocked, a further |
83d8d561903a
Improved 'fatal-signal' module.
Bruno Haible <bruno@clisp.org>
parents:
4770
diff
changeset
|
67 call to block_fatal_signals() has no effect. */ |
4770 | 68 extern void block_fatal_signals (void); |
69 | |
70 /* Stop delaying the catchable fatal signals. */ | |
71 extern void unblock_fatal_signals (void); | |
72 | |
73 | |
40237
b1386ce84ff5
fatal-signal: Add function that lists the fatal signals.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
74 /* Return the list of signals that block_fatal_signals/unblock_fatal_signals |
b1386ce84ff5
fatal-signal: Add function that lists the fatal signals.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
75 would block or unblock. |
b1386ce84ff5
fatal-signal: Add function that lists the fatal signals.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
76 Fills signals[0..count-1] and returns count. */ |
b1386ce84ff5
fatal-signal: Add function that lists the fatal signals.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
77 extern unsigned int get_fatal_signals (int signals[64]); |
b1386ce84ff5
fatal-signal: Add function that lists the fatal signals.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
78 |
b1386ce84ff5
fatal-signal: Add function that lists the fatal signals.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
79 |
4770 | 80 #ifdef __cplusplus |
81 } | |
82 #endif |