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