Skip to content

Commit

Permalink
stdout not proper if EXIT/ERR traphandler defined in commandline mode
Browse files Browse the repository at this point in the history
  • Loading branch information
citrus-it committed Jan 5, 2021
1 parent b4f25be commit aeee2c8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/cmd/ksh93/bltins/trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ int b_trap(int argc,char *argv[],Shbltin_t *context)
shp->trapnote |= SH_SIGTRAP;
else
shp->trapnote = 0;

}
if(sig == SH_ERRTRAP)
{
if(clear)
shp->errtrap = 0;
else
{
if(!shp->fn_depth || shp->end_fn)
shp->errtrap = 1;
}
}
continue;
}
Expand All @@ -144,6 +155,8 @@ int b_trap(int argc,char *argv[],Shbltin_t *context)
else if(clear)
{
sh_sigclear(sig);
if(sig == 0)
shp->exittrap = 0;
if(dflag)
signal(sig,SIG_DFL);
}
Expand All @@ -156,6 +169,11 @@ int b_trap(int argc,char *argv[],Shbltin_t *context)
shp->st.trapcom[sig] = (shp->sigflag[sig]&SH_SIGOFF) ? Empty : strdup(action);
if(arg && arg != Empty)
free(arg);
if(sig == 0)
{
if(!shp->fn_depth || shp->end_fn)
shp->exittrap = 1;
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/cmd/ksh93/include/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ struct shared
char *mathnodes; \
void *coshell; \
char *bltin_dir; \
struct Regress_s*regress;
struct Regress_s*regress; \
char exittrap; \
char errtrap; \
char end_fn;

#include <shell.h>

Expand Down
6 changes: 6 additions & 0 deletions src/cmd/ksh93/sh/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,9 @@ Shell_t *sh_init(register int argc,register char *argv[], Shinit_f userinit)
#endif
if(shp->userinit=userinit)
(*userinit)(shp, 0);
shp->exittrap = 0;
shp->errtrap = 0;
shp->end_fn = 0;
return(shp);
}

Expand Down Expand Up @@ -1686,6 +1689,9 @@ int sh_reinit(char *argv[])
shp->inpipe = shp->outpipe = 0;
job_clear();
job.in_critical = 0;
shp->exittrap = 0;
shp->errtrap = 0;
shp->end_fn = 0;
return(1);
}

Expand Down
3 changes: 3 additions & 0 deletions src/cmd/ksh93/sh/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ static void exfile(register Shell_t *shp, register Sfio_t *iop,register int fno)
error_info.line = 1;
shp->inlineno = 1;
shp->binscript = 0;
shp->exittrap = 0;
shp->errtrap = 0;
shp->end_fn = 0;
if(sfeof(iop))
goto eof_or_error;
/* command loop */
Expand Down
5 changes: 5 additions & 0 deletions src/cmd/ksh93/sh/xec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,8 @@ int sh_exec(register const Shnode_t *t, int flags)
shp->exitval=0;
shp->lastsig = 0;
shp->lastpath = 0;
if(shp->exittrap || shp->errtrap)
execflg = 0;
switch(type&COMMSK)
{
case TCOM:
Expand Down Expand Up @@ -3410,6 +3412,8 @@ int sh_funscope(int argn, char *argv[],int(*fun)(void*),void *arg,int execflg)
nv_putval(SH_PATHNAMENOD,shp->st.filename,NV_NOFREE);
nv_putval(SH_FUNNAMENOD,shp->st.funname,NV_NOFREE);
}
if((execflg & sh_state(SH_NOFORK)))
shp->end_fn = 1;
jmpval = sigsetjmp(buffp->buff,0);
if(jmpval == 0)
{
Expand Down Expand Up @@ -3457,6 +3461,7 @@ int sh_funscope(int argn, char *argv[],int(*fun)(void*),void *arg,int execflg)
shp->st = *prevscope;
shp->topscope = (Shscope_t*)prevscope;
nv_getval(sh_scoped(shp,IFSNOD));
shp->end_fn = 0;
if(nsig)
memcpy((char*)&shp->st.trapcom[0],savstak,nsig);
shp->trapnote=0;
Expand Down

0 comments on commit aeee2c8

Please sign in to comment.