From 2706eac45492b0fcdfc3cf104ac947e65d09ee25 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 7 Aug 2008 16:25:14 +0000 Subject: 25415: Make DEBUG_BEFORE_CMD the default. Reuse ERR_EXIT in DEBUG traps. Clean up trapreturn code. --- Src/init.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'Src/init.c') diff --git a/Src/init.c b/Src/init.c index f2dc99af7..d8a0dbc57 100644 --- a/Src/init.c +++ b/Src/init.c @@ -191,10 +191,6 @@ loop(int toplevel, int justonce) exit(lastval); if (((!interact || sourcelevel) && errflag) || retflag) break; - if (intrap && trapreturn >= 0) { - lastval = trapreturn; - trapreturn = 0; - } if (isset(SINGLECOMMAND) && toplevel) { if (sigtrapped[SIGEXIT]) dotrap(SIGEXIT); @@ -880,7 +876,8 @@ setupvals(void) lastmailcheck = time(NULL); locallevel = sourcelevel = 0; sfcontext = SFC_NONE; - trapreturn = 0; + trap_return = 0; + trap_state = TRAP_STATE_INACTIVE; noerrexit = -1; nohistsave = 1; dirstack = znewlinklist(); @@ -1060,6 +1057,7 @@ source(char *s) char *old_scriptname = scriptname, *us; unsigned char *ocs; int ocsp; + int otrap_return = trap_return, otrap_state = trap_state; if (!s || (!(prog = try_source_file((us = unmeta(s)))) && @@ -1090,6 +1088,13 @@ source(char *s) dosetopt(SHINSTDIN, 0, 1); scriptname = s; + /* + * The special return behaviour of traps shouldn't + * trigger in files sourced from traps; the return + * is just a return from the file. + */ + trap_state = TRAP_STATE_INACTIVE; + sourcelevel++; if (prog) { pushheap(); @@ -1100,6 +1105,9 @@ source(char *s) loop(0, 0); /* loop through the file to be sourced */ sourcelevel--; + trap_state = otrap_state; + trap_return = otrap_return; + /* restore the current shell state */ if (prog) freeeprog(prog); -- cgit 1.4.1