update from texinfo
[gnulib.git] / lib / fatal-signal.h
1 /* Emergency actions in case of a fatal signal.
2    Copyright (C) 2003 Free Software Foundation, Inc.
3    Written by Bruno Haible <bruno@clisp.org>, 2003.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2, or (at your option)
8    any later version.
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
16    along with this program; if not, write to the Free Software Foundation,
17    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24
25 /* It is often useful to do some cleanup action when a usually fatal signal
26    terminates the process, like removing a temporary file or killing a
27    subprocess that may be stuck waiting for a device, pipe or network input.
28    Such signals are SIGHUP, SIGINT, SIGPIPE, SIGTERM, and possibly others.
29    The limitation of this facility is that it cannot work for SIGKILL.  */
30
31 /* Register a cleanup function to be executed when a catchable fatal signal
32    occurs.
33
34    Restrictions for the cleanup function:
35      - The cleanup function can do all kinds of system calls.
36      - It can also access application dependent memory locations and data
37        structures provided they are in a consistent state. One way to ensure
38        this is through block_fatal_signals()/unblock_fatal_signals(), see
39        below.  Another - more tricky - way to ensure this is the careful use
40        of 'volatile'.
41    However,
42      - malloc() and similarly complex facilities are not safe to be called
43        because they are not guaranteed to be in a consistent state.
44      - Also, the cleanup function must not block the catchable fatal signals
45        and leave them blocked upon return.
46
47    The cleanup function is executed asynchronously.  It is unspecified
48    whether during its execution the catchable fatal signals are blocked
49    or not.  */
50 extern void at_fatal_signal (void (*function) (void));
51
52
53 /* Sometimes it is necessary to block the usually fatal signals while the
54    data structures being accessed by the cleanup action are being built or
55    reorganized.  This is the case, for example, when a temporary file or
56    directory is created through mkstemp() or mkdtemp(), because these
57    functions create the temporary file or directory _before_ returning its
58    name to the application.  */
59
60 /* Temporarily delay the catchable fatal signals.
61    The signals will be blocked (= delayed) until the next call to
62    unblock_fatal_signals().  If the signals are already blocked, a further
63    call to block_fatal_signals() has no effect.  */
64 extern void block_fatal_signals (void);
65
66 /* Stop delaying the catchable fatal signals.  */
67 extern void unblock_fatal_signals (void);
68
69
70 #ifdef __cplusplus
71 }
72 #endif