From 172becffea7c24242714c848a5e210ddce7e3b70 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Tue, 25 Jan 2022 14:56:07 +0000 Subject: [PATCH] Some more accumulated minor tweaks and cleanups Notable changes: src/cmd/ksh93/include/fault.h: - Get rid of the superflous sh pointer argument in the sh_pushcontext() and sh_popcontext() macros. (re: 2d3ec8b6) src/cmd/ksh93/tests/io.sh: - Tweak a process substitution test to allow up to a second for unused process substitution processes to disappear. On the Alpine Linux console (at least the musl libc version), this is needed to avoid a test failure as long as no GUI is active. As soon as you start X11, this phenomenon disappears, even on the console. Very strange, but also very probably not ksh's fault. src/cmd/ksh93/tests/shtests: - Instead of just SIGCONT and SIGPIPE, set all signals to default, just to be sure to avoid spurious test failures due to signals that were ignored on entry. (It made no difference to the aforementioned Alpine Linux test failure, so ignored signals had nothing to do with that -- but still a good idea.) .github/workflows/ci.yml: - On the GitHub CI runs, when testing with SHOPTs disabled, disable SHOPT_SPAWN as well, which tests that everything still works correctly with the regular fork(2) method. COPYRIGHT: - Remove duplicate of BSD license. --- .github/workflows/ci.yml | 2 +- COPYRIGHT | 32 --------------------- src/cmd/ksh93/Mamfile | 6 ++-- src/cmd/ksh93/README | 4 +-- src/cmd/ksh93/RELEASE | 2 +- src/cmd/ksh93/RELEASE93 | 2 +- src/cmd/ksh93/bltins/getopts.c | 6 ++-- src/cmd/ksh93/bltins/misc.c | 4 +-- src/cmd/ksh93/bltins/read.c | 4 +-- src/cmd/ksh93/bltins/typeset.c | 4 +-- src/cmd/ksh93/data/builtins.c | 2 +- src/cmd/ksh93/edit/edit.c | 1 - src/cmd/ksh93/edit/emacs.c | 5 ---- src/cmd/ksh93/edit/hexpand.c | 1 - src/cmd/ksh93/include/fault.h | 20 +++++++++---- src/cmd/ksh93/include/nval.h | 2 +- src/cmd/ksh93/sh.memo | 4 +-- src/cmd/ksh93/sh/fault.c | 4 +-- src/cmd/ksh93/sh/init.c | 2 +- src/cmd/ksh93/sh/lex.c | 1 - src/cmd/ksh93/sh/macro.c | 8 +++--- src/cmd/ksh93/sh/main.c | 4 +-- src/cmd/ksh93/sh/name.c | 1 - src/cmd/ksh93/sh/nvdisc.c | 8 +++--- src/cmd/ksh93/sh/nvtree.c | 1 - src/cmd/ksh93/sh/parse.c | 5 ++-- src/cmd/ksh93/sh/subshell.c | 6 ++-- src/cmd/ksh93/sh/xec.c | 48 ++++++++++++++++---------------- src/cmd/ksh93/tests/functions.sh | 1 - src/cmd/ksh93/tests/io.sh | 7 ++++- src/cmd/ksh93/tests/shtests | 2 +- src/cmd/ksh93/tests/substring.sh | 1 - src/lib/libast/disc/sfdcprefix.c | 1 - src/lib/libcmd/stty.c | 1 - 34 files changed, 84 insertions(+), 118 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c0d0217a4..303a4ad3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: LANG=ja_JP.SJIS script -q -e -c "bin/shtests --locale --nocompile" && : disable most SHOPTs, rebuild ksh && sed --regexp-extended --in-place=.orig \ - '/^SHOPT (2DMATCH|AUDIT|BGX|BRACEPAT|DEVFD|DYNAMIC|EDPREDICT|ESH|FIXEDARRAY|HISTEXPAND|MULTIBYTE|NAMESPACE|OPTIMIZE|STATS|SUID_EXEC|VSH)=/ s/=1?/=0/' \ + '/^SHOPT (2DMATCH|AUDIT|BGX|BRACEPAT|DEVFD|DYNAMIC|EDPREDICT|ESH|FIXEDARRAY|HISTEXPAND|MULTIBYTE|NAMESPACE|OPTIMIZE|SPAWN|STATS|SUID_EXEC|VSH)=/ s/=1?/=0/' \ src/cmd/ksh93/SHOPT.sh && bin/package make && : default regression tests with SHOPTs disabled && diff --git a/COPYRIGHT b/COPYRIGHT index c34e6ddf7..ef1e8eb2b 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -82,38 +82,6 @@ bsd package general copyright notice # This software is part of the BSD package # # Copyright (c) 1979-2012 The Regents of the University of California # # # -# Redistribution and use in source and binary forms, with or # -# without modification, are permitted provided that the following # -# conditions are met: # -# # -# 1. Redistributions of source code must retain the above # -# copyright notice, this list of conditions and the # -# following disclaimer. # -# # -# 2. Redistributions in binary form must reproduce the above # -# copyright notice, this list of conditions and the # -# following disclaimer in the documentation and/or other # -# materials provided with the distribution. # -# # -# 3. Neither the name of The Regents of the University of California# -# names of its contributors may be used to endorse or # -# promote products derived from this software without # -# specific prior written permission. # -# # -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND # -# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, # -# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # -# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS # -# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, # -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED # -# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON # -# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # -# POSSIBILITY OF SUCH DAMAGE. # -# # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions # # are met: # diff --git a/src/cmd/ksh93/Mamfile b/src/cmd/ksh93/Mamfile index d604c138e..80f7132d1 100644 --- a/src/cmd/ksh93/Mamfile +++ b/src/cmd/ksh93/Mamfile @@ -659,7 +659,7 @@ make install meta main.o %.c>%.o sh/main.c main prev sh/main.c prev SHOPT.sh - exec - ${CC} ${mam_cc_FLAGS} ${SHOPT_TIMEOUT+-DSHOPT_TIMEOUT=${SHOPT_TIMEOUT}} ${SHOPT_ACCT+-DSHOPT_ACCT=${SHOPT_ACCT}} ${SHOPT_SYSRC+-DSHOPT_SYSRC=${SHOPT_SYSRC}} ${SHOPT_REMOTE+-DSHOPT_REMOTE=${SHOPT_REMOTE}} ${SHOPT_OLDTERMIO+-DSHOPT_OLDTERMIO=${SHOPT_OLDTERMIO}} ${SHOPT_SPAWN+-DSHOPT_SPAWN=${SHOPT_SPAWN}} ${SHOPT_P_SUID+-DSHOPT_P_SUID=${SHOPT_P_SUID}} ${SHOPT_REGRESS+-DSHOPT_REGRESS=${SHOPT_REGRESS}} ${KSH_RELFLAGS} ${KSH_SHOPTFLAGS} ${CCFLAGS} ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${CCFLAGS.FORCE}?} ${DEBUG+-DDEBUG=${DEBUG}} -DSH_DICT=${SH_DICT} ${SH_CMDLIB_DIR+-DSH_CMDLIB_DIR=${SH_CMDLIB_DIR}} -I. -Iinclude -I${PACKAGE_ast_INCLUDE} -D_API_ast=20100309 -D_PACKAGE_ast -DERROR_CONTEXT_T=Error_context_t -c sh/main.c + exec - ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${KSH_SHOPTFLAGS} ${CCFLAGS} ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${CCFLAGS.FORCE}?} ${DEBUG+-DDEBUG=${DEBUG}} -DSH_DICT=${SH_DICT} ${SH_CMDLIB_DIR+-DSH_CMDLIB_DIR=${SH_CMDLIB_DIR}} -I. -Iinclude -I${PACKAGE_ast_INCLUDE} -D_API_ast=20100309 -D_PACKAGE_ast -DERROR_CONTEXT_T=Error_context_t -c sh/main.c done main.o generated make nvdisc.o make sh/nvdisc.c @@ -1147,7 +1147,7 @@ make install meta trestore.o %.c>%.o sh/trestore.c trestore prev sh/trestore.c prev SHOPT.sh - exec - ${CC} ${mam_cc_FLAGS} ${SHOPT_SYSRC+-DSHOPT_SYSRC=${SHOPT_SYSRC}} ${SHOPT_ACCT+-DSHOPT_ACCT=${SHOPT_ACCT}} ${SHOPT_SPAWN+-DSHOPT_SPAWN=${SHOPT_SPAWN}} ${SHOPT_P_SUID+-DSHOPT_P_SUID=${SHOPT_P_SUID}} ${SHOPT_REGRESS+-DSHOPT_REGRESS=${SHOPT_REGRESS}} ${KSH_RELFLAGS} ${KSH_SHOPTFLAGS} ${CCFLAGS} ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${CCFLAGS.FORCE}?} ${SH_CMDLIB_DIR+-DSH_CMDLIB_DIR=${SH_CMDLIB_DIR}} -DSH_DICT=${SH_DICT} -I. -Iinclude -I${PACKAGE_ast_INCLUDE} -D_API_ast=20100309 -D_PACKAGE_ast -DERROR_CONTEXT_T=Error_context_t -c sh/trestore.c + exec - ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${KSH_SHOPTFLAGS} ${CCFLAGS} ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${CCFLAGS.FORCE}?} ${SH_CMDLIB_DIR+-DSH_CMDLIB_DIR=${SH_CMDLIB_DIR}} -DSH_DICT=${SH_DICT} -I. -Iinclude -I${PACKAGE_ast_INCLUDE} -D_API_ast=20100309 -D_PACKAGE_ast -DERROR_CONTEXT_T=Error_context_t -c sh/trestore.c done trestore.o generated make waitevent.o make sh/waitevent.c @@ -1235,7 +1235,7 @@ make install meta strdata.o %.c>%.o data/strdata.c strdata prev data/strdata.c prev SHOPT.sh - exec - ${CC} ${mam_cc_FLAGS} ${SHOPT_P_SUID+-DSHOPT_P_SUID=${SHOPT_P_SUID}} ${SHOPT_REGRESS+-DSHOPT_REGRESS=${SHOPT_REGRESS}} ${KSH_RELFLAGS} ${KSH_SHOPTFLAGS} ${CCFLAGS} ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${CCFLAGS.FORCE}?} ${SH_CMDLIB_DIR+-DSH_CMDLIB_DIR=${SH_CMDLIB_DIR}} -DSH_DICT=${SH_DICT} -I. -Iinclude -I${PACKAGE_ast_INCLUDE} -D_API_ast=20100309 -D_PACKAGE_ast -DERROR_CONTEXT_T=Error_context_t -c data/strdata.c + exec - ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${KSH_SHOPTFLAGS} ${CCFLAGS} ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${CCFLAGS.FORCE}?} ${SH_CMDLIB_DIR+-DSH_CMDLIB_DIR=${SH_CMDLIB_DIR}} -DSH_DICT=${SH_DICT} -I. -Iinclude -I${PACKAGE_ast_INCLUDE} -D_API_ast=20100309 -D_PACKAGE_ast -DERROR_CONTEXT_T=Error_context_t -c data/strdata.c done strdata.o generated make testops.o make data/testops.c diff --git a/src/cmd/ksh93/README b/src/cmd/ksh93/README index 32ea082d0..baeb1f21f 100644 --- a/src/cmd/ksh93/README +++ b/src/cmd/ksh93/README @@ -143,7 +143,7 @@ The options have the following defaults and meanings: SPAWN on Use posix_spawn(3) as combined fork/exec if job control is not active. Improves speed. - STATS on Add .sh.stats compound variable. + STATS on Add .sh.stats compound variable. SUID_EXEC on Execute /etc/suid_exec for setuid, setgid script. @@ -158,7 +158,7 @@ The options have the following defaults and meanings: exiting the shell when you don't enter a command. If non-zero, TMOUT can not be set larger than this value. - TYPEDEF on Enable typeset type definitions. + TYPEDEF on Enable typeset type definitions. VSH on Compile with vi command line editing. The original vi line editor code was provided by Pat Sullivan at CB. diff --git a/src/cmd/ksh93/RELEASE b/src/cmd/ksh93/RELEASE index ec1be0108..30432d3c9 100644 --- a/src/cmd/ksh93/RELEASE +++ b/src/cmd/ksh93/RELEASE @@ -2573,7 +2573,7 @@ ____ directory of the script has been fixed. 01-02-19 A shell script did not always pick up tty mode changes made by external commands such as stty which could - effect the behavior of read. + affect the behavior of read. 01-02-19 The -u, -g, and -k unary tests did not give the correct results when used with negation and this has been fixed. diff --git a/src/cmd/ksh93/RELEASE93 b/src/cmd/ksh93/RELEASE93 index afd108065..39f0c701a 100644 --- a/src/cmd/ksh93/RELEASE93 +++ b/src/cmd/ksh93/RELEASE93 @@ -339,7 +339,7 @@ of ksh. the variable it references was the subject of a compound assignment has been fixed. e. A bug which in which assignment to array variables in - a subshell could effect the parent shell has been + a subshell could affect the parent shell has been fixed. f. read name?prompt was putting a 0 byte at the end of the prompt on standard error. diff --git a/src/cmd/ksh93/bltins/getopts.c b/src/cmd/ksh93/bltins/getopts.c index 68e737305..b329ae9e8 100644 --- a/src/cmd/ksh93/bltins/getopts.c +++ b/src/cmd/ksh93/bltins/getopts.c @@ -106,11 +106,11 @@ int b_getopts(int argc,char *argv[],Shbltin_t *context) if(mode= (*options==':')) options++; extended = *options=='\n' && *(options+1)=='[' || *options=='[' && *(options+1)=='-'; - sh_pushcontext(&sh,&buff,1); + sh_pushcontext(&buff,1); jmpval = sigsetjmp(buff.buff,0); if(jmpval) { - sh_popcontext(&sh,&buff); + sh_popcontext(&buff); sh.st.opterror = 1; if(r==0) return(2); @@ -199,7 +199,7 @@ int b_getopts(int argc,char *argv[],Shbltin_t *context) else nv_putval(np, opt_info.arg, NV_RDONLY); nv_close(np); - sh_popcontext(&sh,&buff); + sh_popcontext(&buff); opt_info.disc = 0; return(r); } diff --git a/src/cmd/ksh93/bltins/misc.c b/src/cmd/ksh93/bltins/misc.c index 34ab787a5..c096f495b 100644 --- a/src/cmd/ksh93/bltins/misc.c +++ b/src/cmd/ksh93/bltins/misc.c @@ -309,7 +309,7 @@ int b_dot_cmd(register int n,char *argv[],Shbltin_t *context) sh.posix_fun = 0; if(np || argv[1]) argsave = sh_argnew(argv,&saveargfor); - sh_pushcontext(&sh,&buff,SH_JMPDOT); + sh_pushcontext(&buff,SH_JMPDOT); jmpval = sigsetjmp(buff.buff,0); if(jmpval == 0) { @@ -324,7 +324,7 @@ int b_dot_cmd(register int n,char *argv[],Shbltin_t *context) sh_eval(iop,sh_isstate(SH_PROFILE)?SH_FUNEVAL:0); } } - sh_popcontext(&sh,&buff); + sh_popcontext(&buff); if(buffer) free(buffer); if(!np) diff --git a/src/cmd/ksh93/bltins/read.c b/src/cmd/ksh93/bltins/read.c index 0c652ce68..9269b04f9 100644 --- a/src/cmd/ksh93/bltins/read.c +++ b/src/cmd/ksh93/bltins/read.c @@ -347,7 +347,7 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, long tim was_share = (sfset(iop,SF_SHARE,sh.redir0!=2)&SF_SHARE)!=0; if(timeout || (sh.fdstatus[fd]&(IOTTY|IONOSEEK))) { - sh_pushcontext(&sh,&buff,1); + sh_pushcontext(&buff,1); jmpval = sigsetjmp(buff.buff,0); if(jmpval) goto done; @@ -829,7 +829,7 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, long tim } done: if(timeout || (sh.fdstatus[fd]&(IOTTY|IONOSEEK))) - sh_popcontext(&sh,&buff); + sh_popcontext(&buff); if(was_write) sfset(iop,SF_WRITE,1); if(!was_share) diff --git a/src/cmd/ksh93/bltins/typeset.c b/src/cmd/ksh93/bltins/typeset.c index f55496718..e54f1e8fe 100644 --- a/src/cmd/ksh93/bltins/typeset.c +++ b/src/cmd/ksh93/bltins/typeset.c @@ -1324,7 +1324,7 @@ static int unall(int argc, char **argv, register Dt_t *troot) } while(name = *argv++) { - sh_pushcontext(&sh,&buff,1); + sh_pushcontext(&buff,1); jmpval = sigsetjmp(buff.buff,0); np = 0; if(jmpval==0) @@ -1336,7 +1336,7 @@ static int unall(int argc, char **argv, register Dt_t *troot) #endif /* SHOPT_NAMESPACE */ np=nv_open(name,troot,NV_NOADD|nflag); } - sh_popcontext(&sh,&buff); + sh_popcontext(&buff); if(jmpval) { r = 1; diff --git a/src/cmd/ksh93/data/builtins.c b/src/cmd/ksh93/data/builtins.c index f88829950..3948a618d 100644 --- a/src/cmd/ksh93/data/builtins.c +++ b/src/cmd/ksh93/data/builtins.c @@ -372,7 +372,7 @@ const char sh_optalias[] = "field splitting and pathname expansion are not performed on " "the arguments. Tilde expansion occurs on \avalue\a. An alias " "definition only affects scripts read by the current shell " - "environment. It does not effect scripts run by this shell.]" + "environment. It does not affect scripts run by this shell.]" "[p?Causes the output to be in the form of alias commands that can be used " "as input to the shell to recreate the current aliases.]" "[t?Each \aname\a is looked up as a command in \b$PATH\b and its path is " diff --git a/src/cmd/ksh93/edit/edit.c b/src/cmd/ksh93/edit/edit.c index 45684dad8..23839fc62 100644 --- a/src/cmd/ksh93/edit/edit.c +++ b/src/cmd/ksh93/edit/edit.c @@ -1716,7 +1716,6 @@ static int ed_histlencopy(const char *cp, char *dp) *dp++ = *oldcp++; } } - } return(n); } diff --git a/src/cmd/ksh93/edit/emacs.c b/src/cmd/ksh93/edit/emacs.c index 03bf08863..a19f7d12c 100644 --- a/src/cmd/ksh93/edit/emacs.c +++ b/src/cmd/ksh93/edit/emacs.c @@ -714,7 +714,6 @@ update: draw(ep,UPDATE); continue; } - } process: @@ -880,7 +879,6 @@ static int escape(register Emacs_t* ep,register genchar *out,int count) } } - case 'b': /* M-b == go backward one word */ case DELETE : case '\b': @@ -1429,9 +1427,7 @@ static void draw(register Emacs_t *ep,Draw_t option) if ((lookahead)&&(option != FINAL)) { - ep->scvalid = 0; /* Screen is out of date, APPEND will not work */ - return; } @@ -1441,7 +1437,6 @@ static void draw(register Emacs_t *ep,Draw_t option) and the window has room for another character, then output the character and adjust the screen only. *****************************************/ - if(logcursor > drawbuff) i = *(logcursor-1); /* last character inserted */ diff --git a/src/cmd/ksh93/edit/hexpand.c b/src/cmd/ksh93/edit/hexpand.c index 517e5671e..306956d87 100644 --- a/src/cmd/ksh93/edit/hexpand.c +++ b/src/cmd/ksh93/edit/hexpand.c @@ -301,7 +301,6 @@ getline: flag |= HIST_EVENT; if(str) /* !string or !?string? event designator */ { - /* search history for string */ hl = hist_find(sh.hist_ptr, str, sh.hist_ptr->histind, diff --git a/src/cmd/ksh93/include/fault.h b/src/cmd/ksh93/include/fault.h index e0f66c3a2..5787e399f 100644 --- a/src/cmd/ksh93/include/fault.h +++ b/src/cmd/ksh93/include/fault.h @@ -101,12 +101,20 @@ struct checkpt Error_context_t err; }; -#define sh_pushcontext(shp,bp,n)( (bp)->mode=(n) , (bp)->olist=0, \ - (bp)->topfd=(shp)->topfd, (bp)->prev=(shp)->jmplist, \ - (bp)->err = *ERROR_CONTEXT_BASE, \ - (shp)->jmplist = (sigjmp_buf*)(&(bp)->buff) \ - ) -#define sh_popcontext(shp,bp) ((shp)->jmplist=(bp)->prev, errorpop(&((bp)->err))) +#define sh_pushcontext(bp,n) \ +( \ + (bp)->mode = (n), \ + (bp)->olist = 0, \ + (bp)->topfd = sh.topfd, \ + (bp)->prev = sh.jmplist, \ + (bp)->err = *ERROR_CONTEXT_BASE, \ + sh.jmplist = (sigjmp_buf*)(&(bp)->buff) \ +) +#define sh_popcontext(bp) \ +( \ + sh.jmplist = (bp)->prev, \ + errorpop(&((bp)->err)) \ +) extern noreturn void sh_done(int); extern void sh_fault(int); diff --git a/src/cmd/ksh93/include/nval.h b/src/cmd/ksh93/include/nval.h index 3997abe5a..a272c7079 100644 --- a/src/cmd/ksh93/include/nval.h +++ b/src/cmd/ksh93/include/nval.h @@ -153,7 +153,7 @@ struct Namval #define NV_RAW NV_LJUST /* used only with NV_BINARY */ #define NV_HOST (NV_RJUST|NV_LJUST) /* map to host filename */ -/* The following attributes do not effect the value */ +/* The following attributes do not affect the value */ #define NV_RDONLY 0x1 /* readonly bit */ #define NV_EXPORT 0x2000 /* export bit */ #define NV_TAGGED 0x8000 /* user define tag bit */ diff --git a/src/cmd/ksh93/sh.memo b/src/cmd/ksh93/sh.memo index 2c6663dc0..f4e4ad110 100644 --- a/src/cmd/ksh93/sh.memo +++ b/src/cmd/ksh93/sh.memo @@ -389,7 +389,7 @@ procedure (the shell equivalent of an include file) is read all at once (unlike start up files which are read a command at -a time) so that any aliases defined there will not effect any commands +a time) so that any aliases defined there will not affect any commands within this script. Predefined aliases do not have this problem. .H 2 "Command Re-entry" @@ -2680,7 +2680,7 @@ part of the language rather than user definable commands. The best examples of commands that fit this description are \f5break\fP and \f5continue\fP. Because they are not reserved words, they can be the -result of shell expansions and are not effected by quoting. +result of shell expansions and are not affected by quoting. These commands have the following special properties: .BL .LI diff --git a/src/cmd/ksh93/sh/fault.c b/src/cmd/ksh93/sh/fault.c index 21d836f22..6f351a1cc 100644 --- a/src/cmd/ksh93/sh/fault.c +++ b/src/cmd/ksh93/sh/fault.c @@ -464,7 +464,7 @@ int sh_trap(const char *trap, int mode) sh_offstate(SH_HISTORY); sh_offstate(SH_VERBOSE); sh.intrap++; - sh_pushcontext(&sh,&buff,SH_JMPTRAP); + sh_pushcontext(&buff,SH_JMPTRAP); jmpval = sigsetjmp(buff.buff,0); if(jmpval == 0) { @@ -491,7 +491,7 @@ int sh_trap(const char *trap, int mode) jmpval=SH_JMPTRAP; } } - sh_popcontext(&sh,&buff); + sh_popcontext(&buff); sh.intrap--; sfsync(sh.outpool); savxit_return = sh.exitval; diff --git a/src/cmd/ksh93/sh/init.c b/src/cmd/ksh93/sh/init.c index 4ae2d8a44..68e41210b 100644 --- a/src/cmd/ksh93/sh/init.c +++ b/src/cmd/ksh93/sh/init.c @@ -1449,7 +1449,7 @@ Shell_t *sh_init(register int argc,register char *argv[], Shinit_f userinit) */ error_info.id = sh_strdup(sh.st.dolv[0]); /* error_info.id is $0 */ sh.jmpbuffer = (void*)&sh.checkbase; - sh_pushcontext(&sh,&sh.checkbase,SH_JMPSCRIPT); + sh_pushcontext(&sh.checkbase,SH_JMPSCRIPT); sh.st.self = &sh.global; sh.topscope = (Shscope_t*)sh.st.self; sh_offstate(SH_INIT); diff --git a/src/cmd/ksh93/sh/lex.c b/src/cmd/ksh93/sh/lex.c index 915b3f8f2..56c5735c9 100644 --- a/src/cmd/ksh93/sh/lex.c +++ b/src/cmd/ksh93/sh/lex.c @@ -1536,7 +1536,6 @@ static int comsub(register Lex_t *lp, int endtok) { if(endtok==LPAREN && lp->lexd.paren) { - if(first==lp->lexd.first) { n = cp+1-(char*)fcseek(0); diff --git a/src/cmd/ksh93/sh/macro.c b/src/cmd/ksh93/sh/macro.c index b1a61e96d..eacc07623 100644 --- a/src/cmd/ksh93/sh/macro.c +++ b/src/cmd/ksh93/sh/macro.c @@ -130,11 +130,11 @@ char *sh_mactry(register char *string) int savexit = sh.savexit; struct checkpt buff; Lex_t *lexp = (Lex_t*)sh.lex_context, savelex = *lexp; - sh_pushcontext(&sh,&buff,SH_JMPSUB); + sh_pushcontext(&buff,SH_JMPSUB); jmp_val = sigsetjmp(buff.buff,0); if(jmp_val == 0) string = sh_mactrim(string,0); - sh_popcontext(&sh,&buff); + sh_popcontext(&buff); *lexp = savelex; sh.savexit = savexit; return(string); @@ -2156,14 +2156,14 @@ static void comsubst(Mac_t *mp,register Shnode_t* t, int type) int r=0; struct checkpt buff; struct ionod *ip=0; - sh_pushcontext(&sh,&buff,SH_JMPIO); + sh_pushcontext(&buff,SH_JMPIO); if((ip=t->tre.treio) && ((ip->iofile&IOLSEEK) || !(ip->iofile&IOUFD)) && (r=sigsetjmp(buff.buff,0))==0) fd = sh_redirect(ip,3); else fd = sh_chkopen(e_devnull); - sh_popcontext(&sh,&buff); + sh_popcontext(&buff); if(r==0 && ip && (ip->iofile&IOLSEEK)) { if(sp=sh.sftable[fd]) diff --git a/src/cmd/ksh93/sh/main.c b/src/cmd/ksh93/sh/main.c index 14ce271a0..89e3ccbd4 100644 --- a/src/cmd/ksh93/sh/main.c +++ b/src/cmd/ksh93/sh/main.c @@ -365,7 +365,7 @@ static void exfile(register Sfio_t *iop,register int fno) int maxtry=IOMAXTRY, tdone=0, execflags; int states,jmpval; struct checkpt buff; - sh_pushcontext(&sh,&buff,SH_JMPERREXIT); + sh_pushcontext(&buff,SH_JMPERREXIT); /* open input stream */ nv_putval(SH_PATHNAMENOD, sh.st.filename, NV_NOFREE); if(!iop) @@ -600,7 +600,7 @@ static void exfile(register Sfio_t *iop,register int fno) } } done: - sh_popcontext(&sh,&buff); + sh_popcontext(&buff); if(sh_isstate(SH_INTERACTIVE)) { if(isatty(0) && !sh_isoption(SH_CFLAG)) diff --git a/src/cmd/ksh93/sh/name.c b/src/cmd/ksh93/sh/name.c index b04f66f55..4e6de3408 100644 --- a/src/cmd/ksh93/sh/name.c +++ b/src/cmd/ksh93/sh/name.c @@ -2565,7 +2565,6 @@ void _nv_unset(register Namval_t *np,int flags) up = np->nvalue.up; else if(nv_isref(np) && !nv_isattr(np,NV_EXPORT|NV_MINIMAL) && np->nvalue.nrp) { - if(np->nvalue.nrp->root && Refdict) dtdelete(Refdict,(void*)np->nvalue.nrp); if(np->nvalue.nrp->sub) diff --git a/src/cmd/ksh93/sh/nvdisc.c b/src/cmd/ksh93/sh/nvdisc.c index fcc0e5f19..45e8790ce 100644 --- a/src/cmd/ksh93/sh/nvdisc.c +++ b/src/cmd/ksh93/sh/nvdisc.c @@ -294,11 +294,11 @@ static void assign(Namval_t *np,const char* val,int flags,Namfun_t *handle) block(bp,type); if(bflag = (type==APPEND && !isblocked(bp,LOOKUPS))) block(bp,LOOKUPS); - sh_pushcontext(&sh, &checkpoint, 1); + sh_pushcontext(&checkpoint, 1); jmpval = sigsetjmp(checkpoint.buff, 0); if(!jmpval) sh_fun(nq,np,(char**)0); - sh_popcontext(&sh, &checkpoint); + sh_popcontext(&checkpoint); if(sh.topfd != checkpoint.topfd) sh_iorestore(checkpoint.topfd, jmpval); unblock(bp,type); @@ -410,11 +410,11 @@ static char* lookup(Namval_t *np, int type, Sfdouble_t *dp,Namfun_t *handle) } block(bp,type); block(bp, UNASSIGN); /* make sure nv_setdisc doesn't invalidate 'vp' by freeing it */ - sh_pushcontext(&sh, &checkpoint, 1); + sh_pushcontext(&checkpoint, 1); jmpval = sigsetjmp(checkpoint.buff, 0); if(!jmpval) sh_fun(nq,np,(char**)0); - sh_popcontext(&sh, &checkpoint); + sh_popcontext(&checkpoint); if(sh.topfd != checkpoint.topfd) sh_iorestore(checkpoint.topfd, jmpval); unblock(bp,UNASSIGN); diff --git a/src/cmd/ksh93/sh/nvtree.c b/src/cmd/ksh93/sh/nvtree.c index ccaf419fa..2e2ae1495 100644 --- a/src/cmd/ksh93/sh/nvtree.c +++ b/src/cmd/ksh93/sh/nvtree.c @@ -396,7 +396,6 @@ void nv_attribute(register Namval_t *np,Sfio_t *out,char *prefix,int noname) } if(np==typep) { - fp = 0; typep = 0; } diff --git a/src/cmd/ksh93/sh/parse.c b/src/cmd/ksh93/sh/parse.c index b0c61f0d6..4dddb72ed 100644 --- a/src/cmd/ksh93/sh/parse.c +++ b/src/cmd/ksh93/sh/parse.c @@ -771,7 +771,6 @@ static Shnode_t *arithfor(Lex_t *lexp,register Shnode_t *tf) tw->wh.dotre = sh_cmd(lexp,n==DOSYM?DONESYM:RBRACE,SH_NL|SH_SEMI); tw->wh.whtyp = TWH; return(tf); - } static Shnode_t *funct(Lex_t *lexp) @@ -875,7 +874,7 @@ static Shnode_t *funct(Lex_t *lexp) } if((flag && lexp->token!=LBRACE) || lexp->token==EOFSYM) sh_syntax(lexp); - sh_pushcontext(&sh,&buff,1); + sh_pushcontext(&buff,1); jmpval = sigsetjmp(buff.buff,0); if(jmpval == 0) { @@ -927,7 +926,7 @@ static Shnode_t *funct(Lex_t *lexp) } else if(sh.shcomp) exit(1); - sh_popcontext(&sh,&buff); + sh_popcontext(&buff); loop_level = saveloop; label_last = savelabel; /* restore the old stack */ diff --git a/src/cmd/ksh93/sh/subshell.c b/src/cmd/ksh93/sh/subshell.c index 33a487b19..fb343a37b 100644 --- a/src/cmd/ksh93/sh/subshell.c +++ b/src/cmd/ksh93/sh/subshell.c @@ -502,7 +502,7 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub) } sh.curenv = ++subenv; savst = sh.st; - sh_pushcontext(&sh,&checkpoint,SH_JMPSUB); + sh_pushcontext(&checkpoint,SH_JMPSUB); sh.subshell++; /* increase level of virtual subshells */ sh.realsubshell++; /* increase ${.sh.subshell} */ sp->prev = subshell_data; @@ -676,7 +676,7 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub) if(sh.subshell==0) /* we must have forked with sh_subfork(); this is the child process */ { subshell_data = sp->prev; - sh_popcontext(&sh,&checkpoint); + sh_popcontext(&checkpoint); if(jmpval==SH_JMPSCRIPT) siglongjmp(*sh.jmplist,jmpval); sh.exitval &= SH_EXITMASK; @@ -881,7 +881,7 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub) sh.subshell--; /* decrease level of virtual subshells */ sh.realsubshell--; /* decrease ${.sh.subshell} */ subshell_data = sp->prev; - sh_popcontext(&sh,&checkpoint); + sh_popcontext(&checkpoint); if(!argsav || argsav->dolrefcnt==argcnt) sh_argfree(argsav,0); if(sh.topfd != checkpoint.topfd) diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index eef18bcd5..bafcc23d4 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -687,7 +687,7 @@ int sh_eval(register Sfio_t *iop, int mode) mode ^= SH_TOPFUN; sh.fn_reset = 1; } - sh_pushcontext(&sh,buffp,SH_JMPEVAL); + sh_pushcontext(buffp,SH_JMPEVAL); buffp->olist = pp->olist; jmpval = sigsetjmp(buffp->buff,0); while(jmpval==0) @@ -718,7 +718,7 @@ int sh_eval(register Sfio_t *iop, int mode) if(!(mode&SH_FUNEVAL)) break; } - sh_popcontext(&sh,buffp); + sh_popcontext(buffp); sh.binscript = binscript; sh.comsub = comsub; if(traceon) @@ -1120,11 +1120,11 @@ int sh_exec(register const Shnode_t *t, int flags) { /* avoid exit on error from nv_setlist, e.g. read-only variable */ struct checkpt *chkp = (struct checkpt*)stakalloc(sizeof(struct checkpt)); - sh_pushcontext(&sh,chkp,SH_JMPCMD); + sh_pushcontext(chkp,SH_JMPCMD); jmpval = sigsetjmp(chkp->buff,1); if(!jmpval) nv_setlist(argp,flgs,tp); - sh_popcontext(&sh,chkp); + sh_popcontext(chkp); if(jmpval) /* error occurred */ goto setexit; } @@ -1272,7 +1272,7 @@ int sh_exec(register const Shnode_t *t, int flags) } if(execflg) sh_onstate(SH_NOFORK); - sh_pushcontext(&sh,buffp,SH_JMPCMD); + sh_pushcontext(buffp,SH_JMPCMD); jmpval = sigsetjmp(buffp->buff,1); if(jmpval == 0) { @@ -1422,7 +1422,7 @@ int sh_exec(register const Shnode_t *t, int flags) sfpool(sfstdin,NIL(Sfio_t*),SF_WRITE); sh.nextprompt = save_prompt; } - sh_popcontext(&sh,buffp); + sh_popcontext(buffp); errorpop(&buffp->err); error_info.flags &= ~(ERROR_SILENT|ERROR_NOTIFY); sh.bltinfun = 0; @@ -1507,7 +1507,7 @@ int sh_exec(register const Shnode_t *t, int flags) if(io) { indx = sh.topfd; - sh_pushcontext(&sh,buffp,SH_JMPIO); + sh_pushcontext(buffp,SH_JMPIO); jmpval = sigsetjmp(buffp->buff,0); } if(jmpval == 0) @@ -1537,7 +1537,7 @@ int sh_exec(register const Shnode_t *t, int flags) { if(buffp->olist) free_list(buffp->olist); - sh_popcontext(&sh,buffp); + sh_popcontext(buffp); sh_iorestore(indx,jmpval); } if(nq) @@ -1715,7 +1715,7 @@ int sh_exec(register const Shnode_t *t, int flags) #endif if(no_fork) sh_sigreset(2); - sh_pushcontext(&sh,buffp,SH_JMPEXIT); + sh_pushcontext(buffp,SH_JMPEXIT); jmpval = sigsetjmp(buffp->buff,0); if(jmpval) goto done; @@ -1826,7 +1826,7 @@ int sh_exec(register const Shnode_t *t, int flags) free(save_sh_fifo); } #endif - sh_popcontext(&sh,buffp); + sh_popcontext(buffp); if(jmpval>SH_JMPEXIT) siglongjmp(*sh.jmplist,jmpval); sh_done(0); @@ -1843,7 +1843,7 @@ int sh_exec(register const Shnode_t *t, int flags) int jmpval, waitall = 0; int simple = (t->fork.forktre->tre.tretyp&COMMSK)==TCOM; struct checkpt *buffp = (struct checkpt*)stkalloc(sh.stk,sizeof(struct checkpt)); - sh_pushcontext(&sh,buffp,SH_JMPIO); + sh_pushcontext(buffp,SH_JMPIO); if(type&FPIN) { was_interactive = sh_isstate(SH_INTERACTIVE); @@ -1877,7 +1877,7 @@ int sh_exec(register const Shnode_t *t, int flags) } else sfsync(sh.outpool); - sh_popcontext(&sh,buffp); + sh_popcontext(buffp); sh_iorestore(buffp->topfd,jmpval); if(buffp->olist) free_list(buffp->olist); @@ -1927,11 +1927,11 @@ int sh_exec(register const Shnode_t *t, int flags) sh_reseed_rand((struct rand*)RANDNOD->nvfun); sh.realsubshell++; sh_sigreset(0); - sh_pushcontext(&sh,buffp,SH_JMPEXIT); + sh_pushcontext(buffp,SH_JMPEXIT); jmpval = sigsetjmp(buffp->buff,0); if(jmpval==0) sh_exec(t->par.partre,flags); - sh_popcontext(&sh,buffp); + sh_popcontext(buffp); if(jmpval > SH_JMPEXIT) siglongjmp(*sh.jmplist,jmpval); if(sh.exitval > 256) @@ -2115,7 +2115,7 @@ int sh_exec(register const Shnode_t *t, int flags) void *optlist = sh.optlist; sh.optlist = 0; sh_tclear(t->for_.fortre); - sh_pushcontext(&sh,buffp,jmpval); + sh_pushcontext(buffp,jmpval); jmpval = sigsetjmp(buffp->buff,0); if(jmpval) goto endfor; @@ -2211,7 +2211,7 @@ int sh_exec(register const Shnode_t *t, int flags) } #if SHOPT_OPTIMIZE endfor: - sh_popcontext(&sh,buffp); + sh_popcontext(buffp); sh_tclear(t->for_.fortre); sh_optclear(optlist); if(jmpval) @@ -2243,7 +2243,7 @@ int sh_exec(register const Shnode_t *t, int flags) sh.optlist = 0; sh_tclear(t->wh.whtre); sh_tclear(t->wh.dotre); - sh_pushcontext(&sh,buffp,jmpval); + sh_pushcontext(buffp,jmpval); jmpval = sigsetjmp(buffp->buff,0); if(jmpval) goto endwhile; @@ -2284,7 +2284,7 @@ int sh_exec(register const Shnode_t *t, int flags) } #if SHOPT_OPTIMIZE endwhile: - sh_popcontext(&sh,buffp); + sh_popcontext(buffp); sh_tclear(t->wh.whtre); sh_tclear(t->wh.dotre); sh_optclear(optlist); @@ -3178,7 +3178,7 @@ int sh_funscope(int argn, char *argv[],int(*fun)(void*),void *arg,int execflg) } sh_sigreset(0); argsav = sh_argnew(argv,&saveargfor); - sh_pushcontext(&sh,buffp,SH_JMPFUN); + sh_pushcontext(buffp,SH_JMPFUN); errorpush(&buffp->err,0); error_info.id = argv[0]; sh.st.var_local = sh.var_tree; @@ -3232,7 +3232,7 @@ int sh_funscope(int argn, char *argv[],int(*fun)(void*),void *arg,int execflg) errormsg(SH_DICT,ERROR_exit(1),e_toodeep,argv[0]); UNREACHABLE(); } - sh_popcontext(&sh,buffp); + sh_popcontext(buffp); sh_unscope(); sh.namespace = nspace; sh.var_tree = (Dt_t*)prevscope->save_tree; @@ -3379,7 +3379,7 @@ int sh_fun(Namval_t *np, Namval_t *nq, char *argv[]) int jmpval; struct checkpt *buffp = (struct checkpt*)stkalloc(sh.stk,sizeof(struct checkpt)); Shbltin_t *bp = &sh.bltindata; - sh_pushcontext(&sh,buffp,SH_JMPCMD); + sh_pushcontext(buffp,SH_JMPCMD); jmpval = sigsetjmp(buffp->buff,1); if(jmpval == 0) { @@ -3392,7 +3392,7 @@ int sh_fun(Namval_t *np, Namval_t *nq, char *argv[]) sh.exitval = 0; sh.exitval = ((Shbltin_f)funptr(np))(n,argv,bp); } - sh_popcontext(&sh,buffp); + sh_popcontext(buffp); if(jmpval>SH_JMPCMD) siglongjmp(*sh.jmplist,jmpval); } @@ -3484,7 +3484,7 @@ static pid_t sh_ntfork(const Shnode_t *t,char *argv[],int *jobid,int flag) otype = savetype; savetype=0; } - sh_pushcontext(&sh,buffp,SH_JMPCMD); + sh_pushcontext(buffp,SH_JMPCMD); errorpush(&buffp->err,ERROR_SILENT); job_lock(); /* errormsg will unlock */ jmpval = sigsetjmp(buffp->buff,0); @@ -3602,7 +3602,7 @@ static pid_t sh_ntfork(const Shnode_t *t,char *argv[],int *jobid,int flag) } else exitset(); - sh_popcontext(&sh,buffp); + sh_popcontext(buffp); if(buffp->olist) free_list(buffp->olist); if(sigwasset) diff --git a/src/cmd/ksh93/tests/functions.sh b/src/cmd/ksh93/tests/functions.sh index bbbc2acec..51242dc71 100755 --- a/src/cmd/ksh93/tests/functions.sh +++ b/src/cmd/ksh93/tests/functions.sh @@ -976,7 +976,6 @@ function _Dbg_print_frame function _Dbg_debug_trap_handler { - integer .level=.sh.level .max=.sh.level-1 while((--.level>=0)) do diff --git a/src/cmd/ksh93/tests/io.sh b/src/cmd/ksh93/tests/io.sh index ff64cc998..6b8c95264 100755 --- a/src/cmd/ksh93/tests/io.sh +++ b/src/cmd/ksh93/tests/io.sh @@ -800,7 +800,12 @@ procsub_pid=$( true >(true) <(true) >(true) <(true) echo "$!" ) -sleep .1 +integer -s i=0 +while kill -0 "$procsub_pid" # on the Alpine Linux console (no GUI), these take about a second to disappear +do sleep .1 + ((++i > 10)) && break +done 2>/dev/null +unset i if kill -0 "$procsub_pid" 2>/dev/null; then kill -TERM "$procsub_pid" # don't leave around what is effectively a zombie process err_exit "process substitutions loop or linger after parent shell finishes" diff --git a/src/cmd/ksh93/tests/shtests b/src/cmd/ksh93/tests/shtests index 593281cdf..79fc88594 100755 --- a/src/cmd/ksh93/tests/shtests +++ b/src/cmd/ksh93/tests/shtests @@ -172,7 +172,7 @@ function valxml command set +o posix 2>/dev/null unset DISPLAY FIGNORE HISTFILE POSIXLY_CORRECT _AST_FEATURES export ENV=/./dev/null SHTESTS_COMMON=$PWD/_common -trap + CONT PIPE # unadvertised -- set SIGCONT and SIGPIPE to SIG_DFL +trap + $(kill -l) # unadvertised -- set all signals to SIG_DFL integer compile=-1 posix=-1 utf8=-1 integer debug=0 keep=0 locale=0 time=1 diff --git a/src/cmd/ksh93/tests/substring.sh b/src/cmd/ksh93/tests/substring.sh index 9daa53c61..3e4de397b 100755 --- a/src/cmd/ksh93/tests/substring.sh +++ b/src/cmd/ksh93/tests/substring.sh @@ -202,7 +202,6 @@ function myexport typeset val val=$(export | grep "^$1=") print ${val#"$1="} - } export dgk=base if [[ $(myexport dgk fun) != fun ]] diff --git a/src/lib/libast/disc/sfdcprefix.c b/src/lib/libast/disc/sfdcprefix.c index d50a5e271..aa78bdaa0 100644 --- a/src/lib/libast/disc/sfdcprefix.c +++ b/src/lib/libast/disc/sfdcprefix.c @@ -77,7 +77,6 @@ static ssize_t pfxwrite(Sfio_t* f, const void* buf, register size_t n, Sfdisc_t* } while ((s = t + 1) < e); pfx->skip = skip; return w; - } /* diff --git a/src/lib/libcmd/stty.c b/src/lib/libcmd/stty.c index 24d6e6604..a94a25360 100644 --- a/src/lib/libcmd/stty.c +++ b/src/lib/libcmd/stty.c @@ -597,7 +597,6 @@ static const Tty_t *lookup(const char *name) return(&Ttable[i]); } return(0); - } static const Tty_t *getspeed(unsigned long val)