bin/sh/trap.c
void
dotrap(void)
{
	int i;
	int savestatus, prev_evalskip, prev_skipcount;

	in_dotrap++;
	for (;;) {
		for (i = 1; i < NSIG; i++) {
			if (gotsig[i]) {
				gotsig[i] = 0;
				if (trap[i]) {
					/*
					 * Ignore SIGCHLD to avoid infinite
					 * recursion if the trap action does
					 * a fork.
					 */
					if (i == SIGCHLD)
						ignore_sigchld++;

					/*
					 * Backup current evalskip
					 * state and reset it before
					 * executing a trap, so that the
					 * trap is not disturbed by an
					 * ongoing break/continue/return
					 * statement.
					 */
					prev_evalskip  = evalskip;
					prev_skipcount = skipcount;
					evalskip = 0;

					last_trapsig = i;
					savestatus = exitstatus;
					evalstring(trap[i], 0);
					exitstatus = savestatus;

					/*
					 * If such a command was not
					 * already in progress, allow a
					 * break/continue/return in the
					 * trap action to have an effect
					 * outside of it.
					 */
					if (prev_evalskip != 0) {
						evalskip  = prev_evalskip;
						skipcount = prev_skipcount;
					}

					if (i == SIGCHLD)
						ignore_sigchld--;
				}
				break;
			}
		}
		if (i >= NSIG)
			break;
	}
	in_dotrap--;
	pendingsigs = 0;
}
/*
 * Called to execute a trap.  Perhaps we should avoid entering new trap
 * handlers while we are executing a trap handler.
 */
Called to execute a trap.  Perhaps we should avoid entering new trap
handlers while we are executing a trap handler.
Called to execute a trap . Perhaps we should avoid entering new trap handlers while we are executing a trap handler .
void
dotrap(void)
{
	int i;
	int savestatus, prev_evalskip, prev_skipcount;
	in_dotrap++;
	for (;;) {
		for (i = 1; i < NSIG; i++) {
			if (gotsig[i]) {
				gotsig[i] = 0;
				if (trap[i]) {
					if (i == SIGCHLD)
						ignore_sigchld++;
					prev_evalskip  = evalskip;
					prev_skipcount = skipcount;
					evalskip = 0;
					last_trapsig = i;
					savestatus = exitstatus;
					evalstring(trap[i], 0);
					exitstatus = savestatus;
					if (prev_evalskip != 0) {
						evalskip  = prev_evalskip;
						skipcount = prev_skipcount;
					}
					if (i == SIGCHLD)
						ignore_sigchld--;
				}
				break;
			}
		}
		if (i >= NSIG)
			break;
	}
	in_dotrap--;
	pendingsigs = 0;
}
void dotrap ( void ) { int i ; int savestatus , prev_evalskip , prev_skipcount ; in_dotrap ++ ; for ( ; ; ) { for ( i = 1 ; i < NSIG ; i ++ ) { if ( gotsig [ i ] ) { gotsig [ i ] = 0 ; if ( trap [ i ] ) { if ( i == SIGCHLD ) ignore_sigchld ++ ; prev_evalskip = evalskip ; prev_skipcount = skipcount ; evalskip = 0 ; last_trapsig = i ; savestatus = exitstatus ; evalstring ( trap [ i ] , 0 ) ; exitstatus = savestatus ; if ( prev_evalskip != 0 ) { evalskip = prev_evalskip ; skipcount = prev_skipcount ; } if ( i == SIGCHLD ) ignore_sigchld -- ; } break ; } } if ( i >= NSIG ) break ; } in_dotrap -- ; pendingsigs = 0 ; }
Called to execute a trap.
Called to execute a trap .
/*
					 * Ignore SIGCHLD to avoid infinite
					 * recursion if the trap action does
					 * a fork.
					 */ /*
					 * Backup current evalskip
					 * state and reset it before
					 * executing a trap, so that the
					 * trap is not disturbed by an
					 * ongoing break/continue/return
					 * statement.
					 */ /*
					 * If such a command was not
					 * already in progress, allow a
					 * break/continue/return in the
					 * trap action to have an effect
					 * outside of it.
					 */