| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/sig.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* sig.c - interface for shell signal handlers and signal initialization. */ | - | ||||||||||||||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||||||||||||||
| 3 | /* Copyright (C) 1994-2015 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 | #include "config.h" | - | ||||||||||||||||||||||||||||||||||||
| 22 | - | |||||||||||||||||||||||||||||||||||||
| 23 | #include "bashtypes.h" | - | ||||||||||||||||||||||||||||||||||||
| 24 | - | |||||||||||||||||||||||||||||||||||||
| 25 | #if defined (HAVE_UNISTD_H) | - | ||||||||||||||||||||||||||||||||||||
| 26 | # ifdef _MINIX | - | ||||||||||||||||||||||||||||||||||||
| 27 | # include <sys/types.h> | - | ||||||||||||||||||||||||||||||||||||
| 28 | # endif | - | ||||||||||||||||||||||||||||||||||||
| 29 | # include <unistd.h> | - | ||||||||||||||||||||||||||||||||||||
| 30 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 31 | - | |||||||||||||||||||||||||||||||||||||
| 32 | #include <stdio.h> | - | ||||||||||||||||||||||||||||||||||||
| 33 | #include <signal.h> | - | ||||||||||||||||||||||||||||||||||||
| 34 | - | |||||||||||||||||||||||||||||||||||||
| 35 | #include "bashintl.h" | - | ||||||||||||||||||||||||||||||||||||
| 36 | - | |||||||||||||||||||||||||||||||||||||
| 37 | #include "shell.h" | - | ||||||||||||||||||||||||||||||||||||
| 38 | #include "execute_cmd.h" | - | ||||||||||||||||||||||||||||||||||||
| 39 | #if defined (JOB_CONTROL) | - | ||||||||||||||||||||||||||||||||||||
| 40 | #include "jobs.h" | - | ||||||||||||||||||||||||||||||||||||
| 41 | #endif /* JOB_CONTROL */ | - | ||||||||||||||||||||||||||||||||||||
| 42 | #include "siglist.h" | - | ||||||||||||||||||||||||||||||||||||
| 43 | #include "sig.h" | - | ||||||||||||||||||||||||||||||||||||
| 44 | #include "trap.h" | - | ||||||||||||||||||||||||||||||||||||
| 45 | - | |||||||||||||||||||||||||||||||||||||
| 46 | #include "builtins/common.h" | - | ||||||||||||||||||||||||||||||||||||
| 47 | #include "builtins/builtext.h" | - | ||||||||||||||||||||||||||||||||||||
| 48 | - | |||||||||||||||||||||||||||||||||||||
| 49 | #if defined (READLINE) | - | ||||||||||||||||||||||||||||||||||||
| 50 | # include "bashline.h" | - | ||||||||||||||||||||||||||||||||||||
| 51 | # include <readline/readline.h> | - | ||||||||||||||||||||||||||||||||||||
| 52 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 53 | - | |||||||||||||||||||||||||||||||||||||
| 54 | #if defined (HISTORY) | - | ||||||||||||||||||||||||||||||||||||
| 55 | # include "bashhist.h" | - | ||||||||||||||||||||||||||||||||||||
| 56 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 57 | - | |||||||||||||||||||||||||||||||||||||
| 58 | extern void initialize_siglist (); | - | ||||||||||||||||||||||||||||||||||||
| 59 | - | |||||||||||||||||||||||||||||||||||||
| 60 | #if !defined (JOB_CONTROL) | - | ||||||||||||||||||||||||||||||||||||
| 61 | extern void initialize_job_signals __P((void)); | - | ||||||||||||||||||||||||||||||||||||
| 62 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 63 | - | |||||||||||||||||||||||||||||||||||||
| 64 | /* Non-zero after SIGINT. */ | - | ||||||||||||||||||||||||||||||||||||
| 65 | volatile sig_atomic_t interrupt_state = 0; | - | ||||||||||||||||||||||||||||||||||||
| 66 | - | |||||||||||||||||||||||||||||||||||||
| 67 | /* Non-zero after SIGWINCH */ | - | ||||||||||||||||||||||||||||||||||||
| 68 | volatile sig_atomic_t sigwinch_received = 0; | - | ||||||||||||||||||||||||||||||||||||
| 69 | - | |||||||||||||||||||||||||||||||||||||
| 70 | /* Non-zero after SIGTERM */ | - | ||||||||||||||||||||||||||||||||||||
| 71 | volatile sig_atomic_t sigterm_received = 0; | - | ||||||||||||||||||||||||||||||||||||
| 72 | - | |||||||||||||||||||||||||||||||||||||
| 73 | /* Set to the value of any terminating signal received. */ | - | ||||||||||||||||||||||||||||||||||||
| 74 | volatile sig_atomic_t terminating_signal = 0; | - | ||||||||||||||||||||||||||||||||||||
| 75 | - | |||||||||||||||||||||||||||||||||||||
| 76 | /* The environment at the top-level R-E loop. We use this in | - | ||||||||||||||||||||||||||||||||||||
| 77 | the case of error return. */ | - | ||||||||||||||||||||||||||||||||||||
| 78 | procenv_t top_level; | - | ||||||||||||||||||||||||||||||||||||
| 79 | - | |||||||||||||||||||||||||||||||||||||
| 80 | #if defined (JOB_CONTROL) || defined (HAVE_POSIX_SIGNALS) | - | ||||||||||||||||||||||||||||||||||||
| 81 | /* The signal masks that this shell runs with. */ | - | ||||||||||||||||||||||||||||||||||||
| 82 | sigset_t top_level_mask; | - | ||||||||||||||||||||||||||||||||||||
| 83 | #endif /* JOB_CONTROL */ | - | ||||||||||||||||||||||||||||||||||||
| 84 | - | |||||||||||||||||||||||||||||||||||||
| 85 | /* When non-zero, we throw_to_top_level (). */ | - | ||||||||||||||||||||||||||||||||||||
| 86 | int interrupt_immediately = 0; | - | ||||||||||||||||||||||||||||||||||||
| 87 | - | |||||||||||||||||||||||||||||||||||||
| 88 | /* When non-zero, we call the terminating signal handler immediately. */ | - | ||||||||||||||||||||||||||||||||||||
| 89 | int terminate_immediately = 0; | - | ||||||||||||||||||||||||||||||||||||
| 90 | - | |||||||||||||||||||||||||||||||||||||
| 91 | #if defined (SIGWINCH) | - | ||||||||||||||||||||||||||||||||||||
| 92 | static SigHandler *old_winch = (SigHandler *)SIG_DFL; | - | ||||||||||||||||||||||||||||||||||||
| 93 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 94 | - | |||||||||||||||||||||||||||||||||||||
| 95 | static void initialize_shell_signals __P((void)); | - | ||||||||||||||||||||||||||||||||||||
| 96 | - | |||||||||||||||||||||||||||||||||||||
| 97 | void | - | ||||||||||||||||||||||||||||||||||||
| 98 | initialize_signals (reinit) | - | ||||||||||||||||||||||||||||||||||||
| 99 | int reinit; | - | ||||||||||||||||||||||||||||||||||||
| 100 | { | - | ||||||||||||||||||||||||||||||||||||
| 101 | initialize_shell_signals (); | - | ||||||||||||||||||||||||||||||||||||
| 102 | initialize_job_signals (); | - | ||||||||||||||||||||||||||||||||||||
| 103 | #if !defined (HAVE_SYS_SIGLIST) && !defined (HAVE_UNDER_SYS_SIGLIST) && !defined (HAVE_STRSIGNAL) | - | ||||||||||||||||||||||||||||||||||||
| 104 | if (reinit == 0) | - | ||||||||||||||||||||||||||||||||||||
| 105 | initialize_siglist (); | - | ||||||||||||||||||||||||||||||||||||
| 106 | #endif /* !HAVE_SYS_SIGLIST && !HAVE_UNDER_SYS_SIGLIST && !HAVE_STRSIGNAL */ | - | ||||||||||||||||||||||||||||||||||||
| 107 | } executed 5448 times by 1 test: end of blockExecuted by:
| 5448 | ||||||||||||||||||||||||||||||||||||
| 108 | - | |||||||||||||||||||||||||||||||||||||
| 109 | /* A structure describing a signal that terminates the shell if not | - | ||||||||||||||||||||||||||||||||||||
| 110 | caught. The orig_handler member is present so children can reset | - | ||||||||||||||||||||||||||||||||||||
| 111 | these signals back to their original handlers. */ | - | ||||||||||||||||||||||||||||||||||||
| 112 | struct termsig { | - | ||||||||||||||||||||||||||||||||||||
| 113 | int signum; | - | ||||||||||||||||||||||||||||||||||||
| 114 | SigHandler *orig_handler; | - | ||||||||||||||||||||||||||||||||||||
| 115 | int orig_flags; | - | ||||||||||||||||||||||||||||||||||||
| 116 | }; | - | ||||||||||||||||||||||||||||||||||||
| 117 | - | |||||||||||||||||||||||||||||||||||||
| 118 | #define NULL_HANDLER (SigHandler *)SIG_DFL | - | ||||||||||||||||||||||||||||||||||||
| 119 | - | |||||||||||||||||||||||||||||||||||||
| 120 | /* The list of signals that would terminate the shell if not caught. | - | ||||||||||||||||||||||||||||||||||||
| 121 | We catch them, but just so that we can write the history file, | - | ||||||||||||||||||||||||||||||||||||
| 122 | and so forth. */ | - | ||||||||||||||||||||||||||||||||||||
| 123 | static struct termsig terminating_signals[] = { | - | ||||||||||||||||||||||||||||||||||||
| 124 | #ifdef SIGHUP | - | ||||||||||||||||||||||||||||||||||||
| 125 | { SIGHUP, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 126 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 127 | - | |||||||||||||||||||||||||||||||||||||
| 128 | #ifdef SIGINT | - | ||||||||||||||||||||||||||||||||||||
| 129 | { SIGINT, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 130 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 131 | - | |||||||||||||||||||||||||||||||||||||
| 132 | #ifdef SIGILL | - | ||||||||||||||||||||||||||||||||||||
| 133 | { SIGILL, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 134 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 135 | - | |||||||||||||||||||||||||||||||||||||
| 136 | #ifdef SIGTRAP | - | ||||||||||||||||||||||||||||||||||||
| 137 | { SIGTRAP, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 138 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 139 | - | |||||||||||||||||||||||||||||||||||||
| 140 | #ifdef SIGIOT | - | ||||||||||||||||||||||||||||||||||||
| 141 | { SIGIOT, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 142 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 143 | - | |||||||||||||||||||||||||||||||||||||
| 144 | #ifdef SIGDANGER | - | ||||||||||||||||||||||||||||||||||||
| 145 | { SIGDANGER, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 146 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 147 | - | |||||||||||||||||||||||||||||||||||||
| 148 | #ifdef SIGEMT | - | ||||||||||||||||||||||||||||||||||||
| 149 | { SIGEMT, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 150 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 151 | - | |||||||||||||||||||||||||||||||||||||
| 152 | #ifdef SIGFPE | - | ||||||||||||||||||||||||||||||||||||
| 153 | { SIGFPE, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 154 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 155 | - | |||||||||||||||||||||||||||||||||||||
| 156 | #ifdef SIGBUS | - | ||||||||||||||||||||||||||||||||||||
| 157 | { SIGBUS, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 158 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 159 | - | |||||||||||||||||||||||||||||||||||||
| 160 | #ifdef SIGSEGV | - | ||||||||||||||||||||||||||||||||||||
| 161 | { SIGSEGV, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 162 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 163 | - | |||||||||||||||||||||||||||||||||||||
| 164 | #ifdef SIGSYS | - | ||||||||||||||||||||||||||||||||||||
| 165 | { SIGSYS, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 166 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 167 | - | |||||||||||||||||||||||||||||||||||||
| 168 | #ifdef SIGPIPE | - | ||||||||||||||||||||||||||||||||||||
| 169 | { SIGPIPE, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 170 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 171 | - | |||||||||||||||||||||||||||||||||||||
| 172 | #ifdef SIGALRM | - | ||||||||||||||||||||||||||||||||||||
| 173 | { SIGALRM, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 174 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 175 | - | |||||||||||||||||||||||||||||||||||||
| 176 | #ifdef SIGTERM | - | ||||||||||||||||||||||||||||||||||||
| 177 | { SIGTERM, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 178 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 179 | - | |||||||||||||||||||||||||||||||||||||
| 180 | #ifdef SIGXCPU | - | ||||||||||||||||||||||||||||||||||||
| 181 | { SIGXCPU, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 182 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 183 | - | |||||||||||||||||||||||||||||||||||||
| 184 | #ifdef SIGXFSZ | - | ||||||||||||||||||||||||||||||||||||
| 185 | { SIGXFSZ, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 186 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 187 | - | |||||||||||||||||||||||||||||||||||||
| 188 | #ifdef SIGVTALRM | - | ||||||||||||||||||||||||||||||||||||
| 189 | { SIGVTALRM, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 190 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 191 | - | |||||||||||||||||||||||||||||||||||||
| 192 | #if 0 | - | ||||||||||||||||||||||||||||||||||||
| 193 | #ifdef SIGPROF | - | ||||||||||||||||||||||||||||||||||||
| 194 | { SIGPROF, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 195 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 196 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 197 | - | |||||||||||||||||||||||||||||||||||||
| 198 | #ifdef SIGLOST | - | ||||||||||||||||||||||||||||||||||||
| 199 | { SIGLOST, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 200 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 201 | - | |||||||||||||||||||||||||||||||||||||
| 202 | #ifdef SIGUSR1 | - | ||||||||||||||||||||||||||||||||||||
| 203 | { SIGUSR1, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 204 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 205 | - | |||||||||||||||||||||||||||||||||||||
| 206 | #ifdef SIGUSR2 | - | ||||||||||||||||||||||||||||||||||||
| 207 | { SIGUSR2, NULL_HANDLER, 0 }, | - | ||||||||||||||||||||||||||||||||||||
| 208 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 209 | }; | - | ||||||||||||||||||||||||||||||||||||
| 210 | - | |||||||||||||||||||||||||||||||||||||
| 211 | #define TERMSIGS_LENGTH (sizeof (terminating_signals) / sizeof (struct termsig)) | - | ||||||||||||||||||||||||||||||||||||
| 212 | - | |||||||||||||||||||||||||||||||||||||
| 213 | #define XSIG(x) (terminating_signals[x].signum) | - | ||||||||||||||||||||||||||||||||||||
| 214 | #define XHANDLER(x) (terminating_signals[x].orig_handler) | - | ||||||||||||||||||||||||||||||||||||
| 215 | #define XSAFLAGS(x) (terminating_signals[x].orig_flags) | - | ||||||||||||||||||||||||||||||||||||
| 216 | - | |||||||||||||||||||||||||||||||||||||
| 217 | static int termsigs_initialized = 0; | - | ||||||||||||||||||||||||||||||||||||
| 218 | - | |||||||||||||||||||||||||||||||||||||
| 219 | /* Initialize signals that will terminate the shell to do some | - | ||||||||||||||||||||||||||||||||||||
| 220 | unwind protection. For non-interactive shells, we only call | - | ||||||||||||||||||||||||||||||||||||
| 221 | this when a trap is defined for EXIT (0) or when trap is run | - | ||||||||||||||||||||||||||||||||||||
| 222 | to display signal dispositions. */ | - | ||||||||||||||||||||||||||||||||||||
| 223 | void | - | ||||||||||||||||||||||||||||||||||||
| 224 | initialize_terminating_signals () | - | ||||||||||||||||||||||||||||||||||||
| 225 | { | - | ||||||||||||||||||||||||||||||||||||
| 226 | register int i; | - | ||||||||||||||||||||||||||||||||||||
| 227 | #if defined (HAVE_POSIX_SIGNALS) | - | ||||||||||||||||||||||||||||||||||||
| 228 | struct sigaction act, oact; | - | ||||||||||||||||||||||||||||||||||||
| 229 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 230 | - | |||||||||||||||||||||||||||||||||||||
| 231 | if (termsigs_initialized)
| 39-81 | ||||||||||||||||||||||||||||||||||||
| 232 | return; executed 39 times by 1 test: return;Executed by:
| 39 | ||||||||||||||||||||||||||||||||||||
| 233 | - | |||||||||||||||||||||||||||||||||||||
| 234 | /* The following code is to avoid an expensive call to | - | ||||||||||||||||||||||||||||||||||||
| 235 | set_signal_handler () for each terminating_signals. Fortunately, | - | ||||||||||||||||||||||||||||||||||||
| 236 | this is possible in Posix. Unfortunately, we have to call signal () | - | ||||||||||||||||||||||||||||||||||||
| 237 | on non-Posix systems for each signal in terminating_signals. */ | - | ||||||||||||||||||||||||||||||||||||
| 238 | #if defined (HAVE_POSIX_SIGNALS) | - | ||||||||||||||||||||||||||||||||||||
| 239 | act.sa_handler = termsig_sighandler; | - | ||||||||||||||||||||||||||||||||||||
| 240 | act.sa_flags = 0; | - | ||||||||||||||||||||||||||||||||||||
| 241 | sigemptyset (&act.sa_mask); | - | ||||||||||||||||||||||||||||||||||||
| 242 | sigemptyset (&oact.sa_mask); | - | ||||||||||||||||||||||||||||||||||||
| 243 | for (i = 0; i < TERMSIGS_LENGTH; i++)
| 81-1377 | ||||||||||||||||||||||||||||||||||||
| 244 | sigaddset (&act.sa_mask, XSIG (i)); executed 1377 times by 1 test: sigaddset (&act.sa_mask, (terminating_signals[i].signum));Executed by:
| 1377 | ||||||||||||||||||||||||||||||||||||
| 245 | for (i = 0; i < TERMSIGS_LENGTH; i++)
| 81-1377 | ||||||||||||||||||||||||||||||||||||
| 246 | { | - | ||||||||||||||||||||||||||||||||||||
| 247 | /* If we've already trapped it, don't do anything. */ | - | ||||||||||||||||||||||||||||||||||||
| 248 | if (signal_is_trapped (XSIG (i)))
| 8-1369 | ||||||||||||||||||||||||||||||||||||
| 249 | continue; executed 8 times by 1 test: continue;Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
| 250 | - | |||||||||||||||||||||||||||||||||||||
| 251 | sigaction (XSIG (i), &act, &oact); | - | ||||||||||||||||||||||||||||||||||||
| 252 | XHANDLER(i) = oact.sa_handler; | - | ||||||||||||||||||||||||||||||||||||
| 253 | XSAFLAGS(i) = oact.sa_flags; | - | ||||||||||||||||||||||||||||||||||||
| 254 | /* Don't do anything with signals that are ignored at shell entry | - | ||||||||||||||||||||||||||||||||||||
| 255 | if the shell is not interactive. */ | - | ||||||||||||||||||||||||||||||||||||
| 256 | /* XXX - should we do this for interactive shells, too? */ | - | ||||||||||||||||||||||||||||||||||||
| 257 | if (interactive_shell == 0 && XHANDLER (i) == SIG_IGN)
| 34-1335 | ||||||||||||||||||||||||||||||||||||
| 258 | { | - | ||||||||||||||||||||||||||||||||||||
| 259 | sigaction (XSIG (i), &oact, &act); | - | ||||||||||||||||||||||||||||||||||||
| 260 | set_signal_hard_ignored (XSIG (i)); | - | ||||||||||||||||||||||||||||||||||||
| 261 | } executed 81 times by 1 test: end of blockExecuted by:
| 81 | ||||||||||||||||||||||||||||||||||||
| 262 | #if defined (SIGPROF) && !defined (_MINIX) | - | ||||||||||||||||||||||||||||||||||||
| 263 | if (XSIG (i) == SIGPROF && XHANDLER (i) != SIG_DFL && XHANDLER (i) != SIG_IGN)
| 0-1369 | ||||||||||||||||||||||||||||||||||||
| 264 | sigaction (XSIG (i), &oact, (struct sigaction *)NULL); never executed: sigaction ((terminating_signals[i].signum), &oact, (struct sigaction *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||
| 265 | #endif /* SIGPROF && !_MINIX */ | - | ||||||||||||||||||||||||||||||||||||
| 266 | } executed 1369 times by 1 test: end of blockExecuted by:
| 1369 | ||||||||||||||||||||||||||||||||||||
| 267 | - | |||||||||||||||||||||||||||||||||||||
| 268 | #else /* !HAVE_POSIX_SIGNALS */ | - | ||||||||||||||||||||||||||||||||||||
| 269 | - | |||||||||||||||||||||||||||||||||||||
| 270 | for (i = 0; i < TERMSIGS_LENGTH; i++) | - | ||||||||||||||||||||||||||||||||||||
| 271 | { | - | ||||||||||||||||||||||||||||||||||||
| 272 | /* If we've already trapped it, don't do anything. */ | - | ||||||||||||||||||||||||||||||||||||
| 273 | if (signal_is_trapped (XSIG (i))) | - | ||||||||||||||||||||||||||||||||||||
| 274 | continue; | - | ||||||||||||||||||||||||||||||||||||
| 275 | - | |||||||||||||||||||||||||||||||||||||
| 276 | XHANDLER(i) = signal (XSIG (i), termsig_sighandler); | - | ||||||||||||||||||||||||||||||||||||
| 277 | XSAFLAGS(i) = 0; | - | ||||||||||||||||||||||||||||||||||||
| 278 | /* Don't do anything with signals that are ignored at shell entry | - | ||||||||||||||||||||||||||||||||||||
| 279 | if the shell is not interactive. */ | - | ||||||||||||||||||||||||||||||||||||
| 280 | /* XXX - should we do this for interactive shells, too? */ | - | ||||||||||||||||||||||||||||||||||||
| 281 | if (interactive_shell == 0 && XHANDLER (i) == SIG_IGN) | - | ||||||||||||||||||||||||||||||||||||
| 282 | { | - | ||||||||||||||||||||||||||||||||||||
| 283 | signal (XSIG (i), SIG_IGN); | - | ||||||||||||||||||||||||||||||||||||
| 284 | set_signal_hard_ignored (XSIG (i)); | - | ||||||||||||||||||||||||||||||||||||
| 285 | } | - | ||||||||||||||||||||||||||||||||||||
| 286 | #ifdef SIGPROF | - | ||||||||||||||||||||||||||||||||||||
| 287 | if (XSIG (i) == SIGPROF && XHANDLER (i) != SIG_DFL && XHANDLER (i) != SIG_IGN) | - | ||||||||||||||||||||||||||||||||||||
| 288 | signal (XSIG (i), XHANDLER (i)); | - | ||||||||||||||||||||||||||||||||||||
| 289 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 290 | } | - | ||||||||||||||||||||||||||||||||||||
| 291 | - | |||||||||||||||||||||||||||||||||||||
| 292 | #endif /* !HAVE_POSIX_SIGNALS */ | - | ||||||||||||||||||||||||||||||||||||
| 293 | - | |||||||||||||||||||||||||||||||||||||
| 294 | termsigs_initialized = 1; | - | ||||||||||||||||||||||||||||||||||||
| 295 | } executed 81 times by 1 test: end of blockExecuted by:
| 81 | ||||||||||||||||||||||||||||||||||||
| 296 | - | |||||||||||||||||||||||||||||||||||||
| 297 | static void | - | ||||||||||||||||||||||||||||||||||||
| 298 | initialize_shell_signals () | - | ||||||||||||||||||||||||||||||||||||
| 299 | { | - | ||||||||||||||||||||||||||||||||||||
| 300 | if (interactive)
| 2-5446 | ||||||||||||||||||||||||||||||||||||
| 301 | initialize_terminating_signals (); executed 2 times by 1 test: initialize_terminating_signals ();Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||
| 302 | - | |||||||||||||||||||||||||||||||||||||
| 303 | #if defined (JOB_CONTROL) || defined (HAVE_POSIX_SIGNALS) | - | ||||||||||||||||||||||||||||||||||||
| 304 | /* All shells use the signal mask they inherit, and pass it along | - | ||||||||||||||||||||||||||||||||||||
| 305 | to child processes. Children will never block SIGCHLD, though. */ | - | ||||||||||||||||||||||||||||||||||||
| 306 | sigemptyset (&top_level_mask); | - | ||||||||||||||||||||||||||||||||||||
| 307 | sigprocmask (SIG_BLOCK, (sigset_t *)NULL, &top_level_mask); | - | ||||||||||||||||||||||||||||||||||||
| 308 | # if defined (SIGCHLD) | - | ||||||||||||||||||||||||||||||||||||
| 309 | sigdelset (&top_level_mask, SIGCHLD); | - | ||||||||||||||||||||||||||||||||||||
| 310 | # endif | - | ||||||||||||||||||||||||||||||||||||
| 311 | #endif /* JOB_CONTROL || HAVE_POSIX_SIGNALS */ | - | ||||||||||||||||||||||||||||||||||||
| 312 | - | |||||||||||||||||||||||||||||||||||||
| 313 | /* And, some signals that are specifically ignored by the shell. */ | - | ||||||||||||||||||||||||||||||||||||
| 314 | set_signal_handler (SIGQUIT, SIG_IGN); | - | ||||||||||||||||||||||||||||||||||||
| 315 | - | |||||||||||||||||||||||||||||||||||||
| 316 | if (interactive)
| 2-5446 | ||||||||||||||||||||||||||||||||||||
| 317 | { | - | ||||||||||||||||||||||||||||||||||||
| 318 | set_signal_handler (SIGINT, sigint_sighandler); | - | ||||||||||||||||||||||||||||||||||||
| 319 | get_original_signal (SIGTERM); | - | ||||||||||||||||||||||||||||||||||||
| 320 | if (signal_is_hard_ignored (SIGTERM) == 0)
| 0-2 | ||||||||||||||||||||||||||||||||||||
| 321 | set_signal_handler (SIGTERM, sigterm_sighandler); executed 2 times by 1 test: set_signal_handler ( 15 , sigterm_sighandler);Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||
| 322 | set_sigwinch_handler (); | - | ||||||||||||||||||||||||||||||||||||
| 323 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||||||||||||||
| 324 | } executed 5448 times by 1 test: end of blockExecuted by:
| 5448 | ||||||||||||||||||||||||||||||||||||
| 325 | - | |||||||||||||||||||||||||||||||||||||
| 326 | void | - | ||||||||||||||||||||||||||||||||||||
| 327 | reset_terminating_signals () | - | ||||||||||||||||||||||||||||||||||||
| 328 | { | - | ||||||||||||||||||||||||||||||||||||
| 329 | register int i; | - | ||||||||||||||||||||||||||||||||||||
| 330 | #if defined (HAVE_POSIX_SIGNALS) | - | ||||||||||||||||||||||||||||||||||||
| 331 | struct sigaction act; | - | ||||||||||||||||||||||||||||||||||||
| 332 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 333 | - | |||||||||||||||||||||||||||||||||||||
| 334 | if (termsigs_initialized == 0)
| 26-2531 | ||||||||||||||||||||||||||||||||||||
| 335 | return; executed 2531 times by 1 test: return;Executed by:
| 2531 | ||||||||||||||||||||||||||||||||||||
| 336 | - | |||||||||||||||||||||||||||||||||||||
| 337 | #if defined (HAVE_POSIX_SIGNALS) | - | ||||||||||||||||||||||||||||||||||||
| 338 | act.sa_flags = 0; | - | ||||||||||||||||||||||||||||||||||||
| 339 | sigemptyset (&act.sa_mask); | - | ||||||||||||||||||||||||||||||||||||
| 340 | for (i = 0; i < TERMSIGS_LENGTH; i++)
| 26-442 | ||||||||||||||||||||||||||||||||||||
| 341 | { | - | ||||||||||||||||||||||||||||||||||||
| 342 | /* Skip a signal if it's trapped or handled specially, because the | - | ||||||||||||||||||||||||||||||||||||
| 343 | trap code will restore the correct value. */ | - | ||||||||||||||||||||||||||||||||||||
| 344 | if (signal_is_trapped (XSIG (i)) || signal_is_special (XSIG (i)))
| 19-413 | ||||||||||||||||||||||||||||||||||||
| 345 | continue; executed 48 times by 1 test: continue;Executed by:
| 48 | ||||||||||||||||||||||||||||||||||||
| 346 | - | |||||||||||||||||||||||||||||||||||||
| 347 | act.sa_handler = XHANDLER (i); | - | ||||||||||||||||||||||||||||||||||||
| 348 | act.sa_flags = XSAFLAGS (i); | - | ||||||||||||||||||||||||||||||||||||
| 349 | sigaction (XSIG (i), &act, (struct sigaction *) NULL); | - | ||||||||||||||||||||||||||||||||||||
| 350 | } executed 394 times by 1 test: end of blockExecuted by:
| 394 | ||||||||||||||||||||||||||||||||||||
| 351 | #else /* !HAVE_POSIX_SIGNALS */ | - | ||||||||||||||||||||||||||||||||||||
| 352 | for (i = 0; i < TERMSIGS_LENGTH; i++) | - | ||||||||||||||||||||||||||||||||||||
| 353 | { | - | ||||||||||||||||||||||||||||||||||||
| 354 | if (signal_is_trapped (XSIG (i)) || signal_is_special (XSIG (i))) | - | ||||||||||||||||||||||||||||||||||||
| 355 | continue; | - | ||||||||||||||||||||||||||||||||||||
| 356 | - | |||||||||||||||||||||||||||||||||||||
| 357 | signal (XSIG (i), XHANDLER (i)); | - | ||||||||||||||||||||||||||||||||||||
| 358 | } | - | ||||||||||||||||||||||||||||||||||||
| 359 | #endif /* !HAVE_POSIX_SIGNALS */ | - | ||||||||||||||||||||||||||||||||||||
| 360 | - | |||||||||||||||||||||||||||||||||||||
| 361 | termsigs_initialized = 0; | - | ||||||||||||||||||||||||||||||||||||
| 362 | } executed 26 times by 1 test: end of blockExecuted by:
| 26 | ||||||||||||||||||||||||||||||||||||
| 363 | #undef XSIG | - | ||||||||||||||||||||||||||||||||||||
| 364 | #undef XHANDLER | - | ||||||||||||||||||||||||||||||||||||
| 365 | - | |||||||||||||||||||||||||||||||||||||
| 366 | /* Run some of the cleanups that should be performed when we run | - | ||||||||||||||||||||||||||||||||||||
| 367 | jump_to_top_level from a builtin command context. XXX - might want to | - | ||||||||||||||||||||||||||||||||||||
| 368 | also call reset_parser here. */ | - | ||||||||||||||||||||||||||||||||||||
| 369 | void | - | ||||||||||||||||||||||||||||||||||||
| 370 | top_level_cleanup () | - | ||||||||||||||||||||||||||||||||||||
| 371 | { | - | ||||||||||||||||||||||||||||||||||||
| 372 | /* Clean up string parser environment. */ | - | ||||||||||||||||||||||||||||||||||||
| 373 | while (parse_and_execute_level)
| 0-388 | ||||||||||||||||||||||||||||||||||||
| 374 | parse_and_execute_cleanup (); never executed: parse_and_execute_cleanup (); | 0 | ||||||||||||||||||||||||||||||||||||
| 375 | - | |||||||||||||||||||||||||||||||||||||
| 376 | #if defined (PROCESS_SUBSTITUTION) | - | ||||||||||||||||||||||||||||||||||||
| 377 | unlink_fifo_list (); | - | ||||||||||||||||||||||||||||||||||||
| 378 | #endif /* PROCESS_SUBSTITUTION */ | - | ||||||||||||||||||||||||||||||||||||
| 379 | - | |||||||||||||||||||||||||||||||||||||
| 380 | run_unwind_protects (); | - | ||||||||||||||||||||||||||||||||||||
| 381 | loop_level = continuing = breaking = funcnest = 0; | - | ||||||||||||||||||||||||||||||||||||
| 382 | executing_list = comsub_ignore_return = return_catch_flag = wait_intr_flag = 0; | - | ||||||||||||||||||||||||||||||||||||
| 383 | } executed 388 times by 1 test: end of blockExecuted by:
| 388 | ||||||||||||||||||||||||||||||||||||
| 384 | - | |||||||||||||||||||||||||||||||||||||
| 385 | /* What to do when we've been interrupted, and it is safe to handle it. */ | - | ||||||||||||||||||||||||||||||||||||
| 386 | void | - | ||||||||||||||||||||||||||||||||||||
| 387 | throw_to_top_level () | - | ||||||||||||||||||||||||||||||||||||
| 388 | { | - | ||||||||||||||||||||||||||||||||||||
| 389 | int print_newline = 0; | - | ||||||||||||||||||||||||||||||||||||
| 390 | - | |||||||||||||||||||||||||||||||||||||
| 391 | if (interrupt_state)
| 0-1 | ||||||||||||||||||||||||||||||||||||
| 392 | { | - | ||||||||||||||||||||||||||||||||||||
| 393 | if (last_command_exit_value < 128)
| 0 | ||||||||||||||||||||||||||||||||||||
| 394 | last_command_exit_value = 128 + SIGINT; never executed: last_command_exit_value = 128 + 2 ; | 0 | ||||||||||||||||||||||||||||||||||||
| 395 | print_newline = 1; | - | ||||||||||||||||||||||||||||||||||||
| 396 | DELINTERRUPT; | - | ||||||||||||||||||||||||||||||||||||
| 397 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 398 | - | |||||||||||||||||||||||||||||||||||||
| 399 | if (interrupt_state)
| 0-1 | ||||||||||||||||||||||||||||||||||||
| 400 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 401 | - | |||||||||||||||||||||||||||||||||||||
| 402 | last_command_exit_signal = (last_command_exit_value > 128) ?
| 0-1 | ||||||||||||||||||||||||||||||||||||
| 403 | (last_command_exit_value - 128) : 0; | - | ||||||||||||||||||||||||||||||||||||
| 404 | last_command_exit_value |= 128; | - | ||||||||||||||||||||||||||||||||||||
| 405 | - | |||||||||||||||||||||||||||||||||||||
| 406 | /* Run any traps set on SIGINT, mostly for interactive shells */ | - | ||||||||||||||||||||||||||||||||||||
| 407 | if (signal_is_trapped (SIGINT))
| 0-1 | ||||||||||||||||||||||||||||||||||||
| 408 | run_interrupt_trap (1); never executed: run_interrupt_trap (1); | 0 | ||||||||||||||||||||||||||||||||||||
| 409 | - | |||||||||||||||||||||||||||||||||||||
| 410 | /* Clean up string parser environment. */ | - | ||||||||||||||||||||||||||||||||||||
| 411 | while (parse_and_execute_level)
| 0-1 | ||||||||||||||||||||||||||||||||||||
| 412 | parse_and_execute_cleanup (); never executed: parse_and_execute_cleanup (); | 0 | ||||||||||||||||||||||||||||||||||||
| 413 | - | |||||||||||||||||||||||||||||||||||||
| 414 | if (running_trap > 0)
| 0-1 | ||||||||||||||||||||||||||||||||||||
| 415 | run_trap_cleanup (running_trap - 1); never executed: run_trap_cleanup (running_trap - 1); | 0 | ||||||||||||||||||||||||||||||||||||
| 416 | - | |||||||||||||||||||||||||||||||||||||
| 417 | #if defined (JOB_CONTROL) | - | ||||||||||||||||||||||||||||||||||||
| 418 | give_terminal_to (shell_pgrp, 0); | - | ||||||||||||||||||||||||||||||||||||
| 419 | #endif /* JOB_CONTROL */ | - | ||||||||||||||||||||||||||||||||||||
| 420 | - | |||||||||||||||||||||||||||||||||||||
| 421 | #if defined (JOB_CONTROL) || defined (HAVE_POSIX_SIGNALS) | - | ||||||||||||||||||||||||||||||||||||
| 422 | /* This needs to stay because jobs.c:make_child() uses it without resetting | - | ||||||||||||||||||||||||||||||||||||
| 423 | the signal mask. */ | - | ||||||||||||||||||||||||||||||||||||
| 424 | sigprocmask (SIG_SETMASK, &top_level_mask, (sigset_t *)NULL); | - | ||||||||||||||||||||||||||||||||||||
| 425 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 426 | - | |||||||||||||||||||||||||||||||||||||
| 427 | reset_parser (); | - | ||||||||||||||||||||||||||||||||||||
| 428 | - | |||||||||||||||||||||||||||||||||||||
| 429 | #if defined (READLINE) | - | ||||||||||||||||||||||||||||||||||||
| 430 | if (interactive)
| 0-1 | ||||||||||||||||||||||||||||||||||||
| 431 | bashline_reset (); never executed: bashline_reset (); | 0 | ||||||||||||||||||||||||||||||||||||
| 432 | #endif /* READLINE */ | - | ||||||||||||||||||||||||||||||||||||
| 433 | - | |||||||||||||||||||||||||||||||||||||
| 434 | #if defined (PROCESS_SUBSTITUTION) | - | ||||||||||||||||||||||||||||||||||||
| 435 | unlink_fifo_list (); | - | ||||||||||||||||||||||||||||||||||||
| 436 | #endif /* PROCESS_SUBSTITUTION */ | - | ||||||||||||||||||||||||||||||||||||
| 437 | - | |||||||||||||||||||||||||||||||||||||
| 438 | run_unwind_protects (); | - | ||||||||||||||||||||||||||||||||||||
| 439 | loop_level = continuing = breaking = funcnest = 0; | - | ||||||||||||||||||||||||||||||||||||
| 440 | executing_list = comsub_ignore_return = return_catch_flag = wait_intr_flag = 0; | - | ||||||||||||||||||||||||||||||||||||
| 441 | - | |||||||||||||||||||||||||||||||||||||
| 442 | if (interactive && print_newline)
| 0-1 | ||||||||||||||||||||||||||||||||||||
| 443 | { | - | ||||||||||||||||||||||||||||||||||||
| 444 | fflush (stdout); | - | ||||||||||||||||||||||||||||||||||||
| 445 | fprintf (stderr, "\n"); | - | ||||||||||||||||||||||||||||||||||||
| 446 | fflush (stderr); | - | ||||||||||||||||||||||||||||||||||||
| 447 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 448 | - | |||||||||||||||||||||||||||||||||||||
| 449 | /* An interrupted `wait' command in a script does not exit the script. */ | - | ||||||||||||||||||||||||||||||||||||
| 450 | if (interactive || (interactive_shell && !shell_initialized) ||
| 0-1 | ||||||||||||||||||||||||||||||||||||
| 451 | (print_newline && signal_is_trapped (SIGINT)))
| 0-1 | ||||||||||||||||||||||||||||||||||||
| 452 | jump_to_top_level (DISCARD); never executed: jump_to_top_level (2); | 0 | ||||||||||||||||||||||||||||||||||||
| 453 | else | - | ||||||||||||||||||||||||||||||||||||
| 454 | jump_to_top_level (EXITPROG); executed 1 time by 1 test: jump_to_top_level (3);Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 455 | } | - | ||||||||||||||||||||||||||||||||||||
| 456 | - | |||||||||||||||||||||||||||||||||||||
| 457 | /* This is just here to isolate the longjmp calls. */ | - | ||||||||||||||||||||||||||||||||||||
| 458 | void | - | ||||||||||||||||||||||||||||||||||||
| 459 | jump_to_top_level (value) | - | ||||||||||||||||||||||||||||||||||||
| 460 | int value; | - | ||||||||||||||||||||||||||||||||||||
| 461 | { | - | ||||||||||||||||||||||||||||||||||||
| 462 | sh_longjmp (top_level, value); | - | ||||||||||||||||||||||||||||||||||||
| 463 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 464 | - | |||||||||||||||||||||||||||||||||||||
| 465 | sighandler | - | ||||||||||||||||||||||||||||||||||||
| 466 | termsig_sighandler (sig) | - | ||||||||||||||||||||||||||||||||||||
| 467 | int sig; | - | ||||||||||||||||||||||||||||||||||||
| 468 | { | - | ||||||||||||||||||||||||||||||||||||
| 469 | /* If we get called twice with the same signal before handling it, | - | ||||||||||||||||||||||||||||||||||||
| 470 | terminate right away. */ | - | ||||||||||||||||||||||||||||||||||||
| 471 | if ( | - | ||||||||||||||||||||||||||||||||||||
| 472 | #ifdef SIGHUP | - | ||||||||||||||||||||||||||||||||||||
| 473 | sig != SIGHUP &&
| 0 | ||||||||||||||||||||||||||||||||||||
| 474 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 475 | #ifdef SIGINT | - | ||||||||||||||||||||||||||||||||||||
| 476 | sig != SIGINT &&
| 0 | ||||||||||||||||||||||||||||||||||||
| 477 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 478 | #ifdef SIGDANGER | - | ||||||||||||||||||||||||||||||||||||
| 479 | sig != SIGDANGER && | - | ||||||||||||||||||||||||||||||||||||
| 480 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 481 | #ifdef SIGPIPE | - | ||||||||||||||||||||||||||||||||||||
| 482 | sig != SIGPIPE &&
| 0 | ||||||||||||||||||||||||||||||||||||
| 483 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 484 | #ifdef SIGALRM | - | ||||||||||||||||||||||||||||||||||||
| 485 | sig != SIGALRM &&
| 0 | ||||||||||||||||||||||||||||||||||||
| 486 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 487 | #ifdef SIGTERM | - | ||||||||||||||||||||||||||||||||||||
| 488 | sig != SIGTERM &&
| 0 | ||||||||||||||||||||||||||||||||||||
| 489 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 490 | #ifdef SIGXCPU | - | ||||||||||||||||||||||||||||||||||||
| 491 | sig != SIGXCPU &&
| 0 | ||||||||||||||||||||||||||||||||||||
| 492 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 493 | #ifdef SIGXFSZ | - | ||||||||||||||||||||||||||||||||||||
| 494 | sig != SIGXFSZ &&
| 0 | ||||||||||||||||||||||||||||||||||||
| 495 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 496 | #ifdef SIGVTALRM | - | ||||||||||||||||||||||||||||||||||||
| 497 | sig != SIGVTALRM &&
| 0 | ||||||||||||||||||||||||||||||||||||
| 498 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 499 | #ifdef SIGLOST | - | ||||||||||||||||||||||||||||||||||||
| 500 | sig != SIGLOST && | - | ||||||||||||||||||||||||||||||||||||
| 501 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 502 | #ifdef SIGUSR1 | - | ||||||||||||||||||||||||||||||||||||
| 503 | sig != SIGUSR1 &&
| 0 | ||||||||||||||||||||||||||||||||||||
| 504 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 505 | #ifdef SIGUSR2 | - | ||||||||||||||||||||||||||||||||||||
| 506 | sig != SIGUSR2 &&
| 0 | ||||||||||||||||||||||||||||||||||||
| 507 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 508 | sig == terminating_signal)
| 0 | ||||||||||||||||||||||||||||||||||||
| 509 | terminate_immediately = 1; never executed: terminate_immediately = 1; | 0 | ||||||||||||||||||||||||||||||||||||
| 510 | - | |||||||||||||||||||||||||||||||||||||
| 511 | terminating_signal = sig; | - | ||||||||||||||||||||||||||||||||||||
| 512 | - | |||||||||||||||||||||||||||||||||||||
| 513 | /* XXX - should this also trigger when interrupt_immediately is set? */ | - | ||||||||||||||||||||||||||||||||||||
| 514 | if (terminate_immediately)
| 0 | ||||||||||||||||||||||||||||||||||||
| 515 | { | - | ||||||||||||||||||||||||||||||||||||
| 516 | #if defined (HISTORY) | - | ||||||||||||||||||||||||||||||||||||
| 517 | /* XXX - will inhibit history file being written */ | - | ||||||||||||||||||||||||||||||||||||
| 518 | # if defined (READLINE) | - | ||||||||||||||||||||||||||||||||||||
| 519 | if (interactive_shell == 0 || interactive == 0 || (sig != SIGHUP && sig != SIGTERM) || no_line_editing || (RL_ISSTATE (RL_STATE_READCMD) == 0))
| 0 | ||||||||||||||||||||||||||||||||||||
| 520 | # endif | - | ||||||||||||||||||||||||||||||||||||
| 521 | history_lines_this_session = 0; never executed: history_lines_this_session = 0; | 0 | ||||||||||||||||||||||||||||||||||||
| 522 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 523 | terminate_immediately = 0; | - | ||||||||||||||||||||||||||||||||||||
| 524 | termsig_handler (sig); | - | ||||||||||||||||||||||||||||||||||||
| 525 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 526 | - | |||||||||||||||||||||||||||||||||||||
| 527 | #if defined (READLINE) | - | ||||||||||||||||||||||||||||||||||||
| 528 | /* Set the event hook so readline will call it after the signal handlers | - | ||||||||||||||||||||||||||||||||||||
| 529 | finish executing, so if this interrupted character input we can get | - | ||||||||||||||||||||||||||||||||||||
| 530 | quick response. If readline is active or has modified the terminal we | - | ||||||||||||||||||||||||||||||||||||
| 531 | need to set this no matter what the signal is, though the check for | - | ||||||||||||||||||||||||||||||||||||
| 532 | RL_STATE_TERMPREPPED is possibly redundant. */ | - | ||||||||||||||||||||||||||||||||||||
| 533 | if (RL_ISSTATE (RL_STATE_SIGHANDLER) || RL_ISSTATE (RL_STATE_TERMPREPPED))
| 0 | ||||||||||||||||||||||||||||||||||||
| 534 | bashline_set_event_hook (); never executed: bashline_set_event_hook (); | 0 | ||||||||||||||||||||||||||||||||||||
| 535 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 536 | - | |||||||||||||||||||||||||||||||||||||
| 537 | SIGRETURN (0); never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 538 | } | - | ||||||||||||||||||||||||||||||||||||
| 539 | - | |||||||||||||||||||||||||||||||||||||
| 540 | void | - | ||||||||||||||||||||||||||||||||||||
| 541 | termsig_handler (sig) | - | ||||||||||||||||||||||||||||||||||||
| 542 | int sig; | - | ||||||||||||||||||||||||||||||||||||
| 543 | { | - | ||||||||||||||||||||||||||||||||||||
| 544 | static int handling_termsig = 0; | - | ||||||||||||||||||||||||||||||||||||
| 545 | - | |||||||||||||||||||||||||||||||||||||
| 546 | /* Simple semaphore to keep this function from being executed multiple | - | ||||||||||||||||||||||||||||||||||||
| 547 | times. Since we no longer are running as a signal handler, we don't | - | ||||||||||||||||||||||||||||||||||||
| 548 | block multiple occurrences of the terminating signals while running. */ | - | ||||||||||||||||||||||||||||||||||||
| 549 | if (handling_termsig)
| 0 | ||||||||||||||||||||||||||||||||||||
| 550 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 551 | handling_termsig = 1; | - | ||||||||||||||||||||||||||||||||||||
| 552 | terminating_signal = 0; /* keep macro from re-testing true. */ | - | ||||||||||||||||||||||||||||||||||||
| 553 | - | |||||||||||||||||||||||||||||||||||||
| 554 | /* I don't believe this condition ever tests true. */ | - | ||||||||||||||||||||||||||||||||||||
| 555 | if (sig == SIGINT && signal_is_trapped (SIGINT))
| 0 | ||||||||||||||||||||||||||||||||||||
| 556 | run_interrupt_trap (0); never executed: run_interrupt_trap (0); | 0 | ||||||||||||||||||||||||||||||||||||
| 557 | - | |||||||||||||||||||||||||||||||||||||
| 558 | #if defined (HISTORY) | - | ||||||||||||||||||||||||||||||||||||
| 559 | /* If we don't do something like this, the history will not be saved when | - | ||||||||||||||||||||||||||||||||||||
| 560 | an interactive shell is running in a terminal window that gets closed | - | ||||||||||||||||||||||||||||||||||||
| 561 | with the `close' button. We can't test for RL_STATE_READCMD because | - | ||||||||||||||||||||||||||||||||||||
| 562 | readline no longer handles SIGTERM synchronously. */ | - | ||||||||||||||||||||||||||||||||||||
| 563 | if (interactive_shell && interactive && (sig == SIGHUP || sig == SIGTERM) && remember_on_history)
| 0 | ||||||||||||||||||||||||||||||||||||
| 564 | maybe_save_shell_history (); never executed: maybe_save_shell_history (); | 0 | ||||||||||||||||||||||||||||||||||||
| 565 | #endif /* HISTORY */ | - | ||||||||||||||||||||||||||||||||||||
| 566 | - | |||||||||||||||||||||||||||||||||||||
| 567 | if (this_shell_builtin == read_builtin)
| 0 | ||||||||||||||||||||||||||||||||||||
| 568 | read_tty_cleanup (); never executed: read_tty_cleanup (); | 0 | ||||||||||||||||||||||||||||||||||||
| 569 | - | |||||||||||||||||||||||||||||||||||||
| 570 | #if defined (JOB_CONTROL) | - | ||||||||||||||||||||||||||||||||||||
| 571 | if (sig == SIGHUP && (interactive || (subshell_environment & (SUBSHELL_COMSUB|SUBSHELL_PROCSUB))))
| 0 | ||||||||||||||||||||||||||||||||||||
| 572 | hangup_all_jobs (); never executed: hangup_all_jobs (); | 0 | ||||||||||||||||||||||||||||||||||||
| 573 | if ((subshell_environment & (SUBSHELL_COMSUB|SUBSHELL_PROCSUB)) == 0)
| 0 | ||||||||||||||||||||||||||||||||||||
| 574 | end_job_control (); never executed: end_job_control (); | 0 | ||||||||||||||||||||||||||||||||||||
| 575 | #endif /* JOB_CONTROL */ | - | ||||||||||||||||||||||||||||||||||||
| 576 | - | |||||||||||||||||||||||||||||||||||||
| 577 | #if defined (PROCESS_SUBSTITUTION) | - | ||||||||||||||||||||||||||||||||||||
| 578 | unlink_fifo_list (); | - | ||||||||||||||||||||||||||||||||||||
| 579 | #endif /* PROCESS_SUBSTITUTION */ | - | ||||||||||||||||||||||||||||||||||||
| 580 | - | |||||||||||||||||||||||||||||||||||||
| 581 | /* Reset execution context */ | - | ||||||||||||||||||||||||||||||||||||
| 582 | loop_level = continuing = breaking = funcnest = 0; | - | ||||||||||||||||||||||||||||||||||||
| 583 | executing_list = comsub_ignore_return = return_catch_flag = wait_intr_flag = 0; | - | ||||||||||||||||||||||||||||||||||||
| 584 | - | |||||||||||||||||||||||||||||||||||||
| 585 | run_exit_trap (); /* XXX - run exit trap possibly in signal context? */ | - | ||||||||||||||||||||||||||||||||||||
| 586 | set_signal_handler (sig, SIG_DFL); | - | ||||||||||||||||||||||||||||||||||||
| 587 | kill (getpid (), sig); | - | ||||||||||||||||||||||||||||||||||||
| 588 | - | |||||||||||||||||||||||||||||||||||||
| 589 | exit (1); /* just in case the kill fails? */ never executed: exit (1); | 0 | ||||||||||||||||||||||||||||||||||||
| 590 | } | - | ||||||||||||||||||||||||||||||||||||
| 591 | - | |||||||||||||||||||||||||||||||||||||
| 592 | /* What we really do when SIGINT occurs. */ | - | ||||||||||||||||||||||||||||||||||||
| 593 | sighandler | - | ||||||||||||||||||||||||||||||||||||
| 594 | sigint_sighandler (sig) | - | ||||||||||||||||||||||||||||||||||||
| 595 | int sig; | - | ||||||||||||||||||||||||||||||||||||
| 596 | { | - | ||||||||||||||||||||||||||||||||||||
| 597 | #if defined (MUST_REINSTALL_SIGHANDLERS) | - | ||||||||||||||||||||||||||||||||||||
| 598 | signal (sig, sigint_sighandler); | - | ||||||||||||||||||||||||||||||||||||
| 599 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 600 | - | |||||||||||||||||||||||||||||||||||||
| 601 | /* interrupt_state needs to be set for the stack of interrupts to work | - | ||||||||||||||||||||||||||||||||||||
| 602 | right. Should it be set unconditionally? */ | - | ||||||||||||||||||||||||||||||||||||
| 603 | if (interrupt_state == 0)
| 0 | ||||||||||||||||||||||||||||||||||||
| 604 | ADDINTERRUPT; never executed: interrupt_state++; | 0 | ||||||||||||||||||||||||||||||||||||
| 605 | - | |||||||||||||||||||||||||||||||||||||
| 606 | /* We will get here in interactive shells with job control active; allow | - | ||||||||||||||||||||||||||||||||||||
| 607 | an interactive wait to be interrupted. wait_intr_flag is only set during | - | ||||||||||||||||||||||||||||||||||||
| 608 | the execution of the wait builtin and when wait_intr_buf is valid. */ | - | ||||||||||||||||||||||||||||||||||||
| 609 | if (wait_intr_flag)
| 0 | ||||||||||||||||||||||||||||||||||||
| 610 | { | - | ||||||||||||||||||||||||||||||||||||
| 611 | last_command_exit_value = 128 + sig; | - | ||||||||||||||||||||||||||||||||||||
| 612 | wait_signal_received = sig; | - | ||||||||||||||||||||||||||||||||||||
| 613 | SIGRETURN (0); never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 614 | } | - | ||||||||||||||||||||||||||||||||||||
| 615 | - | |||||||||||||||||||||||||||||||||||||
| 616 | if (interrupt_immediately)
| 0 | ||||||||||||||||||||||||||||||||||||
| 617 | { | - | ||||||||||||||||||||||||||||||||||||
| 618 | interrupt_immediately = 0; | - | ||||||||||||||||||||||||||||||||||||
| 619 | last_command_exit_value = 128 + sig; | - | ||||||||||||||||||||||||||||||||||||
| 620 | throw_to_top_level (); | - | ||||||||||||||||||||||||||||||||||||
| 621 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 622 | #if defined (READLINE) | - | ||||||||||||||||||||||||||||||||||||
| 623 | /* Set the event hook so readline will call it after the signal handlers | - | ||||||||||||||||||||||||||||||||||||
| 624 | finish executing, so if this interrupted character input we can get | - | ||||||||||||||||||||||||||||||||||||
| 625 | quick response. */ | - | ||||||||||||||||||||||||||||||||||||
| 626 | else if (RL_ISSTATE (RL_STATE_SIGHANDLER))
| 0 | ||||||||||||||||||||||||||||||||||||
| 627 | bashline_set_event_hook (); never executed: bashline_set_event_hook (); | 0 | ||||||||||||||||||||||||||||||||||||
| 628 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 629 | - | |||||||||||||||||||||||||||||||||||||
| 630 | SIGRETURN (0); never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 631 | } | - | ||||||||||||||||||||||||||||||||||||
| 632 | - | |||||||||||||||||||||||||||||||||||||
| 633 | #if defined (SIGWINCH) | - | ||||||||||||||||||||||||||||||||||||
| 634 | sighandler | - | ||||||||||||||||||||||||||||||||||||
| 635 | sigwinch_sighandler (sig) | - | ||||||||||||||||||||||||||||||||||||
| 636 | int sig; | - | ||||||||||||||||||||||||||||||||||||
| 637 | { | - | ||||||||||||||||||||||||||||||||||||
| 638 | #if defined (MUST_REINSTALL_SIGHANDLERS) | - | ||||||||||||||||||||||||||||||||||||
| 639 | set_signal_handler (SIGWINCH, sigwinch_sighandler); | - | ||||||||||||||||||||||||||||||||||||
| 640 | #endif /* MUST_REINSTALL_SIGHANDLERS */ | - | ||||||||||||||||||||||||||||||||||||
| 641 | sigwinch_received = 1; | - | ||||||||||||||||||||||||||||||||||||
| 642 | SIGRETURN (0); never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 643 | } | - | ||||||||||||||||||||||||||||||||||||
| 644 | #endif /* SIGWINCH */ | - | ||||||||||||||||||||||||||||||||||||
| 645 | - | |||||||||||||||||||||||||||||||||||||
| 646 | void | - | ||||||||||||||||||||||||||||||||||||
| 647 | set_sigwinch_handler () | - | ||||||||||||||||||||||||||||||||||||
| 648 | { | - | ||||||||||||||||||||||||||||||||||||
| 649 | #if defined (SIGWINCH) | - | ||||||||||||||||||||||||||||||||||||
| 650 | old_winch = set_signal_handler (SIGWINCH, sigwinch_sighandler); | - | ||||||||||||||||||||||||||||||||||||
| 651 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 652 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||||||||||||||
| 653 | - | |||||||||||||||||||||||||||||||||||||
| 654 | void | - | ||||||||||||||||||||||||||||||||||||
| 655 | unset_sigwinch_handler () | - | ||||||||||||||||||||||||||||||||||||
| 656 | { | - | ||||||||||||||||||||||||||||||||||||
| 657 | #if defined (SIGWINCH) | - | ||||||||||||||||||||||||||||||||||||
| 658 | set_signal_handler (SIGWINCH, old_winch); | - | ||||||||||||||||||||||||||||||||||||
| 659 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 660 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 661 | - | |||||||||||||||||||||||||||||||||||||
| 662 | sighandler | - | ||||||||||||||||||||||||||||||||||||
| 663 | sigterm_sighandler (sig) | - | ||||||||||||||||||||||||||||||||||||
| 664 | int sig; | - | ||||||||||||||||||||||||||||||||||||
| 665 | { | - | ||||||||||||||||||||||||||||||||||||
| 666 | sigterm_received = 1; /* XXX - counter? */ | - | ||||||||||||||||||||||||||||||||||||
| 667 | SIGRETURN (0); never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 668 | } | - | ||||||||||||||||||||||||||||||||||||
| 669 | - | |||||||||||||||||||||||||||||||||||||
| 670 | /* Signal functions used by the rest of the code. */ | - | ||||||||||||||||||||||||||||||||||||
| 671 | #if !defined (HAVE_POSIX_SIGNALS) | - | ||||||||||||||||||||||||||||||||||||
| 672 | - | |||||||||||||||||||||||||||||||||||||
| 673 | /* Perform OPERATION on NEWSET, perhaps leaving information in OLDSET. */ | - | ||||||||||||||||||||||||||||||||||||
| 674 | sigprocmask (operation, newset, oldset) | - | ||||||||||||||||||||||||||||||||||||
| 675 | int operation, *newset, *oldset; | - | ||||||||||||||||||||||||||||||||||||
| 676 | { | - | ||||||||||||||||||||||||||||||||||||
| 677 | int old, new; | - | ||||||||||||||||||||||||||||||||||||
| 678 | - | |||||||||||||||||||||||||||||||||||||
| 679 | if (newset) | - | ||||||||||||||||||||||||||||||||||||
| 680 | new = *newset; | - | ||||||||||||||||||||||||||||||||||||
| 681 | else | - | ||||||||||||||||||||||||||||||||||||
| 682 | new = 0; | - | ||||||||||||||||||||||||||||||||||||
| 683 | - | |||||||||||||||||||||||||||||||||||||
| 684 | switch (operation) | - | ||||||||||||||||||||||||||||||||||||
| 685 | { | - | ||||||||||||||||||||||||||||||||||||
| 686 | case SIG_BLOCK: | - | ||||||||||||||||||||||||||||||||||||
| 687 | old = sigblock (new); | - | ||||||||||||||||||||||||||||||||||||
| 688 | break; | - | ||||||||||||||||||||||||||||||||||||
| 689 | - | |||||||||||||||||||||||||||||||||||||
| 690 | case SIG_SETMASK: | - | ||||||||||||||||||||||||||||||||||||
| 691 | old = sigsetmask (new); | - | ||||||||||||||||||||||||||||||||||||
| 692 | break; | - | ||||||||||||||||||||||||||||||||||||
| 693 | - | |||||||||||||||||||||||||||||||||||||
| 694 | default: | - | ||||||||||||||||||||||||||||||||||||
| 695 | internal_error (_("sigprocmask: %d: invalid operation"), operation); | - | ||||||||||||||||||||||||||||||||||||
| 696 | } | - | ||||||||||||||||||||||||||||||||||||
| 697 | - | |||||||||||||||||||||||||||||||||||||
| 698 | if (oldset) | - | ||||||||||||||||||||||||||||||||||||
| 699 | *oldset = old; | - | ||||||||||||||||||||||||||||||||||||
| 700 | } | - | ||||||||||||||||||||||||||||||||||||
| 701 | - | |||||||||||||||||||||||||||||||||||||
| 702 | #else | - | ||||||||||||||||||||||||||||||||||||
| 703 | - | |||||||||||||||||||||||||||||||||||||
| 704 | #if !defined (SA_INTERRUPT) | - | ||||||||||||||||||||||||||||||||||||
| 705 | # define SA_INTERRUPT 0 | - | ||||||||||||||||||||||||||||||||||||
| 706 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 707 | - | |||||||||||||||||||||||||||||||||||||
| 708 | #if !defined (SA_RESTART) | - | ||||||||||||||||||||||||||||||||||||
| 709 | # define SA_RESTART 0 | - | ||||||||||||||||||||||||||||||||||||
| 710 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 711 | - | |||||||||||||||||||||||||||||||||||||
| 712 | SigHandler * | - | ||||||||||||||||||||||||||||||||||||
| 713 | set_signal_handler (sig, handler) | - | ||||||||||||||||||||||||||||||||||||
| 714 | int sig; | - | ||||||||||||||||||||||||||||||||||||
| 715 | SigHandler *handler; | - | ||||||||||||||||||||||||||||||||||||
| 716 | { | - | ||||||||||||||||||||||||||||||||||||
| 717 | struct sigaction act, oact; | - | ||||||||||||||||||||||||||||||||||||
| 718 | - | |||||||||||||||||||||||||||||||||||||
| 719 | act.sa_handler = handler; | - | ||||||||||||||||||||||||||||||||||||
| 720 | act.sa_flags = 0; | - | ||||||||||||||||||||||||||||||||||||
| 721 | - | |||||||||||||||||||||||||||||||||||||
| 722 | /* XXX - bash-4.2 */ | - | ||||||||||||||||||||||||||||||||||||
| 723 | /* We don't want a child death to interrupt interruptible system calls, even | - | ||||||||||||||||||||||||||||||||||||
| 724 | if we take the time to reap children */ | - | ||||||||||||||||||||||||||||||||||||
| 725 | #if defined (SIGCHLD) | - | ||||||||||||||||||||||||||||||||||||
| 726 | if (sig == SIGCHLD)
| 3960800-6696639 | ||||||||||||||||||||||||||||||||||||
| 727 | act.sa_flags |= SA_RESTART; /* XXX */ executed 3960800 times by 1 test: act.sa_flags |= 0x10000000 ;Executed by:
| 3960800 | ||||||||||||||||||||||||||||||||||||
| 728 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 729 | /* XXX - bash-5.0 */ | - | ||||||||||||||||||||||||||||||||||||
| 730 | /* Let's see if we can keep SIGWINCH from interrupting interruptible system | - | ||||||||||||||||||||||||||||||||||||
| 731 | calls, like open(2)/read(2)/write(2) */ | - | ||||||||||||||||||||||||||||||||||||
| 732 | #if defined (SIGWINCH) | - | ||||||||||||||||||||||||||||||||||||
| 733 | if (sig == SIGWINCH)
| 24-10657415 | ||||||||||||||||||||||||||||||||||||
| 734 | act.sa_flags |= SA_RESTART; /* XXX */ executed 24 times by 1 test: act.sa_flags |= 0x10000000 ;Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||
| 735 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 736 | /* If we're installing a SIGTERM handler for interactive shells, we want | - | ||||||||||||||||||||||||||||||||||||
| 737 | it to be as close to SIG_IGN as possible. */ | - | ||||||||||||||||||||||||||||||||||||
| 738 | if (sig == SIGTERM && handler == sigterm_sighandler)
| 2-10657372 | ||||||||||||||||||||||||||||||||||||
| 739 | act.sa_flags |= SA_RESTART; /* XXX */ executed 2 times by 1 test: act.sa_flags |= 0x10000000 ;Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||
| 740 | - | |||||||||||||||||||||||||||||||||||||
| 741 | sigemptyset (&act.sa_mask); | - | ||||||||||||||||||||||||||||||||||||
| 742 | sigemptyset (&oact.sa_mask); | - | ||||||||||||||||||||||||||||||||||||
| 743 | if (sigaction (sig, &act, &oact) == 0)
| 88-10657351 | ||||||||||||||||||||||||||||||||||||
| 744 | return (oact.sa_handler); executed 10657351 times by 1 test: return (oact. __sigaction_handler.sa_handler );Executed by:
| 10657351 | ||||||||||||||||||||||||||||||||||||
| 745 | else | - | ||||||||||||||||||||||||||||||||||||
| 746 | return (SIG_DFL); executed 88 times by 1 test: return ( ((__sighandler_t) 0) );Executed by:
| 88 | ||||||||||||||||||||||||||||||||||||
| 747 | } | - | ||||||||||||||||||||||||||||||||||||
| 748 | #endif /* HAVE_POSIX_SIGNALS */ | - | ||||||||||||||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |