]>
Commit | Line | Data |
---|---|---|
ccc6cda3 JA |
1 | /* sig.h -- header file for signal handler definitions. */ |
2 | ||
012bac39 | 3 | /* Copyright (C) 1994-2009 Free Software Foundation, Inc. |
ccc6cda3 JA |
4 | |
5 | This file is part of GNU Bash, the Bourne Again SHell. | |
6 | ||
2e4498b3 CR |
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. | |
ccc6cda3 | 11 | |
2e4498b3 CR |
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. | |
ccc6cda3 | 16 | |
2e4498b3 CR |
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 | */ | |
ccc6cda3 JA |
20 | |
21 | /* Make sure that this is included *after* config.h! */ | |
22 | ||
23 | #if !defined (_SIG_H_) | |
24 | # define _SIG_H_ | |
25 | ||
26 | #include "stdc.h" | |
27 | ||
28 | #if !defined (SIGABRT) && defined (SIGIOT) | |
29 | # define SIGABRT SIGIOT | |
30 | #endif | |
31 | ||
32 | #define sighandler RETSIGTYPE | |
7117c2d2 | 33 | typedef RETSIGTYPE SigHandler __P((int)); |
ccc6cda3 JA |
34 | |
35 | #if defined (VOID_SIGHANDLER) | |
36 | # define SIGRETURN(n) return | |
37 | #else | |
38 | # define SIGRETURN(n) return(n) | |
39 | #endif /* !VOID_SIGHANDLER */ | |
40 | ||
41 | /* Here is a definition for set_signal_handler () which simply expands to | |
42 | a call to signal () for non-Posix systems. The code for set_signal_handler | |
43 | in the Posix case resides in general.c. */ | |
44 | #if !defined (HAVE_POSIX_SIGNALS) | |
45 | # define set_signal_handler(sig, handler) (SigHandler *)signal (sig, handler) | |
46 | #else | |
7117c2d2 | 47 | extern SigHandler *set_signal_handler __P((int, SigHandler *)); /* in sig.c */ |
ccc6cda3 JA |
48 | #endif /* _POSIX_VERSION */ |
49 | ||
ccc6cda3 JA |
50 | #if !defined (SIGCHLD) && defined (SIGCLD) |
51 | # define SIGCHLD SIGCLD | |
52 | #endif | |
53 | ||
54 | #if !defined (HAVE_POSIX_SIGNALS) && !defined (sigmask) | |
55 | # define sigmask(x) (1 << ((x)-1)) | |
56 | #endif /* !HAVE_POSIX_SIGNALS && !sigmask */ | |
57 | ||
58 | #if !defined (HAVE_POSIX_SIGNALS) | |
59 | # if !defined (SIG_BLOCK) | |
60 | # define SIG_BLOCK 2 | |
61 | # define SIG_SETMASK 3 | |
62 | # endif /* SIG_BLOCK */ | |
63 | ||
64 | /* sigset_t defined in config.h */ | |
65 | ||
66 | /* Make sure there is nothing inside the signal set. */ | |
67 | # define sigemptyset(set) (*(set) = 0) | |
68 | ||
69 | /* Initialize the signal set to hold all signals. */ | |
70 | # define sigfillset(set) (*set) = sigmask (NSIG) - 1 | |
71 | ||
72 | /* Add SIG to the contents of SET. */ | |
73 | # define sigaddset(set, sig) *(set) |= sigmask (sig) | |
74 | ||
75 | /* Delete SIG from signal set SET. */ | |
76 | # define sigdelset(set, sig) *(set) &= ~sigmask (sig) | |
77 | ||
78 | /* Is SIG a member of the signal set SET? */ | |
79 | # define sigismember(set, sig) ((*(set) & sigmask (sig)) != 0) | |
80 | ||
81 | /* Suspend the process until the reception of one of the signals | |
82 | not present in SET. */ | |
83 | # define sigsuspend(set) sigpause (*(set)) | |
84 | #endif /* !HAVE_POSIX_SIGNALS */ | |
85 | ||
86 | /* These definitions are used both in POSIX and non-POSIX implementations. */ | |
87 | ||
88 | #define BLOCK_SIGNAL(sig, nvar, ovar) \ | |
7117c2d2 | 89 | do { \ |
ccc6cda3 JA |
90 | sigemptyset (&nvar); \ |
91 | sigaddset (&nvar, sig); \ | |
92 | sigemptyset (&ovar); \ | |
7117c2d2 JA |
93 | sigprocmask (SIG_BLOCK, &nvar, &ovar); \ |
94 | } while (0) | |
ccc6cda3 | 95 | |
bfd181e7 | 96 | #define UNBLOCK_SIGNAL(ovar) sigprocmask (SIG_SETMASK, &ovar, (sigset_t *) NULL) |
f6da9f85 | 97 | |
ccc6cda3 | 98 | #if defined (HAVE_POSIX_SIGNALS) |
bfd181e7 CR |
99 | # define BLOCK_CHILD(nvar, ovar) BLOCK_SIGNAL (SIGCHLD, nvar, ovar) |
100 | # define UNBLOCK_CHILD(ovar) UNBLOCK_SIGNAL(ovar) | |
ccc6cda3 JA |
101 | #else /* !HAVE_POSIX_SIGNALS */ |
102 | # define BLOCK_CHILD(nvar, ovar) ovar = sigblock (sigmask (SIGCHLD)) | |
103 | # define UNBLOCK_CHILD(ovar) sigsetmask (ovar) | |
104 | #endif /* !HAVE_POSIX_SIGNALS */ | |
105 | ||
7027abcb CR |
106 | /* Extern variables */ |
107 | extern volatile int sigwinch_received; | |
108 | ||
ac18b312 CR |
109 | extern int interrupt_immediately; |
110 | extern int terminate_immediately; | |
111 | ||
ccc6cda3 | 112 | /* Functions from sig.c. */ |
ac18b312 CR |
113 | extern sighandler termsig_sighandler __P((int)); |
114 | extern void termsig_handler __P((int)); | |
ccc6cda3 | 115 | extern sighandler sigint_sighandler __P((int)); |
7117c2d2 | 116 | extern void initialize_signals __P((int)); |
d166f048 | 117 | extern void initialize_terminating_signals __P((void)); |
ccc6cda3 | 118 | extern void reset_terminating_signals __P((void)); |
d3ad40de | 119 | extern void top_level_cleanup __P((void)); |
ccc6cda3 | 120 | extern void throw_to_top_level __P((void)); |
f73dda09 | 121 | extern void jump_to_top_level __P((int)) __attribute__((__noreturn__)); |
ccc6cda3 | 122 | |
7027abcb CR |
123 | extern sighandler sigwinch_sighandler __P((int)); |
124 | extern void set_sigwinch_handler __P((void)); | |
125 | extern void unset_sigwinch_handler __P((void)); | |
126 | ||
ccc6cda3 JA |
127 | /* Functions defined in trap.c. */ |
128 | extern SigHandler *set_sigint_handler __P((void)); | |
e8ce775d JA |
129 | extern SigHandler *trap_to_sighandler __P((int)); |
130 | extern sighandler trap_handler __P((int)); | |
ccc6cda3 JA |
131 | |
132 | #endif /* _SIG_H_ */ |