mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
DEBUG trap: restore status 2 trigger to skip command (re: d00b4b39)
So now we know what that faulty check for shp->indebug in sh_trap()
was meant to do: it was meant to pass down the trap handler's exit
status, via sh_debug(), down to sh_exec() (xec.c) so that it could
then skip the execution of the next command if the trap's exit
status is 2, as documented in the manual page. As of d00b4b39, exit
status 2 was not passed down, so this stopped working.
This commit reinstates that functionality, but without the exit
status bug in command substitutions caused by the old way.
src/cmd/ksh93/sh/fault.c: sh_trap():
- Save the trap's exit status before restoring the parent
envionment's exit status. Make this saved exit status the return
value of the function. (This does not break anything, AFAICT; the
majority of sh_trap() calls ignore the return value, and the few
that don't ignore it seem to expect it to return exactly this.)
src/cmd/ksh93/sh/xec.c: sh_exec():
- The sh_trap() fix has one side effect: whereas the exit status of
a skipped command was always 2 (as per the trap handler), now it
is always 0, because it gets reset in sh_exec() but no command is
executed. That is probably not a desirable change in behaviour,
so let's fix that here instead: set sh.exitval to 2 when skipping
commands.
src/cmd/ksh93/sh.1:
- Document that ${.sh.command} shell-quotes its arguments for use
by 'eval' and such. This fact was not documented anywhere, AFAIK.
src/cmd/ksh93/shell.3:
- Document that $? (exit status) is made local to trap handlers.
- Document that sh_trap() returns the trap handler's exit status.
src/cmd/ksh93/tests/basic.sh:
- Add test for this bug.
- Add a missing test for the exit status 255 functionality (if a
DEBUG trap handler yields this exit status and we're executing a
function or dot script, a return is triggered).
Fixes: https://github.com/ksh93/ksh/issues/187
This commit is contained in:
parent
2b805f7f1c
commit
a959a35291
6 changed files with 56 additions and 3 deletions
|
|
@ -442,11 +442,12 @@ void sh_chktrap(Shell_t* shp)
|
|||
/*
|
||||
* parse and execute the given trap string, stream or tree depending on mode
|
||||
* mode==0 for string, mode==1 for stream, mode==2 for parse tree
|
||||
* The return value is the exit status of the trap action.
|
||||
*/
|
||||
int sh_trap(const char *trap, int mode)
|
||||
{
|
||||
Shell_t *shp = sh_getinterp();
|
||||
int jmpval, savxit = shp->exitval;
|
||||
int jmpval, savxit = shp->exitval, savxit_return;
|
||||
int was_history = sh_isstate(SH_HISTORY);
|
||||
int was_verbose = sh_isstate(SH_VERBOSE);
|
||||
int staktop = staktell();
|
||||
|
|
@ -487,6 +488,7 @@ int sh_trap(const char *trap, int mode)
|
|||
sh_popcontext(shp,&buff);
|
||||
shp->intrap--;
|
||||
sfsync(shp->outpool);
|
||||
savxit_return = shp->exitval;
|
||||
if(jmpval!=SH_JMPEXIT && jmpval!=SH_JMPFUN)
|
||||
shp->exitval=savxit;
|
||||
stakset(savptr,staktop);
|
||||
|
|
@ -498,7 +500,7 @@ int sh_trap(const char *trap, int mode)
|
|||
exitset();
|
||||
if(jmpval>SH_JMPTRAP && (((struct checkpt*)shp->jmpbuffer)->prev || ((struct checkpt*)shp->jmpbuffer)->mode==SH_JMPSCRIPT))
|
||||
siglongjmp(*shp->jmplist,jmpval);
|
||||
return(shp->exitval);
|
||||
return(savxit_return);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue