Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 1 | /* sig.h -- header file for signal handler definitions. */ |
| 2 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 3 | /* Copyright (C) 1994-2009 Free Software Foundation, Inc. |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 4 | |
| 5 | This file is part of GNU Bash, the Bourne Again SHell. |
| 6 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 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. |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 11 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 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. |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 16 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 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 | */ |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 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 |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 33 | typedef RETSIGTYPE SigHandler __P((int)); |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 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 |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 47 | extern SigHandler *set_signal_handler __P((int, SigHandler *)); /* in sig.c */ |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 48 | #endif /* _POSIX_VERSION */ |
| 49 | |
| 50 | /* Definitions used by the job control code. */ |
| 51 | #if defined (JOB_CONTROL) |
| 52 | |
| 53 | #if !defined (SIGCHLD) && defined (SIGCLD) |
| 54 | # define SIGCHLD SIGCLD |
| 55 | #endif |
| 56 | |
| 57 | #if !defined (HAVE_POSIX_SIGNALS) && !defined (sigmask) |
| 58 | # define sigmask(x) (1 << ((x)-1)) |
| 59 | #endif /* !HAVE_POSIX_SIGNALS && !sigmask */ |
| 60 | |
| 61 | #if !defined (HAVE_POSIX_SIGNALS) |
| 62 | # if !defined (SIG_BLOCK) |
| 63 | # define SIG_BLOCK 2 |
| 64 | # define SIG_SETMASK 3 |
| 65 | # endif /* SIG_BLOCK */ |
| 66 | |
| 67 | /* sigset_t defined in config.h */ |
| 68 | |
| 69 | /* Make sure there is nothing inside the signal set. */ |
| 70 | # define sigemptyset(set) (*(set) = 0) |
| 71 | |
| 72 | /* Initialize the signal set to hold all signals. */ |
| 73 | # define sigfillset(set) (*set) = sigmask (NSIG) - 1 |
| 74 | |
| 75 | /* Add SIG to the contents of SET. */ |
| 76 | # define sigaddset(set, sig) *(set) |= sigmask (sig) |
| 77 | |
| 78 | /* Delete SIG from signal set SET. */ |
| 79 | # define sigdelset(set, sig) *(set) &= ~sigmask (sig) |
| 80 | |
| 81 | /* Is SIG a member of the signal set SET? */ |
| 82 | # define sigismember(set, sig) ((*(set) & sigmask (sig)) != 0) |
| 83 | |
| 84 | /* Suspend the process until the reception of one of the signals |
| 85 | not present in SET. */ |
| 86 | # define sigsuspend(set) sigpause (*(set)) |
| 87 | #endif /* !HAVE_POSIX_SIGNALS */ |
| 88 | |
| 89 | /* These definitions are used both in POSIX and non-POSIX implementations. */ |
| 90 | |
| 91 | #define BLOCK_SIGNAL(sig, nvar, ovar) \ |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 92 | do { \ |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 93 | sigemptyset (&nvar); \ |
| 94 | sigaddset (&nvar, sig); \ |
| 95 | sigemptyset (&ovar); \ |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 96 | sigprocmask (SIG_BLOCK, &nvar, &ovar); \ |
| 97 | } while (0) |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 98 | |
| 99 | #if defined (HAVE_POSIX_SIGNALS) |
| 100 | # define BLOCK_CHILD(nvar, ovar) \ |
| 101 | BLOCK_SIGNAL (SIGCHLD, nvar, ovar) |
| 102 | # define UNBLOCK_CHILD(ovar) \ |
| 103 | sigprocmask (SIG_SETMASK, &ovar, (sigset_t *) NULL) |
| 104 | #else /* !HAVE_POSIX_SIGNALS */ |
| 105 | # define BLOCK_CHILD(nvar, ovar) ovar = sigblock (sigmask (SIGCHLD)) |
| 106 | # define UNBLOCK_CHILD(ovar) sigsetmask (ovar) |
| 107 | #endif /* !HAVE_POSIX_SIGNALS */ |
| 108 | |
| 109 | #endif /* JOB_CONTROL */ |
| 110 | |
Jari Aalto | 95732b4 | 2005-12-07 14:08:12 +0000 | [diff] [blame] | 111 | /* Extern variables */ |
| 112 | extern volatile int sigwinch_received; |
| 113 | |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 114 | extern int interrupt_immediately; |
| 115 | extern int terminate_immediately; |
| 116 | |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 117 | /* Functions from sig.c. */ |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 118 | extern sighandler termsig_sighandler __P((int)); |
| 119 | extern void termsig_handler __P((int)); |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 120 | extern sighandler sigint_sighandler __P((int)); |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 121 | extern void initialize_signals __P((int)); |
Jari Aalto | d166f04 | 1997-06-05 14:59:13 +0000 | [diff] [blame] | 122 | extern void initialize_terminating_signals __P((void)); |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 123 | extern void reset_terminating_signals __P((void)); |
Jari Aalto | f1be666 | 2008-11-18 13:15:12 +0000 | [diff] [blame] | 124 | extern void top_level_cleanup __P((void)); |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 125 | extern void throw_to_top_level __P((void)); |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 126 | extern void jump_to_top_level __P((int)) __attribute__((__noreturn__)); |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 127 | |
Jari Aalto | 95732b4 | 2005-12-07 14:08:12 +0000 | [diff] [blame] | 128 | extern sighandler sigwinch_sighandler __P((int)); |
| 129 | extern void set_sigwinch_handler __P((void)); |
| 130 | extern void unset_sigwinch_handler __P((void)); |
| 131 | |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 132 | /* Functions defined in trap.c. */ |
| 133 | extern SigHandler *set_sigint_handler __P((void)); |
Jari Aalto | e8ce775 | 1997-09-22 20:22:27 +0000 | [diff] [blame] | 134 | extern SigHandler *trap_to_sighandler __P((int)); |
| 135 | extern sighandler trap_handler __P((int)); |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 136 | |
| 137 | #endif /* _SIG_H_ */ |