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