OpenCoverage

trap.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/trap.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* trap.c -- Not the trap command, but useful functions for manipulating-
2 those objects. The trap command is in builtins/trap.def. */-
3-
4/* Copyright (C) 1987-2015 Free Software Foundation, Inc.-
5-
6 This file is part of GNU Bash, the Bourne Again SHell.-
7-
8 Bash is free software: you can redistribute it and/or modify-
9 it under the terms of the GNU General Public License as published by-
10 the Free Software Foundation, either version 3 of the License, or-
11 (at your option) any later version.-
12-
13 Bash is distributed in the hope that it will be useful,-
14 but WITHOUT ANY WARRANTY; without even the implied warranty of-
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
16 GNU General Public License for more details.-
17-
18 You should have received a copy of the GNU General Public License-
19 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
20*/-
21-
22#include "config.h"-
23-
24#if defined (HAVE_UNISTD_H)-
25# include <unistd.h>-
26#endif-
27-
28#include "bashtypes.h"-
29#include "bashansi.h"-
30-
31#include <stdio.h>-
32#include <errno.h>-
33-
34#include "bashintl.h"-
35-
36#include <signal.h>-
37-
38#include "trap.h"-
39-
40#include "shell.h"-
41#include "execute_cmd.h"-
42#include "flags.h"-
43#include "parser.h"-
44#include "input.h" /* for save_token_state, restore_token_state */-
45#include "jobs.h"-
46#include "signames.h"-
47#include "builtins.h"-
48#include "builtins/common.h"-
49#include "builtins/builtext.h"-
50-
51#if defined (READLINE)-
52# include <readline/readline.h>-
53# include "bashline.h"-
54#endif-
55-
56#ifndef errno-
57extern int errno;-
58#endif-
59-
60/* Flags which describe the current handling state of a signal. */-
61#define SIG_INHERITED 0x0 /* Value inherited from parent. */-
62#define SIG_TRAPPED 0x1 /* Currently trapped. */-
63#define SIG_HARD_IGNORE 0x2 /* Signal was ignored on shell entry. */-
64#define SIG_SPECIAL 0x4 /* Treat this signal specially. */-
65#define SIG_NO_TRAP 0x8 /* Signal cannot be trapped. */-
66#define SIG_INPROGRESS 0x10 /* Signal handler currently executing. */-
67#define SIG_CHANGED 0x20 /* Trap value changed in trap handler. */-
68#define SIG_IGNORED 0x40 /* The signal is currently being ignored. */-
69-
70#define SPECIAL_TRAP(s) ((s) == EXIT_TRAP || (s) == DEBUG_TRAP || (s) == ERROR_TRAP || (s) == RETURN_TRAP)-
71-
72/* An array of such flags, one for each signal, describing what the-
73 shell will do with a signal. DEBUG_TRAP == NSIG; some code below-
74 assumes this. */-
75static int sigmodes[BASH_NSIG];-
76-
77static void free_trap_command (int);-
78static void change_signal (int, char *);-
79-
80static int _run_trap_internal (int, char *);-
81-
82static void free_trap_string (int);-
83static void reset_signal (int);-
84static void restore_signal (int);-
85static void reset_or_restore_signal_handlers (sh_resetsig_func_t *);-
86-
87static void trap_if_untrapped (int, char *);-
88-
89/* Variables used here but defined in other files. */-
90extern procenv_t alrmbuf;-
91-
92extern volatile int from_return_trap;-
93-
94extern WORD_LIST *subst_assign_varlist;-
95-
96/* The list of things to do originally, before we started trapping. */-
97SigHandler *original_signals[NSIG];-
98-
99/* For each signal, a slot for a string, which is a command to be-
100 executed when that signal is received. The slot can also contain-
101 DEFAULT_SIG, which means do whatever you were going to do before-
102 you were so rudely interrupted, or IGNORE_SIG, which says ignore-
103 this signal. */-
104char *trap_list[BASH_NSIG];-
105-
106/* A bitmap of signals received for which we have trap handlers. */-
107int pending_traps[NSIG];-
108-
109/* Set to the number of the signal we're running the trap for + 1.-
110 Used in execute_cmd.c and builtins/common.c to clean up when-
111 parse_and_execute does not return normally after executing the-
112 trap command (e.g., when `return' is executed in the trap command). */-
113int running_trap;-
114-
115/* Set to last_command_exit_value before running a trap. */-
116int trap_saved_exit_value;-
117-
118/* The (trapped) signal received while executing in the `wait' builtin */-
119int wait_signal_received;-
120-
121int trapped_signal_received;-
122-
123#define GETORIGSIG(sig) \-
124 do { \-
125 original_signals[sig] = (SigHandler *)set_signal_handler (sig, SIG_DFL); \-
126 set_signal_handler (sig, original_signals[sig]); \-
127 if (original_signals[sig] == SIG_IGN) \-
128 sigmodes[sig] |= SIG_HARD_IGNORE; \-
129 } while (0)-
130-
131#define SETORIGSIG(sig,handler) \-
132 do { \-
133 original_signals[sig] = handler; \-
134 if (original_signals[sig] == SIG_IGN) \-
135 sigmodes[sig] |= SIG_HARD_IGNORE; \-
136 } while (0)-
137-
138#define GET_ORIGINAL_SIGNAL(sig) \-
139 if (sig && sig < NSIG && original_signals[sig] == IMPOSSIBLE_TRAP_HANDLER) \-
140 GETORIGSIG(sig)-
141-
142void-
143initialize_traps ()-
144{-
145 register int i;-
146-
147 initialize_signames();-
148-
149 trap_list[EXIT_TRAP] = trap_list[DEBUG_TRAP] = trap_list[ERROR_TRAP] = trap_list[RETURN_TRAP] = (char *)NULL;-
150 sigmodes[EXIT_TRAP] = sigmodes[DEBUG_TRAP] = sigmodes[ERROR_TRAP] = sigmodes[RETURN_TRAP] = SIG_INHERITED;-
151 original_signals[EXIT_TRAP] = IMPOSSIBLE_TRAP_HANDLER;-
152-
153 for (i = 1; i < NSIG; i++)
i < 65Description
TRUEevaluated 348672 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5448 times by 1 test
Evaluated by:
  • Self test
5448-348672
154 {-
155 pending_traps[i] = 0;-
156 trap_list[i] = (char *)DEFAULT_SIG;-
157 sigmodes[i] = SIG_INHERITED; /* XXX - only set, not used */-
158 original_signals[i] = IMPOSSIBLE_TRAP_HANDLER;-
159 }
executed 348672 times by 1 test: end of block
Executed by:
  • Self test
348672
160-
161 /* Show which signals are treated specially by the shell. */-
162#if defined (SIGCHLD)-
163 GETORIGSIG (SIGCHLD);
never executed: sigmodes[ 17 ] |= 0x2;
original_signa...ghandler_t) 1)Description
TRUEnever evaluated
FALSEevaluated 5448 times by 1 test
Evaluated by:
  • Self test
0-5448
164 sigmodes[SIGCHLD] |= (SIG_SPECIAL | SIG_NO_TRAP);-
165#endif /* SIGCHLD */-
166-
167 GETORIGSIG (SIGINT);
executed 5 times by 1 test: sigmodes[ 2 ] |= 0x2;
Executed by:
  • Self test
original_signa...ghandler_t) 1)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5443 times by 1 test
Evaluated by:
  • Self test
5-5443
168 sigmodes[SIGINT] |= SIG_SPECIAL;-
169-
170#if defined (__BEOS__)-
171 /* BeOS sets SIGINT to SIG_IGN! */-
172 original_signals[SIGINT] = SIG_DFL;-
173 sigmodes[SIGINT] &= ~SIG_HARD_IGNORE;-
174#endif-
175-
176 GETORIGSIG (SIGQUIT);
executed 1 time by 1 test: sigmodes[ 3 ] |= 0x2;
Executed by:
  • Self test
original_signa...ghandler_t) 1)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5447 times by 1 test
Evaluated by:
  • Self test
1-5447
177 sigmodes[SIGQUIT] |= SIG_SPECIAL;-
178-
179 if (interactive)
interactiveDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5446 times by 1 test
Evaluated by:
  • Self test
2-5446
180 {-
181 GETORIGSIG (SIGTERM);
never executed: sigmodes[ 15 ] |= 0x2;
original_signa...ghandler_t) 1)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
182 sigmodes[SIGTERM] |= SIG_SPECIAL;-
183 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
184-
185 get_original_tty_job_signals ();-
186}
executed 5448 times by 1 test: end of block
Executed by:
  • Self test
5448
187-
188#ifdef DEBUG-
189/* Return a printable representation of the trap handler for SIG. */-
190static char *-
191trap_handler_string (sig)-
192 int sig;-
193{-
194 if (trap_list[sig] == (char *)DEFAULT_SIG)
trap_list[sig]...ghandler_t) 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
195 return "DEFAULT_SIG";
never executed: return "DEFAULT_SIG";
0
196 else if (trap_list[sig] == (char *)IGNORE_SIG)
trap_list[sig]...ghandler_t) 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
197 return "IGNORE_SIG";
never executed: return "IGNORE_SIG";
0
198 else if (trap_list[sig] == (char *)IMPOSSIBLE_TRAP_HANDLER)
trap_list[sig]...itialize_trapsDescription
TRUEnever evaluated
FALSEnever evaluated
0
199 return "IMPOSSIBLE_TRAP_HANDLER";
never executed: return "IMPOSSIBLE_TRAP_HANDLER";
0
200 else if (trap_list[sig])
trap_list[sig]Description
TRUEnever evaluated
FALSEnever evaluated
0
201 return trap_list[sig];
never executed: return trap_list[sig];
0
202 else-
203 return "NULL";
never executed: return "NULL";
0
204}-
205#endif-
206-
207/* Return the print name of this signal. */-
208char *-
209signal_name (sig)-
210 int sig;-
211{-
212 char *ret;-
213-
214 /* on cygwin32, signal_names[sig] could be null */-
215 ret = (sig >= BASH_NSIG || sig < 0 || signal_names[sig] == NULL)
sig >= 65 +3Description
TRUEnever evaluated
FALSEevaluated 409 times by 1 test
Evaluated by:
  • Self test
sig < 0Description
TRUEnever evaluated
FALSEevaluated 409 times by 1 test
Evaluated by:
  • Self test
signal_names[s...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 409 times by 1 test
Evaluated by:
  • Self test
0-409
216 ? _("invalid signal number")-
217 : signal_names[sig];-
218-
219 return ret;
executed 409 times by 1 test: return ret;
Executed by:
  • Self test
409
220}-
221-
222/* Turn a string into a signal number, or a number into-
223 a signal number. If STRING is "2", "SIGINT", or "INT",-
224 then (int)2 is returned. Return NO_SIG if STRING doesn't-
225 contain a valid signal descriptor. */-
226int-
227decode_signal (string, flags)-
228 char *string;-
229 int flags;-
230{-
231 intmax_t sig;-
232 char *name;-
233-
234 if (legal_number (string, &sig))
legal_number (string, &sig)Description
TRUEevaluated 131 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 319 times by 1 test
Evaluated by:
  • Self test
131-319
235 return ((sig >= 0 && sig < NSIG) ? (int)sig : NO_SIG);
executed 131 times by 1 test: return ((sig >= 0 && sig < 65 ) ? (int)sig : -1);
Executed by:
  • Self test
131
236-
237 /* A leading `SIG' may be omitted. */-
238 for (sig = 0; sig < BASH_NSIG; sig++)
sig < 65 +3Description
TRUEevaluated 15988 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 154 times by 1 test
Evaluated by:
  • Self test
154-15988
239 {-
240 name = signal_names[sig];-
241 if (name == 0 || name[0] == '\0')
name == 0Description
TRUEnever evaluated
FALSEevaluated 15988 times by 1 test
Evaluated by:
  • Self test
name[0] == '\0'Description
TRUEnever evaluated
FALSEevaluated 15988 times by 1 test
Evaluated by:
  • Self test
0-15988
242 continue;
never executed: continue;
0
243-
244 /* Check name without the SIG prefix first case sensitively or-
245 insensitively depending on whether flags includes DSIG_NOCASE */-
246 if (STREQN (name, "SIG", 3))
never executed: __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "SIG" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
((3 == 0) ? (1..., 3 ))) == 0))Description
TRUEevaluated 15088 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 900 times by 1 test
Evaluated by:
  • Self test
(3 == 0)Description
TRUEnever evaluated
FALSEevaluated 15988 times by 1 test
Evaluated by:
  • Self test
(name)[0] == ("SIG")[0]Description
TRUEevaluated 15088 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 900 times by 1 test
Evaluated by:
  • Self test
(__extension__..." , 3 ))) == 0Description
TRUEevaluated 15088 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
__builtin_constant_p ( 3 )Description
TRUEevaluated 15088 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
__builtin_constant_p ( name )Description
TRUEnever evaluated
FALSEevaluated 15088 times by 1 test
Evaluated by:
  • Self test
strlen ( name ...size_t) ( 3 ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( "SIG" )Description
TRUEevaluated 15088 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
strlen ( "SIG"...size_t) ( 3 ))Description
TRUEnever evaluated
FALSEevaluated 15088 times by 1 test
Evaluated by:
  • Self test
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-15988
247 {-
248 name += 3;-
249-
250 if ((flags & DSIG_NOCASE) && strcasecmp (string, name) == 0)
(flags & 0x02)Description
TRUEevaluated 15088 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
strcasecmp (string, name) == 0Description
TRUEevaluated 59 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15029 times by 1 test
Evaluated by:
  • Self test
0-15088
251 return ((int)sig);
executed 59 times by 1 test: return ((int)sig);
Executed by:
  • Self test
59
252 else if ((flags & DSIG_NOCASE) == 0 && strcmp (string, name) == 0)
never executed: __result = (((const unsigned char *) (const char *) ( string ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(flags & 0x02) == 0Description
TRUEnever evaluated
FALSEevaluated 15029 times by 1 test
Evaluated by:
  • Self test
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-15029
253 return ((int)sig);
never executed: return ((int)sig);
0
254 /* If we can't use the `SIG' prefix to match, punt on this-
255 name now. */-
256 else if ((flags & DSIG_SIGPREFIX) == 0)
(flags & 0x01) == 0Description
TRUEnever evaluated
FALSEevaluated 15029 times by 1 test
Evaluated by:
  • Self test
0-15029
257 continue;
never executed: continue;
0
258 }
executed 15029 times by 1 test: end of block
Executed by:
  • Self test
15029
259-
260 /* Check name with SIG prefix case sensitively or insensitively-
261 depending on whether flags includes DSIG_NOCASE */-
262 name = signal_names[sig];-
263 if ((flags & DSIG_NOCASE) && strcasecmp (string, name) == 0)
(flags & 0x02)Description
TRUEevaluated 15929 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
strcasecmp (string, name) == 0Description
TRUEevaluated 106 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15823 times by 1 test
Evaluated by:
  • Self test
0-15929
264 return ((int)sig);
executed 106 times by 1 test: return ((int)sig);
Executed by:
  • Self test
106
265 else if ((flags & DSIG_NOCASE) == 0 && strcmp (string, name) == 0)
never executed: __result = (((const unsigned char *) (const char *) ( string ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(flags & 0x02) == 0Description
TRUEnever evaluated
FALSEevaluated 15823 times by 1 test
Evaluated by:
  • Self test
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-15823
266 return ((int)sig);
never executed: return ((int)sig);
0
267 }
executed 15823 times by 1 test: end of block
Executed by:
  • Self test
15823
268-
269 return (NO_SIG);
executed 154 times by 1 test: return (-1);
Executed by:
  • Self test
154
270}-
271-
272/* Non-zero when we catch a trapped signal. */-
273static int catch_flag;-
274-
275void-
276run_pending_traps ()-
277{-
278 register int sig;-
279 int old_exit_value, x;-
280 WORD_LIST *save_subst_varlist;-
281 HASH_TABLE *save_tempenv;-
282 sh_parser_state_t pstate;-
283#if defined (ARRAY_VARS)-
284 ARRAY *ps;-
285#endif-
286-
287 if (catch_flag == 0) /* simple optimization */
catch_flag == 0Description
TRUEevaluated 356491293 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-356491293
288 return;
executed 356491293 times by 1 test: return;
Executed by:
  • Self test
356491293
289-
290 if (running_trap > 0)
running_trap > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
291 {-
292#if defined (DEBUG)-
293 internal_warning ("run_pending_traps: recursive invocation while running trap for signal %d", running_trap-1);-
294#endif-
295#if defined (SIGWINCH)-
296 if (running_trap == SIGWINCH+1 && pending_traps[SIGWINCH])
running_trap == 28 +1Description
TRUEnever evaluated
FALSEnever evaluated
pending_traps[ 28 ]Description
TRUEnever evaluated
FALSEnever evaluated
0
297 return; /* no recursive SIGWINCH trap invocations */
never executed: return;
0
298#else-
299 ;-
300#endif-
301 }
never executed: end of block
0
302-
303 catch_flag = trapped_signal_received = 0;-
304-
305 /* Preserve $? when running trap. */-
306 trap_saved_exit_value = old_exit_value = last_command_exit_value;-
307#if defined (ARRAY_VARS)-
308 ps = save_pipestatus_array ();-
309#endif-
310-
311 for (sig = 1; sig < NSIG; sig++)
sig < 65Description
TRUEnever evaluated
FALSEnever evaluated
0
312 {-
313 /* XXX this could be made into a counter by using-
314 while (pending_traps[sig]--) instead of the if statement. */-
315 if (pending_traps[sig])
pending_traps[sig]Description
TRUEnever evaluated
FALSEnever evaluated
0
316 {-
317 if (running_trap == sig+1)
running_trap == sig+1Description
TRUEnever evaluated
FALSEnever evaluated
0
318 /*continue*/;
never executed: ;
0
319-
320 running_trap = sig + 1;-
321-
322 if (sig == SIGINT)
sig == 2Description
TRUEnever evaluated
FALSEnever evaluated
0
323 {-
324 pending_traps[sig] = 0; /* XXX */-
325 run_interrupt_trap (0);-
326 CLRINTERRUPT;-
327 }
never executed: end of block
0
328#if defined (JOB_CONTROL) && defined (SIGCHLD)-
329 else if (sig == SIGCHLD &&
sig == 17Description
TRUEnever evaluated
FALSEnever evaluated
0
330 trap_list[SIGCHLD] != (char *)IMPOSSIBLE_TRAP_HANDLER &&
trap_list[ 17 ...itialize_trapsDescription
TRUEnever evaluated
FALSEnever evaluated
0
331 (sigmodes[SIGCHLD] & SIG_INPROGRESS) == 0)
(sigmodes[ 17 ] & 0x10) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
332 {-
333 sigmodes[SIGCHLD] |= SIG_INPROGRESS;-
334 x = pending_traps[sig];-
335 pending_traps[sig] = 0;-
336 run_sigchld_trap (x); /* use as counter */-
337 running_trap = 0;-
338 sigmodes[SIGCHLD] &= ~SIG_INPROGRESS;-
339 /* continue here rather than reset pending_traps[SIGCHLD] below in-
340 case there are recursive calls to run_pending_traps and children-
341 have been reaped while run_sigchld_trap was running. */-
342 continue;
never executed: continue;
0
343 }-
344 else if (sig == SIGCHLD &&
sig == 17Description
TRUEnever evaluated
FALSEnever evaluated
0
345 trap_list[SIGCHLD] == (char *)IMPOSSIBLE_TRAP_HANDLER &&
trap_list[ 17 ...itialize_trapsDescription
TRUEnever evaluated
FALSEnever evaluated
0
346 (sigmodes[SIGCHLD] & SIG_INPROGRESS) != 0)
(sigmodes[ 17 ] & 0x10) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
347 {-
348 /* This can happen when run_pending_traps is called while-
349 running a SIGCHLD trap handler. */-
350 running_trap = 0;-
351 /* want to leave pending_traps[SIGCHLD] alone here */-
352 continue; /* XXX */
never executed: continue;
0
353 }-
354 else if (sig == SIGCHLD && (sigmodes[SIGCHLD] & SIG_INPROGRESS))
sig == 17Description
TRUEnever evaluated
FALSEnever evaluated
(sigmodes[ 17 ] & 0x10)Description
TRUEnever evaluated
FALSEnever evaluated
0
355 {-
356 /* whoops -- print warning? */-
357 running_trap = 0; /* XXX */-
358 /* want to leave pending_traps[SIGCHLD] alone here */-
359 continue;
never executed: continue;
0
360 }-
361#endif-
362 else if (trap_list[sig] == (char *)DEFAULT_SIG ||
trap_list[sig]...ghandler_t) 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
363 trap_list[sig] == (char *)IGNORE_SIG ||
trap_list[sig]...ghandler_t) 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
364 trap_list[sig] == (char *)IMPOSSIBLE_TRAP_HANDLER)
trap_list[sig]...itialize_trapsDescription
TRUEnever evaluated
FALSEnever evaluated
0
365 {-
366 /* This is possible due to a race condition. Say a bash-
367 process has SIGTERM trapped. A subshell is spawned-
368 using { list; } & and the parent does something and kills-
369 the subshell with SIGTERM. It's possible for the subshell-
370 to set pending_traps[SIGTERM] to 1 before the code in-
371 execute_cmd.c eventually calls restore_original_signals-
372 to reset the SIGTERM signal handler in the subshell. The-
373 next time run_pending_traps is called, pending_traps[SIGTERM]-
374 will be 1, but the trap handler in trap_list[SIGTERM] will-
375 be invalid (probably DEFAULT_SIG, but it could be IGNORE_SIG).-
376 Unless we catch this, the subshell will dump core when-
377 trap_list[SIGTERM] == DEFAULT_SIG, because DEFAULT_SIG is-
378 usually 0x0. */-
379 internal_warning (_("run_pending_traps: bad value in trap_list[%d]: %p"),-
380 sig, trap_list[sig]);-
381 if (trap_list[sig] == (char *)DEFAULT_SIG)
trap_list[sig]...ghandler_t) 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
382 {-
383 internal_warning (_("run_pending_traps: signal handler is SIG_DFL, resending %d (%s) to myself"), sig, signal_name (sig));-
384 kill (getpid (), sig);-
385 }
never executed: end of block
0
386 }
never executed: end of block
0
387 else-
388 {-
389 /* XXX - should we use save_parser_state/restore_parser_state? */-
390 save_parser_state (&pstate);-
391 save_subst_varlist = subst_assign_varlist;-
392 subst_assign_varlist = 0;-
393 save_tempenv = temporary_env;-
394 temporary_env = 0; /* traps should not run with temporary env */-
395-
396#if defined (JOB_CONTROL)-
397 save_pipeline (1); /* XXX only provides one save level */-
398#endif-
399 /* XXX - set pending_traps[sig] = 0 here? */-
400 pending_traps[sig] = 0;-
401 evalstring (savestring (trap_list[sig]), "trap", SEVAL_NONINT|SEVAL_NOHIST|SEVAL_RESETLINE);-
402#if defined (JOB_CONTROL)-
403 restore_pipeline (1);-
404#endif-
405-
406 subst_assign_varlist = save_subst_varlist;-
407 restore_parser_state (&pstate);-
408 temporary_env = save_tempenv;-
409 }
never executed: end of block
0
410-
411 pending_traps[sig] = 0; /* XXX - move before evalstring? */-
412 running_trap = 0;-
413 }
never executed: end of block
0
414 }
never executed: end of block
0
415-
416#if defined (ARRAY_VARS)-
417 restore_pipestatus_array (ps);-
418#endif-
419 last_command_exit_value = old_exit_value;-
420}
never executed: end of block
0
421-
422sighandler-
423trap_handler (sig)-
424 int sig;-
425{-
426 int oerrno;-
427-
428 if ((sigmodes[sig] & SIG_TRAPPED) == 0)
(sigmodes[sig] & 0x1) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
429 {-
430#if defined (DEBUG)-
431 internal_warning ("trap_handler: signal %d: signal not trapped", sig);-
432#endif-
433 SIGRETURN (0);
never executed: return;
0
434 }-
435-
436 if ((sig >= NSIG) ||
(sig >= 65 )Description
TRUEnever evaluated
FALSEnever evaluated
0
437 (trap_list[sig] == (char *)DEFAULT_SIG) ||
(trap_list[sig...andler_t) 0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
438 (trap_list[sig] == (char *)IGNORE_SIG))
(trap_list[sig...andler_t) 1) )Description
TRUEnever evaluated
FALSEnever evaluated
0
439 programming_error (_("trap_handler: bad signal %d"), sig);
never executed: programming_error ( dcgettext (((void *)0), "trap_handler: bad signal %d" , 5) , sig);
0
440 else-
441 {-
442 oerrno = errno;-
443#if defined (MUST_REINSTALL_SIGHANDLERS)-
444# if defined (JOB_CONTROL) && defined (SIGCHLD)-
445 if (sig != SIGCHLD)-
446# endif /* JOB_CONTROL && SIGCHLD */-
447 set_signal_handler (sig, trap_handler);-
448#endif /* MUST_REINSTALL_SIGHANDLERS */-
449-
450 catch_flag = 1;-
451 pending_traps[sig]++;-
452 trapped_signal_received = sig;-
453-
454 if (this_shell_builtin && (this_shell_builtin == wait_builtin))
this_shell_builtinDescription
TRUEnever evaluated
FALSEnever evaluated
(this_shell_bu... wait_builtin)Description
TRUEnever evaluated
FALSEnever evaluated
0
455 {-
456 wait_signal_received = sig;-
457 if (interrupt_immediately && wait_intr_flag)
interrupt_immediatelyDescription
TRUEnever evaluated
FALSEnever evaluated
wait_intr_flagDescription
TRUEnever evaluated
FALSEnever evaluated
0
458 sh_longjmp (wait_intr_buf, 1);
never executed: siglongjmp((wait_intr_buf), (1));
0
459 }
never executed: end of block
0
460-
461#if defined (READLINE)-
462 /* Set the event hook so readline will call it after the signal handlers-
463 finish executing, so if this interrupted character input we can get-
464 quick response. */-
465 if (RL_ISSTATE (RL_STATE_SIGHANDLER) && interrupt_immediately == 0)
(rl_readline_s...& (0x0008000))Description
TRUEnever evaluated
FALSEnever evaluated
interrupt_immediately == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
466 bashline_set_event_hook ();
never executed: bashline_set_event_hook ();
0
467#endif-
468-
469 if (interrupt_immediately)
interrupt_immediatelyDescription
TRUEnever evaluated
FALSEnever evaluated
0
470 run_pending_traps ();
never executed: run_pending_traps ();
0
471-
472 errno = oerrno;-
473 }
never executed: end of block
0
474-
475 SIGRETURN (0);
never executed: return;
0
476}-
477-
478int-
479first_pending_trap ()-
480{-
481 register int i;-
482-
483 for (i = 1; i < NSIG; i++)
i < 65Description
TRUEnever evaluated
FALSEnever evaluated
0
484 if (pending_traps[i])
pending_traps[i]Description
TRUEnever evaluated
FALSEnever evaluated
0
485 return i;
never executed: return i;
0
486 return -1;
never executed: return -1;
0
487}-
488-
489/* Return > 0 if any of the "real" signals (not fake signals like EXIT) are-
490 trapped. */-
491int-
492any_signals_trapped ()-
493{-
494 register int i;-
495-
496 for (i = 1; i < NSIG; i++)
i < 65Description
TRUEevaluated 24384 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 381 times by 1 test
Evaluated by:
  • Self test
381-24384
497 if (sigmodes[i] & SIG_TRAPPED)
sigmodes[i] & 0x1Description
TRUEnever evaluated
FALSEevaluated 24384 times by 1 test
Evaluated by:
  • Self test
0-24384
498 return i;
never executed: return i;
0
499 return -1;
executed 381 times by 1 test: return -1;
Executed by:
  • Self test
381
500}-
501-
502void-
503check_signals ()-
504{-
505 CHECK_ALRM; /* set by the read builtin */
executed 1 time by 1 test: siglongjmp((alrmbuf), (1));
Executed by:
  • Self test
sigalrm_seenDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8538295 times by 1 test
Evaluated by:
  • Self test
1-8538295
506 QUIT;
never executed: termsig_handler (terminating_signal);
never executed: throw_to_top_level ();
terminating_signalDescription
TRUEnever evaluated
FALSEevaluated 8538295 times by 1 test
Evaluated by:
  • Self test
interrupt_stateDescription
TRUEnever evaluated
FALSEevaluated 8538295 times by 1 test
Evaluated by:
  • Self test
0-8538295
507}
executed 8538295 times by 1 test: end of block
Executed by:
  • Self test
8538295
508-
509/* Convenience functions the rest of the shell can use */-
510void-
511check_signals_and_traps ()-
512{-
513 check_signals ();-
514-
515 run_pending_traps ();-
516}
never executed: end of block
0
517-
518#if defined (JOB_CONTROL) && defined (SIGCHLD)-
519-
520#ifdef INCLUDE_UNUSED-
521/* Make COMMAND_STRING be executed when SIGCHLD is caught. */-
522void-
523set_sigchld_trap (command_string)-
524 char *command_string;-
525{-
526 set_signal (SIGCHLD, command_string);-
527}-
528#endif-
529-
530/* Make COMMAND_STRING be executed when SIGCHLD is caught iff SIGCHLD-
531 is not already trapped. IMPOSSIBLE_TRAP_HANDLER is used as a sentinel-
532 to make sure that a SIGCHLD trap handler run via run_sigchld_trap can-
533 reset the disposition to the default and not have the original signal-
534 accidentally restored, undoing the user's command. */-
535void-
536maybe_set_sigchld_trap (command_string)-
537 char *command_string;-
538{-
539 if ((sigmodes[SIGCHLD] & SIG_TRAPPED) == 0 && trap_list[SIGCHLD] == (char *)IMPOSSIBLE_TRAP_HANDLER)
(sigmodes[ 17 ] & 0x1) == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
trap_list[ 17 ...itialize_trapsDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-3
540 set_signal (SIGCHLD, command_string);
executed 3 times by 1 test: set_signal ( 17 , command_string);
Executed by:
  • Self test
3
541}
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
542-
543/* Temporarily set the SIGCHLD trap string to IMPOSSIBLE_TRAP_HANDLER. Used-
544 as a sentinel in run_sigchld_trap and maybe_set_sigchld_trap to see whether-
545 or not a SIGCHLD trap handler reset SIGCHLD disposition to the default. */-
546void-
547set_impossible_sigchld_trap ()-
548{-
549 restore_default_signal (SIGCHLD);-
550 change_signal (SIGCHLD, (char *)IMPOSSIBLE_TRAP_HANDLER);-
551 sigmodes[SIGCHLD] &= ~SIG_TRAPPED; /* maybe_set_sigchld_trap checks this */-
552}
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
553-
554/* Act as if we received SIGCHLD NCHILD times and increment-
555 pending_traps[SIGCHLD] by that amount. This allows us to still run the-
556 SIGCHLD trap once for each exited child. */-
557void-
558queue_sigchld_trap (nchild)-
559 int nchild;-
560{-
561 if (nchild > 0)
nchild > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
562 {-
563 catch_flag = 1;-
564 pending_traps[SIGCHLD] += nchild;-
565 trapped_signal_received = SIGCHLD;-
566 }
never executed: end of block
0
567}
never executed: end of block
0
568#endif /* JOB_CONTROL && SIGCHLD */-
569-
570/* Set a trap for SIG only if SIG is not already trapped. */-
571static inline void-
572trap_if_untrapped (sig, command)-
573 int sig;-
574 char *command;-
575{-
576 if ((sigmodes[sig] & SIG_TRAPPED) == 0)
(sigmodes[sig] & 0x1) == 0Description
TRUEevaluated 1991 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
6-1991
577 set_signal (sig, command);
executed 1991 times by 1 test: set_signal (sig, command);
Executed by:
  • Self test
1991
578}
executed 1997 times by 1 test: end of block
Executed by:
  • Self test
1997
579-
580void-
581set_debug_trap (command)-
582 char *command;-
583{-
584 set_signal (DEBUG_TRAP, command);-
585}
never executed: end of block
0
586-
587/* Separate function to call when functions and sourced files want to restore-
588 the original version of the DEBUG trap before returning. Unless the -T-
589 option is set, source and shell function execution save the old debug trap-
590 and unset the trap. If the function or sourced file changes the DEBUG trap,-
591 SIG_TRAPPED will be set and we don't bother restoring the original trap string.-
592 This is used by both functions and the source builtin. */-
593void-
594maybe_set_debug_trap (command)-
595 char *command;-
596{-
597 trap_if_untrapped (DEBUG_TRAP, command);-
598}
executed 109 times by 1 test: end of block
Executed by:
  • Self test
109
599-
600void-
601set_error_trap (command)-
602 char *command;-
603{-
604 set_signal (ERROR_TRAP, command);-
605}
never executed: end of block
0
606-
607void-
608maybe_set_error_trap (command)-
609 char *command;-
610{-
611 trap_if_untrapped (ERROR_TRAP, command);-
612}
never executed: end of block
0
613-
614void-
615set_return_trap (command)-
616 char *command;-
617{-
618 set_signal (RETURN_TRAP, command);-
619}
never executed: end of block
0
620-
621void-
622maybe_set_return_trap (command)-
623 char *command;-
624{-
625 trap_if_untrapped (RETURN_TRAP, command);-
626}
executed 1888 times by 1 test: end of block
Executed by:
  • Self test
1888
627-
628#ifdef INCLUDE_UNUSED-
629void-
630set_sigint_trap (command)-
631 char *command;-
632{-
633 set_signal (SIGINT, command);-
634}-
635#endif-
636-
637/* Reset the SIGINT handler so that subshells that are doing `shellsy'-
638 things, like waiting for command substitution or executing commands-
639 in explicit subshells ( ( cmd ) ), can catch interrupts properly. */-
640SigHandler *-
641set_sigint_handler ()-
642{-
643 if (sigmodes[SIGINT] & SIG_HARD_IGNORE)
sigmodes[ 2 ] & 0x2Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6588 times by 1 test
Evaluated by:
  • Self test
2-6588
644 return ((SigHandler *)SIG_IGN);
executed 2 times by 1 test: return ((SigHandler *) ((__sighandler_t) 1) );
Executed by:
  • Self test
2
645-
646 else if (sigmodes[SIGINT] & SIG_IGNORED)
sigmodes[ 2 ] & 0x40Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6583 times by 1 test
Evaluated by:
  • Self test
5-6583
647 return ((SigHandler *)set_signal_handler (SIGINT, SIG_IGN)); /* XXX */
executed 5 times by 1 test: return ((SigHandler *)set_signal_handler ( 2 , ((__sighandler_t) 1) ));
Executed by:
  • Self test
5
648-
649 else if (sigmodes[SIGINT] & SIG_TRAPPED)
sigmodes[ 2 ] & 0x1Description
TRUEnever evaluated
FALSEevaluated 6583 times by 1 test
Evaluated by:
  • Self test
0-6583
650 return ((SigHandler *)set_signal_handler (SIGINT, trap_handler));
never executed: return ((SigHandler *)set_signal_handler ( 2 , trap_handler));
0
651-
652 /* The signal is not trapped, so set the handler to the shell's special-
653 interrupt handler. */-
654 else if (interactive) /* XXX - was interactive_shell */
interactiveDescription
TRUEnever evaluated
FALSEevaluated 6583 times by 1 test
Evaluated by:
  • Self test
0-6583
655 return (set_signal_handler (SIGINT, sigint_sighandler));
never executed: return (set_signal_handler ( 2 , sigint_sighandler));
0
656 else-
657 return (set_signal_handler (SIGINT, termsig_sighandler));
executed 6583 times by 1 test: return (set_signal_handler ( 2 , termsig_sighandler));
Executed by:
  • Self test
6583
658}-
659-
660/* Return the correct handler for signal SIG according to the values in-
661 sigmodes[SIG]. */-
662SigHandler *-
663trap_to_sighandler (sig)-
664 int sig;-
665{-
666 if (sigmodes[sig] & (SIG_IGNORED|SIG_HARD_IGNORE))
sigmodes[sig] & (0x40|0x2)Description
TRUEnever evaluated
FALSEnever evaluated
0
667 return (SIG_IGN);
never executed: return ( ((__sighandler_t) 1) );
0
668 else if (sigmodes[sig] & SIG_TRAPPED)
sigmodes[sig] & 0x1Description
TRUEnever evaluated
FALSEnever evaluated
0
669 return (trap_handler);
never executed: return (trap_handler);
0
670 else-
671 return (SIG_DFL);
never executed: return ( ((__sighandler_t) 0) );
0
672}-
673-
674/* Set SIG to call STRING as a command. */-
675void-
676set_signal (sig, string)-
677 int sig;-
678 char *string;-
679{-
680 sigset_t set, oset;-
681-
682 if (SPECIAL_TRAP (sig))
(sig) == 0Description
TRUEevaluated 73 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2136 times by 1 test
Evaluated by:
  • Self test
(sig) == 65Description
TRUEevaluated 141 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1995 times by 1 test
Evaluated by:
  • Self test
(sig) == 65 +1Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1989 times by 1 test
Evaluated by:
  • Self test
(sig) == 65 +2Description
TRUEevaluated 1907 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 82 times by 1 test
Evaluated by:
  • Self test
6-2136
683 {-
684 change_signal (sig, savestring (string));-
685 if (sig == EXIT_TRAP && interactive == 0)
sig == 0Description
TRUEevaluated 73 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2054 times by 1 test
Evaluated by:
  • Self test
interactive == 0Description
TRUEevaluated 73 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2054
686 initialize_terminating_signals ();
executed 73 times by 1 test: initialize_terminating_signals ();
Executed by:
  • Self test
73
687 return;
executed 2127 times by 1 test: return;
Executed by:
  • Self test
2127
688 }-
689-
690 /* A signal ignored on entry to the shell cannot be trapped or reset, but-
691 no error is reported when attempting to do so. -- Posix.2 */-
692 if (sigmodes[sig] & SIG_HARD_IGNORE)
sigmodes[sig] & 0x2Description
TRUEnever evaluated
FALSEevaluated 82 times by 1 test
Evaluated by:
  • Self test
0-82
693 return;
never executed: return;
0
694-
695 /* Make sure we have original_signals[sig] if the signal has not yet-
696 been trapped. */-
697 if ((sigmodes[sig] & SIG_TRAPPED) == 0)
(sigmodes[sig] & 0x1) == 0Description
TRUEevaluated 82 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-82
698 {-
699 /* If we aren't sure of the original value, check it. */-
700 if (original_signals[sig] == IMPOSSIBLE_TRAP_HANDLER)
original_signa...itialize_trapsDescription
TRUEevaluated 50 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 32 times by 1 test
Evaluated by:
  • Self test
32-50
701 GETORIGSIG (sig);
executed 1 time by 1 test: sigmodes[sig] |= 0x2;
Executed by:
  • Self test
executed 50 times by 1 test: end of block
Executed by:
  • Self test
original_signa...ghandler_t) 1)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 49 times by 1 test
Evaluated by:
  • Self test
1-50
702 if (original_signals[sig] == SIG_IGN)
original_signa...ghandler_t) 1)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 81 times by 1 test
Evaluated by:
  • Self test
1-81
703 return;
executed 1 time by 1 test: return;
Executed by:
  • Self test
1
704 }
executed 81 times by 1 test: end of block
Executed by:
  • Self test
81
705-
706 /* Only change the system signal handler if SIG_NO_TRAP is not set.-
707 The trap command string is changed in either case. The shell signal-
708 handlers for SIGINT and SIGCHLD run the user specified traps in an-
709 environment in which it is safe to do so. */-
710 if ((sigmodes[sig] & SIG_NO_TRAP) == 0)
(sigmodes[sig] & 0x8) == 0Description
TRUEevaluated 77 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
4-77
711 {-
712 BLOCK_SIGNAL (sig, set, oset);-
713 change_signal (sig, savestring (string));-
714 set_signal_handler (sig, trap_handler);-
715 UNBLOCK_SIGNAL (oset);-
716 }
executed 77 times by 1 test: end of block
Executed by:
  • Self test
77
717 else-
718 change_signal (sig, savestring (string));
executed 4 times by 1 test: change_signal (sig, (char *)strcpy (sh_xmalloc((1 + strlen (string)), "trap.c", 718), (string)));
Executed by:
  • Self test
4
719}-
720-
721static void-
722free_trap_command (sig)-
723 int sig;-
724{-
725 if ((sigmodes[sig] & SIG_TRAPPED) && trap_list[sig] &&
(sigmodes[sig] & 0x1)Description
TRUEevaluated 1589 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7816 times by 1 test
Evaluated by:
  • Self test
trap_list[sig]Description
TRUEevaluated 1589 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-7816
726 (trap_list[sig] != (char *)IGNORE_SIG) &&
(trap_list[sig...andler_t) 1) )Description
TRUEevaluated 1578 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
11-1578
727 (trap_list[sig] != (char *)DEFAULT_SIG) &&
(trap_list[sig...andler_t) 0) )Description
TRUEevaluated 1578 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1578
728 (trap_list[sig] != (char *)IMPOSSIBLE_TRAP_HANDLER))
(trap_list[sig...tialize_traps)Description
TRUEevaluated 1578 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1578
729 free (trap_list[sig]);
executed 1578 times by 1 test: sh_xfree((trap_list[sig]), "trap.c", 729);
Executed by:
  • Self test
1578
730}
executed 9405 times by 1 test: end of block
Executed by:
  • Self test
9405
731-
732/* If SIG has a string assigned to it, get rid of it. Then give it-
733 VALUE. */-
734static void-
735change_signal (sig, value)-
736 int sig;-
737 char *value;-
738{-
739 if ((sigmodes[sig] & SIG_INPROGRESS) == 0)
(sigmodes[sig] & 0x10) == 0Description
TRUEevaluated 7851 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 482 times by 1 test
Evaluated by:
  • Self test
482-7851
740 free_trap_command (sig);
executed 7851 times by 1 test: free_trap_command (sig);
Executed by:
  • Self test
7851
741 trap_list[sig] = value;-
742-
743 sigmodes[sig] |= SIG_TRAPPED;-
744 if (value == (char *)IGNORE_SIG)
value == (char...ghandler_t) 1)Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8316 times by 1 test
Evaluated by:
  • Self test
17-8316
745 sigmodes[sig] |= SIG_IGNORED;
executed 17 times by 1 test: sigmodes[sig] |= 0x40;
Executed by:
  • Self test
17
746 else-
747 sigmodes[sig] &= ~SIG_IGNORED;
executed 8316 times by 1 test: sigmodes[sig] &= ~0x40;
Executed by:
  • Self test
8316
748 if (sigmodes[sig] & SIG_INPROGRESS)
sigmodes[sig] & 0x10Description
TRUEevaluated 482 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7851 times by 1 test
Evaluated by:
  • Self test
482-7851
749 sigmodes[sig] |= SIG_CHANGED;
executed 482 times by 1 test: sigmodes[sig] |= 0x20;
Executed by:
  • Self test
482
750}
executed 8333 times by 1 test: end of block
Executed by:
  • Self test
8333
751-
752void-
753get_original_signal (sig)-
754 int sig;-
755{-
756 /* If we aren't sure the of the original value, then get it. */-
757 if (sig > 0 && sig < NSIG && original_signals[sig] == (SigHandler *)IMPOSSIBLE_TRAP_HANDLER)
sig > 0Description
TRUEevaluated 19110 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
sig < 65Description
TRUEevaluated 19110 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
original_signa...itialize_trapsDescription
TRUEevaluated 16290 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2820 times by 1 test
Evaluated by:
  • Self test
0-19110
758 GETORIGSIG (sig);
never executed: sigmodes[sig] |= 0x2;
executed 16290 times by 1 test: end of block
Executed by:
  • Self test
original_signa...ghandler_t) 1)Description
TRUEnever evaluated
FALSEevaluated 16290 times by 1 test
Evaluated by:
  • Self test
0-16290
759}
executed 19110 times by 1 test: end of block
Executed by:
  • Self test
19110
760-
761void-
762get_all_original_signals ()-
763{-
764 register int i;-
765-
766 for (i = 1; i < NSIG; i++)
i < 65Description
TRUEevaluated 2752 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 43 times by 1 test
Evaluated by:
  • Self test
43-2752
767 GET_ORIGINAL_SIGNAL (i);
never executed: sigmodes[i] |= 0x2;
executed 608 times by 1 test: end of block
Executed by:
  • Self test
original_signa...ghandler_t) 1)Description
TRUEnever evaluated
FALSEevaluated 608 times by 1 test
Evaluated by:
  • Self test
iDescription
TRUEevaluated 2752 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
i < 65Description
TRUEevaluated 2752 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
original_signa...itialize_trapsDescription
TRUEevaluated 608 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2144 times by 1 test
Evaluated by:
  • Self test
0-2752
768}
executed 43 times by 1 test: end of block
Executed by:
  • Self test
43
769-
770void-
771set_original_signal (sig, handler)-
772 int sig;-
773 SigHandler *handler;-
774{-
775 if (sig > 0 && sig < NSIG && original_signals[sig] == (SigHandler *)IMPOSSIBLE_TRAP_HANDLER)
sig > 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
sig < 65Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
original_signa...itialize_trapsDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-6
776 SETORIGSIG (sig, handler);
never executed: sigmodes[sig] |= 0x2;
executed 6 times by 1 test: end of block
Executed by:
  • Self test
original_signa...ghandler_t) 1)Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
0-6
777}
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
778-
779/* Restore the default action for SIG; i.e., the action the shell-
780 would have taken before you used the trap command. This is called-
781 from trap_builtin (), which takes care to restore the handlers for-
782 the signals the shell treats specially. */-
783void-
784restore_default_signal (sig)-
785 int sig;-
786{-
787 if (SPECIAL_TRAP (sig))
(sig) == 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2042 times by 1 test
Evaluated by:
  • Self test
(sig) == 65Description
TRUEevaluated 123 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1919 times by 1 test
Evaluated by:
  • Self test
(sig) == 65 +1Description
TRUEnever evaluated
FALSEevaluated 1919 times by 1 test
Evaluated by:
  • Self test
(sig) == 65 +2Description
TRUEevaluated 1896 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 23 times by 1 test
Evaluated by:
  • Self test
0-2042
788 {-
789 if ((sig != DEBUG_TRAP && sig != ERROR_TRAP && sig != RETURN_TRAP) ||
sig != 65Description
TRUEevaluated 1902 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 123 times by 1 test
Evaluated by:
  • Self test
sig != 65 +1Description
TRUEevaluated 1902 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
sig != 65 +2Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1896 times by 1 test
Evaluated by:
  • Self test
0-1902
790 (sigmodes[sig] & SIG_INPROGRESS) == 0)
(sigmodes[sig] & 0x10) == 0Description
TRUEevaluated 1537 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 482 times by 1 test
Evaluated by:
  • Self test
482-1537
791 free_trap_command (sig);
executed 1543 times by 1 test: free_trap_command (sig);
Executed by:
  • Self test
1543
792 trap_list[sig] = (char *)NULL;-
793 sigmodes[sig] &= ~SIG_TRAPPED;-
794 if (sigmodes[sig] & SIG_INPROGRESS)
sigmodes[sig] & 0x10Description
TRUEevaluated 482 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1543 times by 1 test
Evaluated by:
  • Self test
482-1543
795 sigmodes[sig] |= SIG_CHANGED;
executed 482 times by 1 test: sigmodes[sig] |= 0x20;
Executed by:
  • Self test
482
796 return;
executed 2025 times by 1 test: return;
Executed by:
  • Self test
2025
797 }-
798-
799 GET_ORIGINAL_SIGNAL (sig);
never executed: sigmodes[sig] |= 0x2;
never executed: end of block
original_signa...ghandler_t) 1)Description
TRUEnever evaluated
FALSEnever evaluated
sigDescription
TRUEevaluated 23 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
sig < 65Description
TRUEevaluated 23 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
original_signa...itialize_trapsDescription
TRUEnever evaluated
FALSEevaluated 23 times by 1 test
Evaluated by:
  • Self test
0-23
800-
801 /* A signal ignored on entry to the shell cannot be trapped or reset, but-
802 no error is reported when attempting to do so. Thanks Posix.2. */-
803 if (sigmodes[sig] & SIG_HARD_IGNORE)
sigmodes[sig] & 0x2Description
TRUEnever evaluated
FALSEevaluated 23 times by 1 test
Evaluated by:
  • Self test
0-23
804 return;
never executed: return;
0
805-
806 /* If we aren't trapping this signal, don't bother doing anything else. */-
807 /* We special-case SIGCHLD and IMPOSSIBLE_TRAP_HANDLER (see above) as a-
808 sentinel to determine whether or not disposition is reset to the default-
809 while the trap handler is executing. */-
810 if (((sigmodes[sig] & SIG_TRAPPED) == 0) &&
((sigmodes[sig] & 0x1) == 0)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
6-17
811 (sig != SIGCHLD || (sigmodes[sig] & SIG_INPROGRESS) == 0 || trap_list[sig] != (char *)IMPOSSIBLE_TRAP_HANDLER))
sig != 17Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(sigmodes[sig] & 0x10) == 0Description
TRUEnever evaluated
FALSEnever evaluated
trap_list[sig]...itialize_trapsDescription
TRUEnever evaluated
FALSEnever evaluated
0-6
812 return;
executed 6 times by 1 test: return;
Executed by:
  • Self test
6
813-
814 /* Only change the signal handler for SIG if it allows it. */-
815 if ((sigmodes[sig] & SIG_NO_TRAP) == 0)
(sigmodes[sig] & 0x8) == 0Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
4-13
816 set_signal_handler (sig, original_signals[sig]);
executed 13 times by 1 test: set_signal_handler (sig, original_signals[sig]);
Executed by:
  • Self test
13
817-
818 /* Change the trap command in either case. */-
819 change_signal (sig, (char *)DEFAULT_SIG);-
820-
821 /* Mark the signal as no longer trapped. */-
822 sigmodes[sig] &= ~SIG_TRAPPED;-
823}
executed 17 times by 1 test: end of block
Executed by:
  • Self test
17
824-
825/* Make this signal be ignored. */-
826void-
827ignore_signal (sig)-
828 int sig;-
829{-
830 if (SPECIAL_TRAP (sig) && ((sigmodes[sig] & SIG_IGNORED) == 0))
(sig) == 0Description
TRUEnever evaluated
FALSEevaluated 23 times by 1 test
Evaluated by:
  • Self test
(sig) == 65Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
(sig) == 65 +1Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
(sig) == 65 +2Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
((sigmodes[sig] & 0x40) == 0)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-23
831 {-
832 change_signal (sig, (char *)IGNORE_SIG);-
833 return;
executed 6 times by 1 test: return;
Executed by:
  • Self test
6
834 }-
835-
836 GET_ORIGINAL_SIGNAL (sig);
never executed: sigmodes[sig] |= 0x2;
never executed: end of block
original_signa...ghandler_t) 1)Description
TRUEnever evaluated
FALSEnever evaluated
sigDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
sig < 65Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
original_signa...itialize_trapsDescription
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
0-17
837-
838 /* A signal ignored on entry to the shell cannot be trapped or reset.-
839 No error is reported when the user attempts to do so. */-
840 if (sigmodes[sig] & SIG_HARD_IGNORE)
sigmodes[sig] & 0x2Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
0-17
841 return;
never executed: return;
0
842-
843 /* If already trapped and ignored, no change necessary. */-
844 if (sigmodes[sig] & SIG_IGNORED)
sigmodes[sig] & 0x40Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
6-11
845 return;
executed 6 times by 1 test: return;
Executed by:
  • Self test
6
846-
847 /* Only change the signal handler for SIG if it allows it. */-
848 if ((sigmodes[sig] & SIG_NO_TRAP) == 0)
(sigmodes[sig] & 0x8) == 0Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-11
849 set_signal_handler (sig, SIG_IGN);
executed 11 times by 1 test: set_signal_handler (sig, ((__sighandler_t) 1) );
Executed by:
  • Self test
11
850-
851 /* Change the trap command in either case. */-
852 change_signal (sig, (char *)IGNORE_SIG);-
853}
executed 11 times by 1 test: end of block
Executed by:
  • Self test
11
854-
855/* Handle the calling of "trap 0". The only sticky situation is when-
856 the command to be executed includes an "exit". This is why we have-
857 to provide our own place for top_level to jump to. */-
858int-
859run_exit_trap ()-
860{-
861 char *trap_command;-
862 int code, function_code, retval;-
863#if defined (ARRAY_VARS)-
864 ARRAY *ps;-
865#endif-
866-
867 trap_saved_exit_value = last_command_exit_value;-
868#if defined (ARRAY_VARS)-
869 ps = save_pipestatus_array ();-
870#endif-
871 function_code = 0;-
872-
873 /* Run the trap only if signal 0 is trapped and not ignored, and we are not-
874 currently running in the trap handler (call to exit in the list of-
875 commands given to trap 0). */-
876 if ((sigmodes[EXIT_TRAP] & SIG_TRAPPED) &&
(sigmodes[0] & 0x1)Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2730 times by 1 test
Evaluated by:
  • Self test
32-2730
877 (sigmodes[EXIT_TRAP] & (SIG_IGNORED|SIG_INPROGRESS)) == 0)
(sigmodes[0] &...40|0x10)) == 0Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-32
878 {-
879 trap_command = savestring (trap_list[EXIT_TRAP]);-
880 sigmodes[EXIT_TRAP] &= ~SIG_TRAPPED;-
881 sigmodes[EXIT_TRAP] |= SIG_INPROGRESS;-
882-
883 retval = trap_saved_exit_value;-
884 running_trap = 1;-
885-
886 code = setjmp_nosigs (top_level);-
887-
888 /* If we're in a function, make sure return longjmps come here, too. */-
889 if (return_catch_flag)
return_catch_flagDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
6-28
890 function_code = setjmp_nosigs (return_catch);
executed 6 times by 1 test: function_code = __sigsetjmp ( (return_catch) , 0 ) ;
Executed by:
  • Self test
6
891-
892 if (code == 0 && function_code == 0)
code == 0Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
function_code == 0Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-32
893 {-
894 reset_parser ();-
895 parse_and_execute (trap_command, "exit trap", SEVAL_NONINT|SEVAL_NOHIST|SEVAL_RESETLINE);-
896 }
executed 30 times by 1 test: end of block
Executed by:
  • Self test
30
897 else if (code == ERREXIT)
code == 4Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
898 retval = last_command_exit_value;
never executed: retval = last_command_exit_value;
0
899 else if (code == EXITPROG)
code == 3Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
900 retval = last_command_exit_value;
executed 2 times by 1 test: retval = last_command_exit_value;
Executed by:
  • Self test
2
901 else if (function_code != 0)
function_code != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
902 retval = return_catch_value;
never executed: retval = return_catch_value;
0
903 else-
904 retval = trap_saved_exit_value;
never executed: retval = trap_saved_exit_value;
0
905-
906 running_trap = 0;-
907#if defined (ARRAY_VARS)-
908 array_dispose (ps);-
909#endif-
910-
911 return retval;
executed 32 times by 1 test: return retval;
Executed by:
  • Self test
32
912 }-
913-
914#if defined (ARRAY_VARS)-
915 restore_pipestatus_array (ps);-
916#endif-
917 return (trap_saved_exit_value);
executed 2730 times by 1 test: return (trap_saved_exit_value);
Executed by:
  • Self test
2730
918}-
919-
920void-
921run_trap_cleanup (sig)-
922 int sig;-
923{-
924 sigmodes[sig] &= ~(SIG_INPROGRESS|SIG_CHANGED);-
925}
never executed: end of block
0
926-
927#define RECURSIVE_SIG(s) (SPECIAL_TRAP(s) == 0)-
928-
929/* Run a trap command for SIG. SIG is one of the signals the shell treats-
930 specially. Returns the exit status of the executed trap command list. */-
931static int-
932_run_trap_internal (sig, tag)-
933 int sig;-
934 char *tag;-
935{-
936 char *trap_command, *old_trap;-
937 int trap_exit_value;-
938 volatile int save_return_catch_flag, function_code, old_int;-
939 int flags;-
940 procenv_t save_return_catch;-
941 WORD_LIST *save_subst_varlist;-
942 HASH_TABLE *save_tempenv;-
943 sh_parser_state_t pstate;-
944#if defined (ARRAY_VARS)-
945 ARRAY *ps;-
946#endif-
947-
948 trap_exit_value = function_code = 0;-
949 trap_saved_exit_value = last_command_exit_value;-
950 /* Run the trap only if SIG is trapped and not ignored, and we are not-
951 currently executing in the trap handler. */-
952 if ((sigmodes[sig] & SIG_TRAPPED) && ((sigmodes[sig] & SIG_IGNORED) == 0) &&
(sigmodes[sig] & 0x1)Description
TRUEevaluated 2073 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
((sigmodes[sig] & 0x40) == 0)Description
TRUEevaluated 2073 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2073
953 (trap_list[sig] != (char *)IMPOSSIBLE_TRAP_HANDLER) &&
(trap_list[sig...tialize_traps)Description
TRUEevaluated 2073 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2073
954#if 0-
955 /* Uncomment this to allow some special signals to recursively execute-
956 trap handlers. */-
957 (RECURSIVE_SIG (sig) || (sigmodes[sig] & SIG_INPROGRESS) == 0))-
958#else-
959 ((sigmodes[sig] & SIG_INPROGRESS) == 0))
((sigmodes[sig] & 0x10) == 0)Description
TRUEevaluated 2073 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2073
960#endif-
961 {-
962 old_trap = trap_list[sig];-
963 sigmodes[sig] |= SIG_INPROGRESS;-
964 sigmodes[sig] &= ~SIG_CHANGED; /* just to be sure */-
965 trap_command = savestring (old_trap);-
966-
967 running_trap = sig + 1;-
968-
969 old_int = interrupt_state; /* temporarily suppress pending interrupts */-
970 CLRINTERRUPT;-
971-
972#if defined (ARRAY_VARS)-
973 ps = save_pipestatus_array ();-
974#endif-
975-
976 save_parser_state (&pstate);-
977 save_subst_varlist = subst_assign_varlist;-
978 subst_assign_varlist = 0;-
979 save_tempenv = temporary_env;-
980 temporary_env = 0; /* traps should not run with temporary env */-
981-
982#if defined (JOB_CONTROL)-
983 if (sig != DEBUG_TRAP) /* run_debug_trap does this */
sig != 65Description
TRUEevaluated 112 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1961 times by 1 test
Evaluated by:
  • Self test
112-1961
984 save_pipeline (1); /* XXX only provides one save level */
executed 112 times by 1 test: save_pipeline (1);
Executed by:
  • Self test
112
985#endif-
986-
987 /* If we're in a function, make sure return longjmps come here, too. */-
988 save_return_catch_flag = return_catch_flag;-
989 if (return_catch_flag)
return_catch_flagDescription
TRUEevaluated 1764 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 309 times by 1 test
Evaluated by:
  • Self test
309-1764
990 {-
991 COPY_PROCENV (return_catch, save_return_catch);-
992 function_code = setjmp_nosigs (return_catch);-
993 }
executed 1764 times by 1 test: end of block
Executed by:
  • Self test
1764
994-
995 flags = SEVAL_NONINT|SEVAL_NOHIST;-
996 if (sig != DEBUG_TRAP && sig != RETURN_TRAP && sig != ERROR_TRAP)
sig != 65Description
TRUEevaluated 112 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1961 times by 1 test
Evaluated by:
  • Self test
sig != 65 +2Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 102 times by 1 test
Evaluated by:
  • Self test
sig != 65 +1Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
0-1961
997 flags |= SEVAL_RESETLINE;
never executed: flags |= 0x010;
0
998 if (function_code == 0)
function_code == 0Description
TRUEevaluated 2073 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2073
999 {-
1000 parse_and_execute (trap_command, tag, flags);-
1001 trap_exit_value = last_command_exit_value;-
1002 }
executed 2073 times by 1 test: end of block
Executed by:
  • Self test
2073
1003 else-
1004 trap_exit_value = return_catch_value;
never executed: trap_exit_value = return_catch_value;
0
1005-
1006#if defined (JOB_CONTROL)-
1007 if (sig != DEBUG_TRAP) /* run_debug_trap does this */
sig != 65Description
TRUEevaluated 112 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1961 times by 1 test
Evaluated by:
  • Self test
112-1961
1008 restore_pipeline (1);
executed 112 times by 1 test: restore_pipeline (1);
Executed by:
  • Self test
112
1009#endif-
1010-
1011 subst_assign_varlist = save_subst_varlist;-
1012 restore_parser_state (&pstate);-
1013-
1014#if defined (ARRAY_VARS)-
1015 restore_pipestatus_array (ps);-
1016#endif-
1017-
1018 temporary_env = save_tempenv;-
1019-
1020 sigmodes[sig] &= ~SIG_INPROGRESS;-
1021 running_trap = 0;-
1022 interrupt_state = old_int;-
1023-
1024 if (sigmodes[sig] & SIG_CHANGED)
sigmodes[sig] & 0x20Description
TRUEevaluated 185 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1888 times by 1 test
Evaluated by:
  • Self test
185-1888
1025 {-
1026#if 0-
1027 /* Special traps like EXIT, DEBUG, RETURN are handled explicitly in-
1028 the places where they can be changed using unwind-protects. For-
1029 example, look at execute_cmd.c:execute_function(). */-
1030 if (SPECIAL_TRAP (sig) == 0)-
1031#endif-
1032 free (old_trap);-
1033 sigmodes[sig] &= ~SIG_CHANGED;-
1034 }
executed 185 times by 1 test: end of block
Executed by:
  • Self test
185
1035-
1036 if (save_return_catch_flag)
save_return_catch_flagDescription
TRUEevaluated 1764 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 309 times by 1 test
Evaluated by:
  • Self test
309-1764
1037 {-
1038 return_catch_flag = save_return_catch_flag;-
1039 return_catch_value = trap_exit_value;-
1040 COPY_PROCENV (save_return_catch, return_catch);-
1041 if (function_code)
function_codeDescription
TRUEnever evaluated
FALSEevaluated 1764 times by 1 test
Evaluated by:
  • Self test
0-1764
1042 {-
1043#if 0-
1044 from_return_trap = sig == RETURN_TRAP;-
1045#endif-
1046 sh_longjmp (return_catch, 1);-
1047 }
never executed: end of block
0
1048 }
executed 1764 times by 1 test: end of block
Executed by:
  • Self test
1764
1049 }
executed 2073 times by 1 test: end of block
Executed by:
  • Self test
2073
1050-
1051 return trap_exit_value;
executed 2073 times by 1 test: return trap_exit_value;
Executed by:
  • Self test
2073
1052}-
1053-
1054int-
1055run_debug_trap ()-
1056{-
1057 int trap_exit_value, old_verbose;-
1058 pid_t save_pgrp;-
1059 int save_pipe[2];-
1060-
1061 /* XXX - question: should the DEBUG trap inherit the RETURN trap? */-
1062 trap_exit_value = 0;-
1063 if ((sigmodes[DEBUG_TRAP] & SIG_TRAPPED) && ((sigmodes[DEBUG_TRAP] & SIG_IGNORED) == 0) && ((sigmodes[DEBUG_TRAP] & SIG_INPROGRESS) == 0))
(sigmodes[ 65 ] & 0x1)Description
TRUEevaluated 9358 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 115301181 times by 1 test
Evaluated by:
  • Self test
((sigmodes[ 65 ] & 0x40) == 0)Description
TRUEevaluated 9346 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
((sigmodes[ 65 ] & 0x10) == 0)Description
TRUEevaluated 1961 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7385 times by 1 test
Evaluated by:
  • Self test
12-115301181
1064 {-
1065#if defined (JOB_CONTROL)-
1066 save_pgrp = pipeline_pgrp;-
1067 pipeline_pgrp = 0;-
1068 save_pipeline (1);-
1069# if defined (PGRP_PIPE)-
1070 save_pgrp_pipe (save_pipe, 1);-
1071# endif-
1072 stop_making_children ();-
1073#endif-
1074-
1075 old_verbose = echo_input_at_read;-
1076#if 0 /* not yet */-
1077 echo_input_at_read = 0;-
1078#endif-
1079-
1080 trap_exit_value = _run_trap_internal (DEBUG_TRAP, "debug trap");-
1081-
1082 echo_input_at_read = old_verbose;-
1083-
1084#if defined (JOB_CONTROL)-
1085 pipeline_pgrp = save_pgrp;-
1086 restore_pipeline (1);-
1087# if defined (PGRP_PIPE)-
1088 close_pgrp_pipe ();-
1089 restore_pgrp_pipe (save_pipe);-
1090# endif-
1091 if (pipeline_pgrp > 0 && ((subshell_environment & (SUBSHELL_ASYNC|SUBSHELL_PIPE)) == 0))
pipeline_pgrp > 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1953 times by 1 test
Evaluated by:
  • Self test
((subshell_env...1|0x10)) == 0)Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1953
1092 give_terminal_to (pipeline_pgrp, 1);
executed 8 times by 1 test: give_terminal_to (pipeline_pgrp, 1);
Executed by:
  • Self test
8
1093-
1094 notify_and_cleanup ();-
1095#endif-
1096 -
1097#if defined (DEBUGGER)-
1098 /* If we're in the debugger and the DEBUG trap returns 2 while we're in-
1099 a function or sourced script, we force a `return'. */-
1100 if (debugging_mode && trap_exit_value == 2 && return_catch_flag)
debugging_modeDescription
TRUEevaluated 1889 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 72 times by 1 test
Evaluated by:
  • Self test
trap_exit_value == 2Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1888 times by 1 test
Evaluated by:
  • Self test
return_catch_flagDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1889
1101 {-
1102 return_catch_value = trap_exit_value;-
1103 sh_longjmp (return_catch, 1);-
1104 }
never executed: end of block
0
1105#endif-
1106 }
executed 1961 times by 1 test: end of block
Executed by:
  • Self test
1961
1107 return trap_exit_value;
executed 115310539 times by 1 test: return trap_exit_value;
Executed by:
  • Self test
115310539
1108}-
1109-
1110void-
1111run_error_trap ()-
1112{-
1113 if ((sigmodes[ERROR_TRAP] & SIG_TRAPPED) && ((sigmodes[ERROR_TRAP] & SIG_IGNORED) == 0) && (sigmodes[ERROR_TRAP] & SIG_INPROGRESS) == 0)
(sigmodes[ 65 +1] & 0x1)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
((sigmodes[ 65... & 0x40) == 0)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(sigmodes[ 65 +1] & 0x10) == 0Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-10
1114 _run_trap_internal (ERROR_TRAP, "error trap");
executed 10 times by 1 test: _run_trap_internal ( 65 +1, "error trap");
Executed by:
  • Self test
10
1115}
executed 10 times by 1 test: end of block
Executed by:
  • Self test
10
1116-
1117void-
1118run_return_trap ()-
1119{-
1120 int old_exit_value;-
1121-
1122#if 0-
1123 if ((sigmodes[DEBUG_TRAP] & SIG_TRAPPED) && (sigmodes[DEBUG_TRAP] & SIG_INPROGRESS))-
1124 return;-
1125#endif-
1126-
1127 if ((sigmodes[RETURN_TRAP] & SIG_TRAPPED) && ((sigmodes[RETURN_TRAP] & SIG_IGNORED) == 0) && (sigmodes[RETURN_TRAP] & SIG_INPROGRESS) == 0)
(sigmodes[ 65 +2] & 0x1)Description
TRUEevaluated 201 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1637403 times by 1 test
Evaluated by:
  • Self test
((sigmodes[ 65... & 0x40) == 0)Description
TRUEevaluated 201 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(sigmodes[ 65 +2] & 0x10) == 0Description
TRUEevaluated 102 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 99 times by 1 test
Evaluated by:
  • Self test
0-1637403
1128 {-
1129 old_exit_value = last_command_exit_value;-
1130 _run_trap_internal (RETURN_TRAP, "return trap");-
1131 last_command_exit_value = old_exit_value;-
1132 }
executed 102 times by 1 test: end of block
Executed by:
  • Self test
102
1133}
executed 1637604 times by 1 test: end of block
Executed by:
  • Self test
1637604
1134-
1135/* Run a trap set on SIGINT. This is called from throw_to_top_level (), and-
1136 declared here to localize the trap functions. */-
1137void-
1138run_interrupt_trap (will_throw)-
1139 int will_throw; /* from throw_to_top_level? */-
1140{-
1141 if (will_throw && running_trap > 0)
will_throwDescription
TRUEnever evaluated
FALSEnever evaluated
running_trap > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1142 run_trap_cleanup (running_trap - 1);
never executed: run_trap_cleanup (running_trap - 1);
0
1143 _run_trap_internal (SIGINT, "interrupt trap");-
1144}
never executed: end of block
0
1145-
1146/* Free all the allocated strings in the list of traps and reset the trap-
1147 values to the default. Intended to be called from subshells that want-
1148 to complete work done by reset_signal_handlers upon execution of a-
1149 subsequent `trap' command that changes a signal's disposition. We need-
1150 to make sure that we duplicate the behavior of-
1151 reset_or_restore_signal_handlers and not change the disposition of signals-
1152 that are set to be ignored. */-
1153void-
1154free_trap_strings ()-
1155{-
1156 register int i;-
1157-
1158 for (i = 0; i < NSIG; i++)
i < 65Description
TRUEevaluated 1690 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
26-1690
1159 {-
1160 if (trap_list[i] != (char *)IGNORE_SIG)
trap_list[i] !...ghandler_t) 1)Description
TRUEevaluated 1689 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-1689
1161 free_trap_string (i);
executed 1689 times by 1 test: free_trap_string (i);
Executed by:
  • Self test
1689
1162 }
executed 1690 times by 1 test: end of block
Executed by:
  • Self test
1690
1163 for (i = NSIG; i < BASH_NSIG; i++)
i < 65 +3Description
TRUEevaluated 78 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
26-78
1164 {-
1165 /* Don't free the trap string if the subshell inherited the trap */-
1166 if ((sigmodes[i] & SIG_TRAPPED) == 0)
(sigmodes[i] & 0x1) == 0Description
TRUEevaluated 78 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-78
1167 {-
1168 free_trap_string (i);-
1169 trap_list[i] = (char *)NULL;-
1170 }
executed 78 times by 1 test: end of block
Executed by:
  • Self test
78
1171 }
executed 78 times by 1 test: end of block
Executed by:
  • Self test
78
1172}
executed 26 times by 1 test: end of block
Executed by:
  • Self test
26
1173-
1174/* Free a trap command string associated with SIG without changing signal-
1175 disposition. Intended to be called from free_trap_strings() */-
1176static void-
1177free_trap_string (sig)-
1178 int sig;-
1179{-
1180 change_signal (sig, (char *)DEFAULT_SIG);-
1181 sigmodes[sig] &= ~SIG_TRAPPED;-
1182}
executed 1767 times by 1 test: end of block
Executed by:
  • Self test
1767
1183-
1184/* Reset the handler for SIG to the original value but leave the trap string-
1185 in place. */-
1186static void-
1187reset_signal (sig)-
1188 int sig;-
1189{-
1190 set_signal_handler (sig, original_signals[sig]);-
1191 sigmodes[sig] &= ~SIG_TRAPPED;-
1192}
executed 15587 times by 1 test: end of block
Executed by:
  • Self test
15587
1193-
1194/* Set the handler signal SIG to the original and free any trap-
1195 command associated with it. */-
1196static void-
1197restore_signal (sig)-
1198 int sig;-
1199{-
1200 set_signal_handler (sig, original_signals[sig]);-
1201 change_signal (sig, (char *)DEFAULT_SIG);-
1202 sigmodes[sig] &= ~SIG_TRAPPED;-
1203}
executed 4321 times by 1 test: end of block
Executed by:
  • Self test
4321
1204-
1205static void-
1206reset_or_restore_signal_handlers (reset)-
1207 sh_resetsig_func_t *reset;-
1208{-
1209 register int i;-
1210-
1211 /* Take care of the exit trap first */-
1212 if (sigmodes[EXIT_TRAP] & SIG_TRAPPED)
sigmodes[0] & 0x1Description
TRUEevaluated 36 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6594 times by 1 test
Evaluated by:
  • Self test
36-6594
1213 {-
1214 sigmodes[EXIT_TRAP] &= ~SIG_TRAPPED;-
1215 if (reset != reset_signal)
reset != reset_signalDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 25 times by 1 test
Evaluated by:
  • Self test
11-25
1216 {-
1217 free_trap_command (EXIT_TRAP);-
1218 trap_list[EXIT_TRAP] = (char *)NULL;-
1219 }
executed 11 times by 1 test: end of block
Executed by:
  • Self test
11
1220 }
executed 36 times by 1 test: end of block
Executed by:
  • Self test
36
1221-
1222 for (i = 1; i < NSIG; i++)
i < 65Description
TRUEevaluated 424320 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6630 times by 1 test
Evaluated by:
  • Self test
6630-424320
1223 {-
1224 if (sigmodes[i] & SIG_TRAPPED)
sigmodes[i] & 0x1Description
TRUEevaluated 37 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 424283 times by 1 test
Evaluated by:
  • Self test
37-424283
1225 {-
1226 if (trap_list[i] == (char *)IGNORE_SIG)
trap_list[i] =...ghandler_t) 1)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 31 times by 1 test
Evaluated by:
  • Self test
6-31
1227 set_signal_handler (i, SIG_IGN);
executed 6 times by 1 test: set_signal_handler (i, ((__sighandler_t) 1) );
Executed by:
  • Self test
6
1228 else-
1229 (*reset) (i);
executed 31 times by 1 test: (*reset) (i);
Executed by:
  • Self test
31
1230 }-
1231 else if (sigmodes[i] & SIG_SPECIAL)
sigmodes[i] & 0x4Description
TRUEevaluated 19877 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 404406 times by 1 test
Evaluated by:
  • Self test
19877-404406
1232 (*reset) (i);
executed 19877 times by 1 test: (*reset) (i);
Executed by:
  • Self test
19877
1233 pending_traps[i] = 0; /* XXX */-
1234 }
executed 424320 times by 1 test: end of block
Executed by:
  • Self test
424320
1235-
1236 /* Command substitution and other child processes don't inherit the-
1237 debug, error, or return traps. If we're in the debugger, and the-
1238 `functrace' or `errtrace' options have been set, then let command-
1239 substitutions inherit them. Let command substitution inherit the-
1240 RETURN trap if we're in the debugger and tracing functions. */-
1241 if (function_trace_mode == 0)
function_trace_mode == 0Description
TRUEevaluated 6622 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
8-6622
1242 {-
1243 sigmodes[DEBUG_TRAP] &= ~SIG_TRAPPED;-
1244 sigmodes[RETURN_TRAP] &= ~SIG_TRAPPED;-
1245 }
executed 6622 times by 1 test: end of block
Executed by:
  • Self test
6622
1246 if (error_trace_mode == 0)
error_trace_mode == 0Description
TRUEevaluated 6612 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
18-6612
1247 sigmodes[ERROR_TRAP] &= ~SIG_TRAPPED;
executed 6612 times by 1 test: sigmodes[ 65 +1] &= ~0x1;
Executed by:
  • Self test
6612
1248}
executed 6630 times by 1 test: end of block
Executed by:
  • Self test
6630
1249-
1250/* Reset trapped signals to their original values, but don't free the-
1251 trap strings. Called by the command substitution code and other places-
1252 that create a "subshell environment". */-
1253void-
1254reset_signal_handlers ()-
1255{-
1256 reset_or_restore_signal_handlers (reset_signal);-
1257}
executed 5191 times by 1 test: end of block
Executed by:
  • Self test
5191
1258-
1259/* Reset all trapped signals to their original values. Signals set to be-
1260 ignored with trap '' SIGNAL should be ignored, so we make sure that they-
1261 are. Called by child processes after they are forked. */-
1262void-
1263restore_original_signals ()-
1264{-
1265 reset_or_restore_signal_handlers (restore_signal);-
1266}
executed 1439 times by 1 test: end of block
Executed by:
  • Self test
1439
1267-
1268/* If a trap handler exists for signal SIG, then call it; otherwise just-
1269 return failure. Returns 1 if it called the trap handler. */-
1270int-
1271maybe_call_trap_handler (sig)-
1272 int sig;-
1273{-
1274 /* Call the trap handler for SIG if the signal is trapped and not ignored. */-
1275 if ((sigmodes[sig] & SIG_TRAPPED) && ((sigmodes[sig] & SIG_IGNORED) == 0))
(sigmodes[sig] & 0x1)Description
TRUEnever evaluated
FALSEnever evaluated
((sigmodes[sig] & 0x40) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1276 {-
1277 switch (sig)-
1278 {-
1279 case SIGINT:
never executed: case 2 :
0
1280 run_interrupt_trap (0);-
1281 break;
never executed: break;
0
1282 case EXIT_TRAP:
never executed: case 0:
0
1283 run_exit_trap ();-
1284 break;
never executed: break;
0
1285 case DEBUG_TRAP:
never executed: case 65 :
0
1286 run_debug_trap ();-
1287 break;
never executed: break;
0
1288 case ERROR_TRAP:
never executed: case 65 +1:
0
1289 run_error_trap ();-
1290 break;
never executed: break;
0
1291 default:
never executed: default:
0
1292 trap_handler (sig);-
1293 break;
never executed: break;
0
1294 }-
1295 return (1);
never executed: return (1);
0
1296 }-
1297 else-
1298 return (0);
never executed: return (0);
0
1299}-
1300-
1301int-
1302signal_is_trapped (sig)-
1303 int sig;-
1304{-
1305 return (sigmodes[sig] & SIG_TRAPPED);
executed 2147483647 times by 1 test: return (sigmodes[sig] & 0x1);
Executed by:
  • Self test
Inf
1306}-
1307-
1308int-
1309signal_is_pending (sig)-
1310 int sig;-
1311{-
1312 return (pending_traps[sig]);
executed 501789 times by 1 test: return (pending_traps[sig]);
Executed by:
  • Self test
501789
1313}-
1314-
1315int-
1316signal_is_special (sig)-
1317 int sig;-
1318{-
1319 return (sigmodes[sig] & SIG_SPECIAL);
executed 413 times by 1 test: return (sigmodes[sig] & 0x4);
Executed by:
  • Self test
413
1320}-
1321-
1322int-
1323signal_is_ignored (sig)-
1324 int sig;-
1325{-
1326 return (sigmodes[sig] & SIG_IGNORED);
executed 4287 times by 1 test: return (sigmodes[sig] & 0x40);
Executed by:
  • Self test
4287
1327}-
1328-
1329int-
1330signal_is_hard_ignored (sig)-
1331 int sig;-
1332{-
1333 return (sigmodes[sig] & SIG_HARD_IGNORE);
executed 22634 times by 1 test: return (sigmodes[sig] & 0x2);
Executed by:
  • Self test
22634
1334}-
1335-
1336void-
1337set_signal_hard_ignored (sig)-
1338 int sig;-
1339{-
1340 sigmodes[sig] |= SIG_HARD_IGNORE;-
1341 original_signals[sig] = SIG_IGN;-
1342}
executed 81 times by 1 test: end of block
Executed by:
  • Self test
81
1343-
1344void-
1345set_signal_ignored (sig)-
1346 int sig;-
1347{-
1348 original_signals[sig] = SIG_IGN;-
1349}
never executed: end of block
0
1350-
1351int-
1352signal_in_progress (sig)-
1353 int sig;-
1354{-
1355 return (sigmodes[sig] & SIG_INPROGRESS);
executed 113672152 times by 1 test: return (sigmodes[sig] & 0x10);
Executed by:
  • Self test
113672152
1356}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2