trap.c (217461) | trap.c (217472) |
---|---|
1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Kenneth Almquist. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 22 unchanged lines hidden (view full) --- 31 */ 32 33#ifndef lint 34#if 0 35static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95"; 36#endif 37#endif /* not lint */ 38#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Kenneth Almquist. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 22 unchanged lines hidden (view full) --- 31 */ 32 33#ifndef lint 34#if 0 35static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95"; 36#endif 37#endif /* not lint */ 38#include <sys/cdefs.h> |
39__FBSDID("$FreeBSD: head/bin/sh/trap.c 217461 2011-01-15 21:09:00Z jilles $"); | 39__FBSDID("$FreeBSD: head/bin/sh/trap.c 217472 2011-01-16 13:56:41Z jilles $"); |
40 41#include <signal.h> 42#include <unistd.h> 43#include <stdlib.h> 44 45#include "shell.h" 46#include "main.h" 47#include "nodes.h" /* for other headers */ --- 26 unchanged lines hidden (view full) --- 74MKINIT char sigmode[NSIG]; /* current value of signal */ 75int pendingsigs; /* indicates some signal received */ 76int in_dotrap; /* do we execute in a trap handler? */ 77static char *volatile trap[NSIG]; /* trap handler commands */ 78static volatile sig_atomic_t gotsig[NSIG]; 79 /* indicates specified signal received */ 80static int ignore_sigchld; /* Used while handling SIGCHLD traps. */ 81volatile sig_atomic_t gotwinch; | 40 41#include <signal.h> 42#include <unistd.h> 43#include <stdlib.h> 44 45#include "shell.h" 46#include "main.h" 47#include "nodes.h" /* for other headers */ --- 26 unchanged lines hidden (view full) --- 74MKINIT char sigmode[NSIG]; /* current value of signal */ 75int pendingsigs; /* indicates some signal received */ 76int in_dotrap; /* do we execute in a trap handler? */ 77static char *volatile trap[NSIG]; /* trap handler commands */ 78static volatile sig_atomic_t gotsig[NSIG]; 79 /* indicates specified signal received */ 80static int ignore_sigchld; /* Used while handling SIGCHLD traps. */ 81volatile sig_atomic_t gotwinch; |
82static int last_trapsig; |
|
82 83static int exiting; /* exitshell() has been called */ 84static int exiting_exitstatus; /* value passed to exitshell() */ 85 86static int getsigaction(int, sig_t *); 87 88 89/* --- 346 unchanged lines hidden (view full) --- 436 if (trap[i]) { 437 /* 438 * Ignore SIGCHLD to avoid infinite 439 * recursion if the trap action does 440 * a fork. 441 */ 442 if (i == SIGCHLD) 443 ignore_sigchld++; | 83 84static int exiting; /* exitshell() has been called */ 85static int exiting_exitstatus; /* value passed to exitshell() */ 86 87static int getsigaction(int, sig_t *); 88 89 90/* --- 346 unchanged lines hidden (view full) --- 437 if (trap[i]) { 438 /* 439 * Ignore SIGCHLD to avoid infinite 440 * recursion if the trap action does 441 * a fork. 442 */ 443 if (i == SIGCHLD) 444 ignore_sigchld++; |
445 last_trapsig = i; |
|
444 savestatus = exitstatus; 445 evalstring(trap[i], 0); 446 exitstatus = savestatus; 447 if (i == SIGCHLD) 448 ignore_sigchld--; 449 } 450 break; 451 } --- 38 unchanged lines hidden (view full) --- 490 exitshell_savedstatus(); 491} 492 493void 494exitshell_savedstatus(void) 495{ 496 struct jmploc loc1, loc2; 497 char *p; | 446 savestatus = exitstatus; 447 evalstring(trap[i], 0); 448 exitstatus = savestatus; 449 if (i == SIGCHLD) 450 ignore_sigchld--; 451 } 452 break; 453 } --- 38 unchanged lines hidden (view full) --- 492 exitshell_savedstatus(); 493} 494 495void 496exitshell_savedstatus(void) 497{ 498 struct jmploc loc1, loc2; 499 char *p; |
500 int sig = 0; 501 sigset_t sigs; |
|
498 | 502 |
499 if (!exiting) 500 exiting_exitstatus = oexitstatus; | 503 if (!exiting) { 504 if (in_dotrap && last_trapsig) { 505 sig = last_trapsig; 506 exiting_exitstatus = sig + 128; 507 } else 508 exiting_exitstatus = oexitstatus; 509 } |
501 exitstatus = oexitstatus = exiting_exitstatus; 502 if (setjmp(loc1.loc)) { 503 goto l1; 504 } 505 if (setjmp(loc2.loc)) { 506 goto l2; 507 } 508 handler = &loc1; 509 if ((p = trap[0]) != NULL && *p != '\0') { 510 trap[0] = NULL; 511 evalstring(p, 0); 512 } 513l1: handler = &loc2; /* probably unnecessary */ 514 flushall(); 515#if JOBS 516 setjobctl(0); 517#endif | 510 exitstatus = oexitstatus = exiting_exitstatus; 511 if (setjmp(loc1.loc)) { 512 goto l1; 513 } 514 if (setjmp(loc2.loc)) { 515 goto l2; 516 } 517 handler = &loc1; 518 if ((p = trap[0]) != NULL && *p != '\0') { 519 trap[0] = NULL; 520 evalstring(p, 0); 521 } 522l1: handler = &loc2; /* probably unnecessary */ 523 flushall(); 524#if JOBS 525 setjobctl(0); 526#endif |
518l2: _exit(exiting_exitstatus); | 527l2: 528 if (sig != 0 && sig != SIGSTOP && sig != SIGTSTP && sig != SIGTTIN && 529 sig != SIGTTOU) { 530 signal(sig, SIG_DFL); 531 sigemptyset(&sigs); 532 sigaddset(&sigs, sig); 533 sigprocmask(SIG_UNBLOCK, &sigs, NULL); 534 kill(getpid(), sig); 535 /* If the default action is to ignore, fall back to _exit(). */ 536 } 537 _exit(exiting_exitstatus); |
519} | 538} |