72 |
/* trap handler commands */ |
/* trap handler commands */ |
73 |
char *trap[NSIG]; |
char *trap[NSIG]; |
74 |
/* current value of signal */ |
/* current value of signal */ |
75 |
static char sigmode[NSIG - 1]; |
char sigmode[NSIG - 1]; |
76 |
/* indicates specified signal received */ |
/* indicates specified signal received */ |
77 |
char gotsig[NSIG - 1]; |
static char gotsig[NSIG - 1]; |
78 |
/* last pending signal */ |
/* last pending signal */ |
79 |
volatile sig_atomic_t pendingsigs; |
volatile sig_atomic_t pendingsigs; |
|
/* do we generate EXSIG events */ |
|
|
int exsig; |
|
80 |
|
|
81 |
#ifdef mkinit |
#ifdef mkinit |
82 |
INCLUDE <signal.h> |
INCLUDE "trap.h" |
83 |
INIT { |
INIT { |
84 |
signal(SIGCHLD, SIG_DFL); |
sigmode[SIGCHLD - 1] = S_DFL; |
85 |
|
setsignal(SIGCHLD); |
86 |
} |
} |
87 |
#endif |
#endif |
88 |
|
|
116 |
else |
else |
117 |
action = *ap++; |
action = *ap++; |
118 |
while (*ap) { |
while (*ap) { |
119 |
if ((signo = decode_signal(*ap, 0)) < 0) |
if ((signo = decode_signal(*ap, 0)) < 0) { |
120 |
sh_error("%s: bad trap", *ap); |
outfmt(out2, "trap: %s: bad trap\n", *ap); |
121 |
|
return 1; |
122 |
|
} |
123 |
INTOFF; |
INTOFF; |
124 |
if (action) { |
if (action) { |
125 |
if (action[0] == '-' && action[1] == '\0') |
if (action[0] == '-' && action[1] == '\0') |
207 |
} |
} |
208 |
} |
} |
209 |
|
|
210 |
|
if (signo == SIGCHLD) |
211 |
|
action = S_CATCH; |
212 |
|
|
213 |
t = &sigmode[signo - 1]; |
t = &sigmode[signo - 1]; |
214 |
tsig = *t; |
tsig = *t; |
215 |
if (tsig == 0) { |
if (tsig == 0) { |
277 |
gotsig[signo - 1] = 1; |
gotsig[signo - 1] = 1; |
278 |
pendingsigs = signo; |
pendingsigs = signo; |
279 |
|
|
280 |
if (exsig || (signo == SIGINT && !trap[SIGINT])) { |
if (signo == SIGINT && !trap[SIGINT]) { |
281 |
if (!suppressint) |
if (!suppressint) |
282 |
onint(); |
onint(); |
283 |
intpending = 1; |
intpending = 1; |
311 |
p = trap[i + 1]; |
p = trap[i + 1]; |
312 |
if (!p) |
if (!p) |
313 |
continue; |
continue; |
314 |
evalstring(p, SKIPEVAL); |
evalstring(p, 0); |
315 |
exitstatus = savestatus; |
exitstatus = savestatus; |
316 |
if (evalskip) |
if (evalskip) |
317 |
return evalskip; |
return evalskip; |
360 |
TRACE(("pid %d, exitshell(%d)\n", getpid(), status)); |
TRACE(("pid %d, exitshell(%d)\n", getpid(), status)); |
361 |
if (setjmp(loc.loc)) { |
if (setjmp(loc.loc)) { |
362 |
if (exception == EXEXIT) |
if (exception == EXEXIT) |
363 |
_exit(exitstatus); |
status = exitstatus; |
364 |
goto out; |
goto out; |
365 |
} |
} |
366 |
handler = &loc; |
handler = &loc; |
367 |
if ((p = trap[0])) { |
if ((p = trap[0])) { |
368 |
trap[0] = NULL; |
trap[0] = NULL; |
369 |
|
evalskip = 0; |
370 |
evalstring(p, 0); |
evalstring(p, 0); |
371 |
} |
} |
|
flushall(); |
|
372 |
out: |
out: |
373 |
|
/* |
374 |
|
* Disable job control so that whoever had the foreground before we |
375 |
|
* started can get it back. |
376 |
|
*/ |
377 |
|
if (likely(!setjmp(loc.loc))) |
378 |
|
setjobctl(0); |
379 |
|
flushall(); |
380 |
_exit(status); |
_exit(status); |
381 |
/* NOTREACHED */ |
/* NOTREACHED */ |
382 |
} |
} |