]> git.ipfire.org Git - thirdparty/bash.git/blob - quit.h
Bash-4.2 patch 8
[thirdparty/bash.git] / quit.h
1 /* quit.h -- How to handle SIGINT gracefully. */
2
3 /* Copyright (C) 1993-2009 Free Software Foundation, Inc.
4
5 This file is part of GNU Bash, the Bourne Again SHell.
6
7 Bash is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 Bash is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #if !defined (_QUIT_H_)
22 #define _QUIT_H_
23
24 /* Non-zero means SIGINT has already ocurred. */
25 extern volatile int interrupt_state;
26 extern volatile int terminating_signal;
27
28 /* Macro to call a great deal. SIGINT just sets the interrupt_state variable.
29 When it is safe, put QUIT in the code, and the "interrupt" will take
30 place. The same scheme is used for terminating signals (e.g., SIGHUP)
31 and the terminating_signal variable. That calls a function which will
32 end up exiting the shell. */
33 #define QUIT \
34 do { \
35 if (terminating_signal) termsig_handler (terminating_signal); \
36 if (interrupt_state) throw_to_top_level (); \
37 } while (0)
38
39 #define SETINTERRUPT interrupt_state = 1
40 #define CLRINTERRUPT interrupt_state = 0
41
42 #define ADDINTERRUPT interrupt_state++
43 #define DELINTERRUPT interrupt_state--
44
45 /* The same sort of thing, this time just for signals that would ordinarily
46 cause the shell to terminate. */
47
48 #define CHECK_TERMSIG \
49 do { \
50 if (terminating_signal) termsig_handler (terminating_signal); \
51 } while (0)
52
53 #endif /* _QUIT_H_ */