From 78fb8aaccf960c48a6b3b51794af6d28b87b9866 Mon Sep 17 00:00:00 2001 From: dana Date: Fri, 12 Apr 2019 14:00:19 -0500 Subject: 44198: Add cd_silent option to suppress all cd output --- Src/builtin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Src/builtin.c') diff --git a/Src/builtin.c b/Src/builtin.c index 8dcdcc024..49f017046 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -720,7 +720,7 @@ bin_set(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) /**** directory-handling builtins ****/ /**/ -int doprintdir = 0; /* set in exec.c (for autocd) */ +int doprintdir = 0; /* set in exec.c (for autocd, cdpath, etc.) */ /* pwd: display the name of the current directory */ @@ -1251,7 +1251,7 @@ cd_new_pwd(int func, LinkNode dir, int quiet) if (func != BIN_CD && isset(INTERACTIVE)) { if (unset(PUSHDSILENT) && !quiet) printdirstack(); - } else if (doprintdir) { + } else if (unset(CDSILENT) && doprintdir) { fprintdir(pwd, stdout); putchar('\n'); } -- cgit v1.2.3 From d66fd7fcf503b0b8a96b9aafc7263de9886a661e Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Tue, 14 May 2019 23:18:32 +0200 Subject: 44291: printf with argument specifier out of range for an int crashed the shell --- ChangeLog | 5 +++++ Src/builtin.c | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index e44e2f08d..446d732d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2019-05-14 Oliver Kiddle + + * 44291: Src/builtin.c: printf with argument specifier out of + range for an int crashed the shell. + 2019-05-14 Peter Stephenson * 44296: Src/parse.c, Test/B02typeset.ztst: "typeset Q= {X}" diff --git a/Src/builtin.c b/Src/builtin.c index 49f017046..5fbb86635 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -4993,8 +4993,7 @@ bin_print(char *name, char **args, Options ops, int func) narg = strtoul(c, &endptr, 0); if (*endptr == '$') { c = endptr + 1; - DPUTS(narg <= 0, "specified zero or negative arg"); - if (narg > argc) { + if (narg <= 0 || narg > argc) { zwarnnam(name, "%d: argument specifier out of range", narg); if (fout != stdout) -- cgit v1.2.3 From fae7c853319798e170a0bcf1b3098b1a07447c70 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Tue, 14 May 2019 23:36:59 +0200 Subject: 44284: combination of -T and -p to typeset crashed the shell. --- ChangeLog | 3 +++ Src/builtin.c | 6 ++---- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index c5d7e62ff..9cdb70ba7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2019-05-14 Oliver Kiddle + * 44284: Src/builtin.c: combination of -T and -p to typeset + crashed the shell. + * 44290: Src/jobs.c: job number exceeding int range and wrapping to a negative number crashed the shell. diff --git a/Src/builtin.c b/Src/builtin.c index 5fbb86635..2453f82c0 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2582,9 +2582,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), } } pm->node.flags |= (on & PM_READONLY); - - if (OPT_ISSET(ops,'p')) - paramtab->printnode(&pm->node, PRINT_TYPESET); + DPUTS(OPT_ISSET(ops,'p'), "BUG: -p not handled"); return pm; } @@ -2714,7 +2712,7 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func) (!isset(GLOBALEXPORT) && !OPT_ISSET(ops,'g'))) on |= PM_LOCAL; - if (on & PM_TIED) { + if ((on & PM_TIED) && !OPT_ISSET(ops, 'p')) { Param apm; struct asgment asg0, asg2; char *oldval = NULL, *joinstr; -- cgit v1.2.3 From 1b1cb4416105e083eaf34379efacfd4cafa77fb0 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sat, 22 Jun 2019 12:54:34 +0100 Subject: 44443: POSIX allows exporting readonly variables --- ChangeLog | 5 +++++ Src/builtin.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index 034e2ae9f..14aadf2e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2019-06-23 Peter Stephenson + + * Martijn: 44443: Src/builtin.c: POSIX allows exporting readonly + variables. + 2019-06-20 Peter Stephenson * 44435: Doc/Zsh/expn.yo, NEWS, README, Src/Zle/compctl.c, diff --git a/Src/builtin.c b/Src/builtin.c index 2453f82c0..e863cc4bb 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2171,7 +2171,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), !ASG_VALUEP(asg)) on |= PM_UNSET; else if (usepm && (pm->node.flags & PM_READONLY) && - !(on & PM_READONLY)) { + !(on & PM_READONLY) && func != BIN_EXPORT) { zerr("read-only variable: %s", pm->node.nam); return NULL; } -- cgit v1.2.3 From 700ec49581650ea1f0bffacb207a30145e278417 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sat, 29 Jun 2019 00:17:42 +0200 Subject: 44469: correct error on missing option argument --- ChangeLog | 5 +++++ Src/builtin.c | 17 ++++++++++++----- Test/B10getopts.ztst | 17 +++++++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index 7c1d327d5..1eb2ef24a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2019-07-01 Peter Stephenson + + * Martijn: 44469: Src/builtin.c, Test/B10getopts.ztst: correct + error on missing option argument. + 2019-06-24 Peter Stephenson * 44446: Src/parse.c, Test/A04redirect.ztst: fix here document diff --git a/Src/builtin.c b/Src/builtin.c index e863cc4bb..9b9e76c77 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5511,14 +5511,12 @@ bin_getopts(UNUSED(char *name), char **argv, UNUSED(Options ops), UNUSED(int fun /* check for legality */ if(opch == ':' || !(p = memchr(optstr, opch, lenoptstr))) { p = "?"; - err: zsfree(zoptarg); setsparam(var, ztrdup(p)); if(quiet) { zoptarg = metafy(optbuf, lenoptbuf, META_DUP); } else { - zwarn(*p == '?' ? "bad option: %c%c" : - "argument expected after %c%c option", + zwarn("bad option: %c%c", "?-+"[lenoptbuf], opch); zoptarg=ztrdup(""); } @@ -5529,8 +5527,17 @@ bin_getopts(UNUSED(char *name), char **argv, UNUSED(Options ops), UNUSED(int fun if(p[1] == ':') { if(optcind == lenstr) { if(!args[zoptind]) { - p = ":"; - goto err; + zsfree(zoptarg); + if(quiet) { + setsparam(var, ztrdup(":")); + zoptarg = metafy(optbuf, lenoptbuf, META_DUP); + } else { + setsparam(var, ztrdup("?")); + zoptarg = ztrdup(""); + zwarn("argument expected after %c%c option", + "?-+"[lenoptbuf], opch); + } + return 0; } p = ztrdup(args[zoptind++]); } else diff --git a/Test/B10getopts.ztst b/Test/B10getopts.ztst index 7eba5a4b1..72c9e209e 100644 --- a/Test/B10getopts.ztst +++ b/Test/B10getopts.ztst @@ -79,3 +79,20 @@ test_getopts +x 1:one illegal option, + variant >test_getopts:3: bad option: +x + + set -- -x + OPTIND=1 + while getopts x: opt; do + echo "$opt,${OPTARG:-Empty}" + done +0:missing option-argument (error message mode) +>?,Empty +?(eval):3: argument expected after -x option + + set -- -x + OPTIND=1 + while getopts :x: opt; do + echo "$opt,${OPTARG:-Empty}" + done +0:missing option-argument (quiet mode) +>:,x -- cgit v1.2.3 From 5415e1d4df68a759d5b5c3ca65c5e7b3c7c8cfb1 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Mon, 8 Jul 2019 17:56:57 -0700 Subject: 44502: Quote function name for "autoload -X" --- ChangeLog | 2 ++ Src/builtin.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index b65de3925..a73ab744c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2019-07-08 Bart Schaefer + * 44502: Src/builtin.c: Quote function name for "autoload -X" + * 44495: Doc/Zsh/params.yo: Mention coproc under $! 2019-07-08 Peter Stephenson diff --git a/Src/builtin.c b/Src/builtin.c index 9b9e76c77..7db36c41b 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -3029,7 +3029,7 @@ eval_autoload(Shfunc shf, char *name, Options ops, int func) } if (OPT_MINUS(ops,'X')) { char *fargv[3]; - fargv[0] = name; + fargv[0] = quotestring(name, QT_SINGLE_OPTIONAL); fargv[1] = "\"$@\""; fargv[2] = 0; shf->funcdef = mkautofn(shf); -- cgit v1.2.3 From 4fae52572699770fdf4af6bc94d8b219cb401ad2 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 10 Apr 2019 20:54:52 +0100 Subject: Copy functions using functions -c old new. Documentation and test. --- Doc/Zsh/builtins.yo | 11 ++++++++- Src/builtin.c | 43 ++++++++++++++++++++++++++++++-- Test/C04funcdef.ztst | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 119 insertions(+), 4 deletions(-) (limited to 'Src/builtin.c') diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index d7b6e88fa..9eee30d46 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -858,10 +858,11 @@ point numbers are not permitted. ) findex(functions) xitem(tt(functions) [ {tt(PLUS())|tt(-)}tt(UkmtTuWz) ] [ tt(-x) var(num) ] [ var(name) ... ]) +xitem(tt(functions -c) var(oldfn) var(newfn)) xitem(tt(functions -M) [tt(-s)] var(mathfn) [ var(min) [ var(max) [ var(shellfn) ] ] ]) xitem(tt(functions -M) [ tt(-m) var(pattern) ... ]) item(tt(functions +M) [ tt(-m) ] var(mathfn) ... )( -Equivalent to tt(typeset -f), with the exception of the tt(-x), +Equivalent to tt(typeset -f), with the exception of the tt(-c), tt(-x), tt(-M) and tt(-W) options. For tt(functions -u) and tt(functions -U), see tt(autoload), which provides additional options. @@ -875,6 +876,14 @@ function or functions only. The option is turned off at the start of nested functions (apart from anonoymous functions) unless the called function also has the tt(-W) attribute. +The tt(-c) option causes var(oldfn) to be copied to var(newfn). The +copy is efficiently handled internally by reference counting. If +var(oldfn) was marked for autoload it is first loaded and if this +fails the copy fails. Either function may subsequently be redefined +without affecting the other. A typical idiom is that var(oldfn) is the +name of a library shell function which is then redefined to call +tt(newfn), thereby installing a modified version of the function. + Use of the tt(-M) option may not be combined with any of the options handled by tt(typeset -f). diff --git a/Src/builtin.c b/Src/builtin.c index 7db36c41b..5b95cc4fd 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -74,7 +74,7 @@ static struct builtin builtins[] = BUILTIN("fc", 0, bin_fc, 0, -1, BIN_FC, "aAdDe:EfiIlLmnpPrRt:W", NULL), BUILTIN("fg", 0, bin_fg, 0, -1, BIN_FG, NULL, NULL), BUILTIN("float", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_typeset, 0, -1, 0, "E:%F:%HL:%R:%Z:%ghlp:%rtux", "E"), - BUILTIN("functions", BINF_PLUSOPTS, bin_functions, 0, -1, 0, "kmMstTuUWx:z", NULL), + BUILTIN("functions", BINF_PLUSOPTS, bin_functions, 0, -1, 0, "ckmMstTuUWx:z", NULL), BUILTIN("getln", 0, bin_read, 0, -1, 0, "ecnAlE", "zr"), BUILTIN("getopts", 0, bin_getopts, 2, -1, 0, NULL, NULL), BUILTIN("hash", BINF_MAGICEQUALS, bin_hash, 0, -1, 0, "Ldfmrv", NULL), @@ -3248,11 +3248,50 @@ bin_functions(char *name, char **argv, Options ops, int func) if ((off & PM_UNDEFINED) || (OPT_ISSET(ops,'k') && OPT_ISSET(ops,'z')) || (OPT_ISSET(ops,'x') && !OPT_HASARG(ops,'x')) || - (OPT_MINUS(ops,'X') && (OPT_ISSET(ops,'m') || !scriptname))) { + (OPT_MINUS(ops,'X') && (OPT_ISSET(ops,'m') || !scriptname)) || + (OPT_ISSET(ops,'c') && (OPT_ISSET(ops,'x') || OPT_ISSET(ops,'X') || + OPT_ISSET(ops,'m')))) { zwarnnam(name, "invalid option(s)"); return 1; } + if (OPT_ISSET(ops,'c')) { + Shfunc newsh; + if (!*argv || !argv[1] || argv[2]) { + zwarnnam(name, "-c: requires two arguments"); + return 1; + } + shf = (Shfunc) shfunctab->getnode(shfunctab, *argv); + if (!shf) { + zwarnnam(name, "no such funciton: %s", *argv); + return 1; + } + if (shf->node.flags & PM_UNDEFINED) { + if (shf->funcdef) { + freeeprog(shf->funcdef); + shf->funcdef = &dummy_eprog; + } + shf = loadautofn(shf, 1, 0, 0); + if (!shf) + return 1; + } + newsh = zalloc(sizeof(*newsh)); + memcpy(newsh, shf, sizeof(*newsh)); + if (newsh->node.flags & PM_LOADDIR) { + /* Expand original location of autoloaded file */ + newsh->node.flags &= ~PM_LOADDIR; + newsh->filename = tricat(shf->filename, "/", shf->node.nam); + } else + newsh->filename = ztrdup(shf->filename); + newsh->funcdef->nref++; + if (newsh->redir) + newsh->redir->nref++; + if (shf->sticky) + newsh->sticky = sticky_emulation_dup(sticky, 0); + shfunctab->addnode(shfunctab, ztrdup(argv[1]), &newsh->node); + return 0; + } + if (OPT_ISSET(ops,'x')) { char *eptr; expand = (int)zstrtol(OPT_ARG(ops,'x'), &eptr, 10); diff --git a/Test/C04funcdef.ztst b/Test/C04funcdef.ztst index 3aaf7fb4a..407fc471f 100644 --- a/Test/C04funcdef.ztst +++ b/Test/C04funcdef.ztst @@ -503,7 +503,7 @@ not_trashed() { print This function was not trashed; } autoload -Uz /foo/bar/not_trashed not_trashed -0:autoload with absolute path doesn't trash loaded function +0:autoload with absolute path does not trash loaded function >This function was not trashed # keep spec from getting loaded in parent shell for simplicity @@ -542,6 +542,73 @@ 0:autoload containing dash >this should run automatically + tbc() { + print This function is called $0. + } + tbc + functions -c tbc newcopy + newcopy + unfunction tbc + newcopy +0:functions -c +>This function is called tbc. +>This function is called newcopy. +>This function is called newcopy. + + ( + fpath=(.) + print >tbc_auto 'print This autoloaded function is called $0.' + autoload -Uz tbc_auto + functions -c tbc_auto newcopy_auto + newcopy_auto + tbc_auto + ) +0:functions -c with autoload +>This autoloaded function is called newcopy_auto. +>This autoloaded function is called tbc_auto. + + ( + fpath=(.) + print >tbc_redef "print This is the core of the old function." + autoload -Uz tbc_redef + functions -c tbc_redef tbc_original + tbc_redef() { + print About to call the original. + tbc_original + print Stopped calling the original because once is enough. + } + tbc_redef + ) +0:function -c with redefinition +>About to call the original. +>This is the core of the old function. +>Stopped calling the original because once is enough. + + ( + fpath=(.) + print >line_info '\nprint -P "%1x:%I is where we are."' + autoload -Uz line_info + functions -c line_info preserve_file + preserve_file + ) +0:functions -c preserves file information +>line_info:2 is where we are. + + ( + fpath=(.) + print >func_info '\nprint -P "%N:%i is where we are."' + autoload -Uz func_info + functions -c func_info change_output + change_output + ) +0:functions -c updates non-file function information +>change_output:2 is where we are. + + autoload -Uz cant_autoload_for_copying + functions -c cant_autoload_for_copying not_copied +1:functions -c gracefully rejects failed autoload +?(eval):2: cant_autoload_for_copying: function definition file not found + %clean rm -f file.in file.out -- cgit v1.2.3 From 72c6dbe1bee6f4a036b9be38d1430ab75b753c4b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 10 Oct 2019 03:44:56 +0000 Subject: unposted: functions -c: Fix typo --- ChangeLog | 4 ++++ Src/builtin.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index 5f6d1db43..696bb2f2f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2019-10-10 Daniel Shahaf + + * unposted: Src/builtin.c: functions -c: Fix typo + 2019-10-02 Daniel Shahaf * 44797: Completion/Unix/Command/_git: _git-config: Complete diff --git a/Src/builtin.c b/Src/builtin.c index 5b95cc4fd..18daad4fa 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -3263,7 +3263,7 @@ bin_functions(char *name, char **argv, Options ops, int func) } shf = (Shfunc) shfunctab->getnode(shfunctab, *argv); if (!shf) { - zwarnnam(name, "no such funciton: %s", *argv); + zwarnnam(name, "no such function: %s", *argv); return 1; } if (shf->node.flags & PM_UNDEFINED) { -- cgit v1.2.3 From c578f0a08b9257f3db85dab5431270f1a6eb8858 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Tue, 10 Dec 2019 20:41:08 +0100 Subject: 45004: Fix typos in comments --- ChangeLog | 9 +++++++++ Src/builtin.c | 4 ++-- Src/compat.c | 4 ++-- Src/exec.c | 2 +- Src/glob.c | 4 ++-- Src/hashtable.c | 2 +- Src/hist.c | 4 ++-- Src/init.c | 6 +++--- Src/jobs.c | 2 +- Src/lex.c | 2 +- Src/main.c | 4 ++-- Src/mem.c | 2 +- Src/module.c | 2 +- Src/params.c | 2 +- Src/parse.c | 2 +- Src/pattern.c | 18 +++++++++--------- Src/prompt.c | 2 +- Src/subst.c | 12 ++++++------ Src/text.c | 2 +- Src/watch.c | 2 +- Src/zsh.h | 16 ++++++++-------- Test/A02alias.ztst | 2 +- Test/C01arith.ztst | 2 +- Test/C02cond.ztst | 2 +- Test/D03procsubst.ztst | 2 +- Test/D06subscript.ztst | 4 ++-- Test/D08cmdsubst.ztst | 2 +- Test/E01options.ztst | 2 +- Test/V10private.ztst | 2 +- 29 files changed, 65 insertions(+), 56 deletions(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index e9fe1e78a..434318f27 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2019-12-11 Martijn Dekker + * 45004: Src/builtin.c, Src/compat.c, Src/exec.c, Src/glob.c, + Src/hashtable.c, Src/hist.c, Src/init.c, Src/jobs.c, + Src/lex.c, Src/main.c, Src/mem.c, Src/module.c, Src/params.c, + Src/parse.c, Src/pattern.c, Src/prompt.c, Src/subst.c, + Src/text.c, Src/watch.c, Src/zsh.h, Test/A02alias.ztst, + Test/C01arith.ztst, Test/C02cond.ztst, Test/D03procsubst.ztst, + Test/D06subscript.ztst, Test/D08cmdsubst.ztst, + Test/E01options.ztst, Test/V10private.ztst: Fix typos in comments + * 45003: Etc/FAQ.yo, Etc/zsh-development-guide, Functions/Prompts/prompt_oliver_setup, Functions/Zle/insert-composed-char, NEWS, README: Fix more diff --git a/Src/builtin.c b/Src/builtin.c index 18daad4fa..bd7736d2c 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -1718,7 +1718,7 @@ fcsubs(char **sp, struct asgment *sub) newstr = sub->value.scalar; sub = (Asgment)sub->node.next; oldpos = s; - /* loop over occurences of oldstr in s, replacing them with newstr */ + /* loop over occurrences of oldstr in s, replacing them with newstr */ while ((newpos = (char *)strstr(oldpos, oldstr))) { newmem = (char *) zhalloc(1 + (newpos - s) + strlen(newstr) + strlen(newpos + strlen(oldstr))); @@ -2526,7 +2526,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), * Attempt to assign a scalar value to an array. * This can happen if the array is special. * We'll be lenient and guess what the user meant. - * This is how normal assigment works. + * This is how normal assignment works. */ if (*asg->value.scalar) { /* Array with one value */ diff --git a/Src/compat.c b/Src/compat.c index 02b66a780..8ab335aa1 100644 --- a/Src/compat.c +++ b/Src/compat.c @@ -30,8 +30,8 @@ #include "zsh.mdh" #include "compat.pro" -/* Return pointer to first occurence of string t * - * in string s. Return NULL if not present. */ +/* Return pointer to first occurrence of string t * + * in string s. Return NULL if not present. */ /**/ #ifndef HAVE_STRSTR diff --git a/Src/exec.c b/Src/exec.c index 6014ec9a5..9dc91a71e 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -4299,7 +4299,7 @@ save_params(Estate state, Wordcode pc, LinkList *restore_p, LinkList *remove_p) (unset(RESTRICTED) || !(pm->node.flags & PM_RESTRICTED))) { /* * In this case we're just saving parts of - * the parameter in a tempory, so use heap allocation + * the parameter in a temporary, so use heap allocation * and don't bother copying every detail. */ tpm = (Param) hcalloc(sizeof *tpm); diff --git a/Src/glob.c b/Src/glob.c index 92fd64e7c..a367b082b 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -274,7 +274,7 @@ addpath(char *s, int l) } /* stat the filename s appended to pathbuf. l should be true for lstat, * - * false for stat. If st is NULL, the file is only checked for existance. * + * false for stat. If st is NULL, the file is only checked for existence. * * s == "" is treated as s == ".". This is necessary since on most systems * * foo/ can be used to reference a non-directory foo. Returns nonzero if * * the file does not exists. */ @@ -566,7 +566,7 @@ scanner(Complist q, int shortcircuit) continue; errsfound = errssofar; if (pattry(p, fn)) { - /* if this name matchs the pattern... */ + /* if this name matches the pattern... */ if (pbcwdsav == pathbufcwd && strlen(fn) + pathpos - pathbufcwd >= PATH_MAX) { int err; diff --git a/Src/hashtable.c b/Src/hashtable.c index b7baa3142..e210ddeca 100644 --- a/Src/hashtable.c +++ b/Src/hashtable.c @@ -996,7 +996,7 @@ printshfuncnode(HashNode hn, int printflags) * expansion of leading tabs. * expand = 0 is standard: use hard tabs. * expand > 0 uses that many spaces. - * expand < 0 uses no identation. + * expand < 0 uses no indentation. * * Note this function and the following two are called with * interrupts queued, so saving and restoring text_expand_tabs diff --git a/Src/hist.c b/Src/hist.c index e47be8e15..74116e82f 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -181,7 +181,7 @@ mod_export char *chline; * To avoid having to modify this every time we modify chline, * we set it when we push the stack, and unset it when we pop * the appropriate value off the stack. As it's never modified - * on the stack this is the only maintainance we ever do on it. + * on the stack this is the only maintenance we ever do on it. * In return, ZLE has to check both zle_chline and (if that's * NULL) chline to get the current value. */ @@ -476,7 +476,7 @@ herrflush(void) * * Note that this is a side effect --- this is not the usual reason * for testing lex_add_raw which is to add the text to a different - * buffer used when we are actually parsing the command substituion + * buffer used when we are actually parsing the command substitution * (nothing to do with ZLE). Sorry. */ while (inbufct && (!strin || lex_add_raw)) { diff --git a/Src/init.c b/Src/init.c index 445cd3937..2306d7bdf 100644 --- a/Src/init.c +++ b/Src/init.c @@ -137,7 +137,7 @@ loop(int toplevel, int justonce) else stophist = hstop; /* - * Reset all errors, including user interupts. + * Reset all errors, including user interrupts. * This is what allows ^C in an interactive shell * to return us to the command line. */ @@ -203,7 +203,7 @@ loop(int toplevel, int justonce) * that would be inconsistent with the case where * we didn't execute a preexec function. This is * an implementation detail that an interrupting user - * does't care about. + * doesn't care about. */ errflag &= ~ERRFLAG_ERROR; } @@ -362,7 +362,7 @@ static void parseopts_setemulate(char *nam, int flags) * Parse shell options. * * If (flags & PARSEARGS_TOPLEVEL): - * - we are doing shell initilisation + * - we are doing shell initialisation * - nam is the name under which the shell was started * - set up emulation and standard options based on that. * Otherwise: diff --git a/Src/jobs.c b/Src/jobs.c index c06cb9c79..e7438251e 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -1085,7 +1085,7 @@ printjob(Job jn, int lng, int synch) { /* * A subjob still has process, which must finish before - * further excution of the superjob, which the user wants to + * further execution of the superjob, which the user wants to * know about. So report the status of the subjob as if it * were the user-visible superjob. */ diff --git a/Src/lex.c b/Src/lex.c index f43bcc7db..1d86da94e 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -2109,7 +2109,7 @@ skipcomm(void) hist_in_word(1); } else { /* - * Set up for nested command subsitution, however + * Set up for nested command substitution, however * we don't actually need the string until we get * back to the top level and recover the lot. * The $() body just appears empty. diff --git a/Src/main.c b/Src/main.c index 30eef5a25..bad698ee7 100644 --- a/Src/main.c +++ b/Src/main.c @@ -34,7 +34,7 @@ * Support for Cygwin binary/text mode filesystems. * Peter A. Castro * - * This deserves some explaination, because it uses Cygwin specific + * This deserves some explanation, because it uses Cygwin specific * runtime functions. * * Cygwin supports the notion of binary or text mode access to files @@ -43,7 +43,7 @@ * and all. If it's on a text mounted filesystem, Cygwin will strip out * the CRs. This presents a problem because zsh code doesn't allow for * CRLF's as line terminators. So, we must force all open files to be - * in text mode reguardless of the underlying filesystem attributes. + * in text mode regardless of the underlying filesystem attributes. * However, we only want to do this for reading, not writing as we still * want to write files in the mode of the filesystem. To do this, * we have two options: augment all {f}open() calls to have O_TEXT added to diff --git a/Src/mem.c b/Src/mem.c index 77e4375f0..5951e57ed 100644 --- a/Src/mem.c +++ b/Src/mem.c @@ -1120,7 +1120,7 @@ struct m_hdr { /* length of memory header, length of first field of memory header and minimal size of a block left free (if we allocate memory and take a block from the free list that is larger than needed, it must have at - least M_MIN extra bytes to be splitted; if it has, the rest is put on + least M_MIN extra bytes to be split; if it has, the rest is put on the free list) */ #define M_HSIZE (sizeof(struct m_hdr)) diff --git a/Src/module.c b/Src/module.c index 33d75ebbd..f41b82f25 100644 --- a/Src/module.c +++ b/Src/module.c @@ -442,7 +442,7 @@ add_autobin(const char *module, const char *bnam, int flags) } /* Remove the builtin added previously by addbuiltin(). Returns * - * zero on succes and -1 if there is no builtin with that name. */ + * zero on success and -1 if there is no builtin with that name. */ /**/ int diff --git a/Src/params.c b/Src/params.c index a253a9d8e..da7a6b4c5 100644 --- a/Src/params.c +++ b/Src/params.c @@ -3548,7 +3548,7 @@ setiparam(char *s, zlong val) /* * Set an integer parameter without forcing creation of an integer type. - * This is useful if the integer is going to be set to a parmaeter which + * This is useful if the integer is going to be set to a parameter which * would usually be scalar but may not exist. */ diff --git a/Src/parse.c b/Src/parse.c index 53709ac00..de1b27967 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -1811,7 +1811,7 @@ par_simple(int *cmplx, int nr) for (ptr = str; *ptr; ptr++) { /* * We can't treat this as "simple" if it contains - * expansions that require process subsitution, since then + * expansions that require process substitution, since then * we need process handling. */ if (ptr[1] == Inpar && diff --git a/Src/pattern.c b/Src/pattern.c index 97d488a31..95e5a79a0 100644 --- a/Src/pattern.c +++ b/Src/pattern.c @@ -156,7 +156,7 @@ typedef union upat *Upat; * P_BRANCH, but applies to the immediately preceding branch. The code in * the corresponding branch is followed by a P_EXCSYNC, which simply * acts as a marker that a P_EXCLUDE comes next. The P_EXCLUDE - * has a pointer to char embeded in it, which works + * has a pointer to char embedded in it, which works * like P_WBRANCH: if we get to the P_EXCSYNC, and we already matched * up to the same position, fail. Thus we are forced to backtrack * on closures in the P_BRANCH if the first attempt was excluded. @@ -502,7 +502,7 @@ patcompcharsset(void) } } -/* Called before parsing a set of file matchs to initialize flags */ +/* Called before parsing a set of file matches to initialize flags */ /**/ void @@ -2082,7 +2082,7 @@ patmungestring(char **string, int *stringlen, int *unmetalenin) } /* - * Allocate memeory for pattern match. Note this is specific to use + * Allocate memory for pattern match. Note this is specific to use * of pattern *and* trial string. * * Unmetafy a trial string for use in pattern matching, if needed. @@ -2103,7 +2103,7 @@ patmungestring(char **string, int *stringlen, int *unmetalenin) * In patstralloc (supplied by caller, must last until last pattry is done) * unmetalen is the unmetafied length of the string; it will be * calculated if the input value is negative. - * unmetalenp is the umetafied length of a path segment preceeding + * unmetalenp is the umetafied length of a path segment preceding * the trial string needed for file mananagement; it is calculated as * needed so does not need to be initialised. * alloced is the memory allocated on the heap --- same as return value from @@ -2237,7 +2237,7 @@ pattrylen(Patprog prog, char *string, int len, int unmetalen, * depends on both prog *and* the trial string). This should only be * done if there is no path prefix (pathpos == 0) as otherwise the path * buffer and unmetafied string may not match. To do this, - * patallocstr() is callled (use force = 1 to ensure it is alway + * patallocstr() is called (use force = 1 to ensure it is always * unmetafied); paststralloc points to existing storage. Memory is * on the heap. * @@ -2331,7 +2331,7 @@ pattryrefs(Patprog prog, char *string, int stringlen, int unmetalenin, if (patstralloc->alloced) { /* - * Unmetafied; we need pattern sring that's also unmetafied. + * Unmetafied; we need pattern string that's also unmetafied. * We'll cache it in the patstralloc structure. * Note it's on the heap. */ @@ -2389,7 +2389,7 @@ pattryrefs(Patprog prog, char *string, int stringlen, int unmetalenin, /* * Remember the length in case used for ${..#..} etc. * In this case, we didn't unmetafy the pattern string - * In the orignal structure, but it might be unmetafied + * in the original structure, but it might be unmetafied * for use with an unmetafied test string. */ patinlen = pstrlen; @@ -2619,10 +2619,10 @@ pattryrefs(Patprog prog, char *string, int stringlen, int unmetalenin, } /* - * Return length of previous succesful match. This is + * Return length of previous successful match. This is * in metafied bytes, i.e. includes a count of Meta characters, * unless the match was done on an unmetafied string using - * a patstralloc stuct, in which case it, too is unmetafed. + * a patstralloc struct, in which case it too is unmetafied. * Unusual and futile attempt at modular encapsulation. */ diff --git a/Src/prompt.c b/Src/prompt.c index 7f4d7a70e..b65bfb86b 100644 --- a/Src/prompt.c +++ b/Src/prompt.c @@ -163,7 +163,7 @@ promptpath(char *p, int npath, int tilde) * * txtchangep gives an integer controlling the attributes of * the prompt. This is for use in zle to maintain the attributes - * consistenly. Other parts of the shell should not need to use it. + * consistently. Other parts of the shell should not need to use it. */ /**/ diff --git a/Src/subst.c b/Src/subst.c index b132f251b..f887dbd24 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -91,7 +91,7 @@ keyvalpairelement(LinkList list, LinkNode node) * "flag"s contains PREFORK_* flags, defined in zsh.h. * * "ret_flags" is used to return PREFORK_* values from nested parameter - * substitions. It may be NULL in which case PREFORK_SUBEXP must not + * substitutions. It may be NULL in which case PREFORK_SUBEXP must not * appear in flags; any return value from below will be discarded. */ @@ -1548,7 +1548,7 @@ untok_and_escape(char *s, int escapes, int tok_arg) /* * See if an argument str looks like a subscript or length following * a colon and parse it. It must be followed by a ':' or nothing. - * If this succeeds, expand and return the evaulated expression if + * If this succeeds, expand and return the evaluated expression if * found, else return NULL. * * We assume this is what is meant if the first character is not @@ -1682,7 +1682,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, */ int wantt = 0; /* - * Indicates spliting a string into an array. There aren't + * Indicates splitting a string into an array. There aren't * actually that many special cases for this --- which may * be why it doesn't work properly; we split in some cases * where we shouldn't, in particular on the multsubs for @@ -1732,7 +1732,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, int mods = 0; /* * The (z) flag, nothing to do with SH_WORD_SPLIT which is tied - * spbreak, see above; fairly straighforward in use but c.f. + * spbreak, see above; fairly straightforward in use but cf. * the comment for mods. * * This gets set to one of the LEXFLAGS_* values. @@ -2725,7 +2725,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, * substitution is in quotes) always good enough? Potentially * we may be OK by now --- all potential `@'s and subexpressions * have been handled, including any [@] index which comes up - * by virture of v->isarr being set to SCANPM_ISVAR_AT which + * by virtue of v->isarr being set to SCANPM_ISVAR_AT which * is now in isarr. * * However, if we are replacing multsub() with something that @@ -3110,7 +3110,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, /* * Either loop over an array doing replacements or - * do the replacment on a string. + * do the replacement on a string. * * We need an untokenized value for matching. */ diff --git a/Src/text.c b/Src/text.c index a4191bf1a..69530ae79 100644 --- a/Src/text.c +++ b/Src/text.c @@ -584,7 +584,7 @@ gettext2(Estate state) state->pc = end; if (!nargs) { /* - * Unnamed fucntion. + * Unnamed function. * We're not going to pull any arguments off * later, so skip them now... */ diff --git a/Src/watch.c b/Src/watch.c index cd7dc643d..93b3cb134 100644 --- a/Src/watch.c +++ b/Src/watch.c @@ -98,7 +98,7 @@ /* * In utmpx, the ut_name field is replaced by ut_user. - * Howver, on some systems ut_name may already be defined this + * However, on some systems ut_name may already be defined this * way for the purposes of utmp. */ # ifndef ut_name diff --git a/Src/zsh.h b/Src/zsh.h index fc3ed2127..9194ea82c 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -455,7 +455,7 @@ enum { */ #define FDT_FLOCK_EXEC 6 /* - * Entry used by a process substition. + * Entry used by a process substitution. * This marker is not tested internally as we associated the file * descriptor with a job for closing. * @@ -1255,7 +1255,7 @@ enum { /* * Assignment has value? * If the assignment is an arrray, then it certainly has a value --- we - * can only tell if there's an expicit assignment. + * can only tell if there's an explicit assignment. */ #define ASG_VALUEP(asg) (ASG_ARRAYP(asg) || \ @@ -1444,8 +1444,8 @@ struct builtin { */ #define BINF_HANDLES_OPTS (1<<18) /* - * Handles the assignement interface. The argv list actually contains - * two nested litsts, the first of normal arguments, and the second of + * Handles the assignment interface. The argv list actually contains + * two nested lists, the first of normal arguments, and the second of * assignment structures. */ #define BINF_ASSIGN (1<<19) @@ -2006,7 +2006,7 @@ enum { enum { /* * Set if the string had whitespace at the start - * that should cause word splitting against any preceeding string. + * that should cause word splitting against any preceding string. */ MULTSUB_WS_AT_START = 1, /* @@ -2272,9 +2272,9 @@ struct histent { */ #define LEXFLAGS_NEWLINE 0x0010 -/******************************************/ -/* Definitions for programable completion */ -/******************************************/ +/*******************************************/ +/* Definitions for programmable completion */ +/*******************************************/ /* Nothing special. */ #define IN_NOTHING 0 diff --git a/Test/A02alias.ztst b/Test/A02alias.ztst index 99f7aae26..ca415fa39 100644 --- a/Test/A02alias.ztst +++ b/Test/A02alias.ztst @@ -129,7 +129,7 @@ setopt ALIAS_FUNC_DEF eval 'goodalias() { print does now work; }' isafunc) -0:ALIAS_FUNC_DEF causes the icky behaviour to be avaliable +0:ALIAS_FUNC_DEF causes the icky behaviour to be available >does now work (alias thisisokthough='thisworks() { print That worked; }' diff --git a/Test/C01arith.ztst b/Test/C01arith.ztst index 9dfc065c8..419f45292 100644 --- a/Test/C01arith.ztst +++ b/Test/C01arith.ztst @@ -386,7 +386,7 @@ esac) print after case in subshell) ' -0:Non-arithmetic subst with command subsitution parse from hell +0:Non-arithmetic subst with command substitution parse from hell >yes, this one after case in subshell print "a$((echo one subst) diff --git a/Test/C02cond.ztst b/Test/C02cond.ztst index 4ffb07dd4..4b1ec02f0 100644 --- a/Test/C02cond.ztst +++ b/Test/C02cond.ztst @@ -388,7 +388,7 @@ F:Failures in these cases do not indicate a problem in the shell. eval test $w print $? done -0:test compatability weirdness: treat ! as a string sometimes +0:test compatibility weirdness: treat ! as a string sometimes >0 >0 >1 diff --git a/Test/D03procsubst.ztst b/Test/D03procsubst.ztst index 1ef55821b..8cf4e2a7f 100644 --- a/Test/D03procsubst.ztst +++ b/Test/D03procsubst.ztst @@ -26,7 +26,7 @@ >SEcond ViErtE diff =(cat FILE1) =(cat FILE2) -1:=(...) substituion +1:=(...) substitution >1c1 >< First Second Third Fourth >--- diff --git a/Test/D06subscript.ztst b/Test/D06subscript.ztst index 3ea7fb7e4..c1a8d79cf 100644 --- a/Test/D06subscript.ztst +++ b/Test/D06subscript.ztst @@ -190,7 +190,7 @@ typeset -ga empty echo X${${empty##*}[-1]}X -0:Negative index applied to substition result from empty array +0:Negative index applied to substitution result from empty array >XX print $empty[(i)] $empty[(I)] @@ -221,7 +221,7 @@ >fimble two three four print X$array[(R)notfound]X -0:(R) yuckily returns the first element on failure withe KSH_ZERO_SUBSCRIPT +0:(R) yuckily returns the first element on failure with KSH_ZERO_SUBSCRIPT >XfimbleX unsetopt KSH_ZERO_SUBSCRIPT diff --git a/Test/D08cmdsubst.ztst b/Test/D08cmdsubst.ztst index 4e0759e35..04bf698aa 100644 --- a/Test/D08cmdsubst.ztst +++ b/Test/D08cmdsubst.ztst @@ -174,6 +174,6 @@ eval '{ OPEN print hi; CLOSE } var=$({ OPEN print bye; CLOSE}) && print $var' ) -0:Alias expansion needed in parsing substituions +0:Alias expansion needed in parsing substitutions >hi >bye diff --git a/Test/E01options.ztst b/Test/E01options.ztst index 0f6bb3455..c4b101bdb 100644 --- a/Test/E01options.ztst +++ b/Test/E01options.ztst @@ -850,7 +850,7 @@ # With non-special command: original value restored # With special builtin: new value kept - # With special builtin preceeded by "command": original value restored. + # With special builtin preceded by "command": original value restored. (setopt posixbuiltins FOO=val0 FOO=val1 true; echo $FOO diff --git a/Test/V10private.ztst b/Test/V10private.ztst index 880784e12..a3a63867b 100644 --- a/Test/V10private.ztst +++ b/Test/V10private.ztst @@ -104,7 +104,7 @@ private -h path print X$path } -0:privates may hide tied paramters +0:privates may hide tied parameters >X # Deliberate type mismatch here -- cgit v1.2.3 From cb4dc956439140ca595b2b7dfd511efaa22d1e22 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 12 Dec 2019 10:47:00 +0000 Subject: 45009: POSIX_CD needs to suppress some forms of option. Otherwise forms of argument allowed by POSIX are interpreted as options instead. --- Doc/Zsh/builtins.yo | 2 ++ Doc/Zsh/options.yo | 3 ++- Src/builtin.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) (limited to 'Src/builtin.c') diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 15d3e0cf4..415bce613 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -290,6 +290,8 @@ of the list shown by the tt(dirs) command, starting with zero. An argument of the form `tt(-)var(n)' counts from the right. If the tt(PUSHD_MINUS) option is set, the meanings of `tt(PLUS())' and `tt(-)' in this context are swapped. +If the tt(POSIX_CD) option is set, this form of tt(cd) is not recognised +and will be interpreted as the first form. If the tt(-q) (quiet) option is specified, the hook function tt(chpwd) and the functions in the array tt(chpwd_functions) are not called. diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 903c31134..88bb643d1 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -148,7 +148,8 @@ ifzman(zmanref(zshbuiltins))\ ifnzman(noderef(Shell Builtin Commands)). If the option is set, the shell does not test for directories beneath the local directory (`tt(.)') until after all directories in tt(cdpath) -have been tested. +have been tested, and the tt(cd) and tt(chdir) commands do not recognise +arguments of the form `{tt(PLUS())|tt(-)}var(n)' as directory stack entries. Also, if the option is set, the conditions under which the shell prints the new directory after changing to it are modified. It is diff --git a/Src/builtin.c b/Src/builtin.c index bd7736d2c..7bf4281da 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -912,7 +912,7 @@ cd_get_dest(char *nam, char **argv, int hard, int func) char *end; doprintdir++; - if (argv[0][1] && (argv[0][0] == '+' || argv[0][0] == '-') + if (!isset(POSIXCD) && argv[0][1] && (argv[0][0] == '+' || argv[0][0] == '-') && strspn(argv[0]+1, "0123456789") == strlen(argv[0]+1)) { dd = zstrtol(argv[0] + 1, &end, 10); if (*end == '\0') { -- cgit v1.2.3 From 06c2a625b33b85aff0c7699e12f0eaf1fcc97ba6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Dec 2019 02:41:14 +0000 Subject: unposted: Update comment to reflect variable rename in 41012 (= zsh-5.3.1-182-gd7110d8f0). --- Src/builtin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Src/builtin.c') diff --git a/Src/builtin.c b/Src/builtin.c index 7bf4281da..00b5d5c50 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5807,7 +5807,7 @@ zexit(int val, int from_where) return; } } - /* Positive in_exit means we have been here before */ + /* Positive shell_exiting means we have been here before */ if (from_where == 2 || (shell_exiting++ && from_where)) return; -- cgit v1.2.3 From 8bc4400762289e5cdbcfa50aab5982f8e7e28dfc Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Dec 2019 04:43:48 +0000 Subject: 45058: internal: Add symbolic names to possible values of zexit()'s "from_where" parameter. No functional change. --- ChangeLog | 5 +++++ Src/Modules/zpty.c | 2 +- Src/Zle/zle_main.c | 4 ++-- Src/builtin.c | 24 +++++++++++++----------- Src/exec.c | 2 +- Src/init.c | 10 +++++----- Src/signals.c | 8 ++++---- Src/subst.c | 2 +- Src/zsh.h | 8 ++++++++ 9 files changed, 40 insertions(+), 25 deletions(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index 4ae35b692..9b7571f8a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2019-12-17 Daniel Shahaf + * 45058: Src/Modules/zpty.c, Src/Zle/zle_main.c, Src/builtin.c, + Src/exec.c, Src/init.c, Src/signals.c, Src/subst.c, Src/zsh.h: + internal: Add symbolic names to possible values of zexit()'s + "from_where" parameter. No functional change. + * unposted: Src/builtin.c: Update comment to reflect variable rename in 41012 (zsh-5.3.1-182-gd7110d8f0). diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c index 2f83f7ce6..45fd15ee0 100644 --- a/Src/Modules/zpty.c +++ b/Src/Modules/zpty.c @@ -426,7 +426,7 @@ newptycmd(char *nam, char *pname, char **args, int echo, int nblock) execode(prog, 1, 0, "zpty"); stopmsg = 2; mypid = 0; /* trick to ensure we _exit() */ - zexit(lastval, 0); + zexit(lastval, ZEXIT_NORMAL); } master = movefd(master); if (master == -1) { diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 27dc8ef21..22cb21be3 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -905,7 +905,7 @@ getbyte(long do_keytmout, int *timeout, int full) if ((zlereadflags & ZLRF_IGNOREEOF) && icnt++ < 20) continue; stopmsg = 1; - zexit(1, 0); + zexit(1, ZEXIT_NORMAL); } icnt = 0; if (errno == EINTR) { @@ -928,7 +928,7 @@ getbyte(long do_keytmout, int *timeout, int full) } else if (errno != 0) { zerr("error on TTY read: %e", errno); stopmsg = 1; - zexit(1, 0); + zexit(1, ZEXIT_NORMAL); } } if (cc == '\r') /* undo the exchange of \n and \r determined by */ diff --git a/Src/builtin.c b/Src/builtin.c index 00b5d5c50..5fe5ea6d1 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5665,7 +5665,7 @@ bin_break(char *name, char **argv, UNUSED(Options ops), int func) } return lastval; } - zexit(num, 0); /* else treat return as logout/exit */ + zexit(num, ZEXIT_NORMAL); /* else treat return as logout/exit */ break; case BIN_LOGOUT: if (unset(LOGINSHELL)) { @@ -5687,7 +5687,7 @@ bin_break(char *name, char **argv, UNUSED(Options ops), int func) * If we are already exiting... give this all up as * a bad job. */ - if (stopmsg || (zexit(0,2), !stopmsg)) { + if (stopmsg || (zexit(0, ZEXIT_DEFERRED), !stopmsg)) { retflag = 1; breaks = loops; exit_pending = 1; @@ -5695,7 +5695,7 @@ bin_break(char *name, char **argv, UNUSED(Options ops), int func) exit_val = num; } } else - zexit(num, 0); + zexit(num, ZEXIT_NORMAL); break; } return 0; @@ -5780,14 +5780,15 @@ _realexit(void) /* exit the shell. val is the return value of the shell. * * from_where is - * 1 if zexit is called because of a signal - * 2 if we can't actually exit yet (e.g. functions need - * terminating) but should perform the usual interactive tests. + * ZEXIT_SIGNAL if zexit is called because of a signal + * ZEXIT_DEFERRED if we can't actually exit yet (e.g., functions need + * terminating) but should perform the usual interactive + * tests. */ /**/ mod_export void -zexit(int val, int from_where) +zexit(int val, enum zexit_t from_where) { /* * Don't do anything recursively: see below. @@ -5798,7 +5799,7 @@ zexit(int val, int from_where) if (shell_exiting == -1) return; - if (isset(MONITOR) && !stopmsg && from_where != 1) { + if (isset(MONITOR) && !stopmsg && from_where != ZEXIT_SIGNAL) { scanjobs(); /* check if jobs need printing */ if (isset(CHECKJOBS)) checkjobs(); /* check if any jobs are running/stopped */ @@ -5808,7 +5809,8 @@ zexit(int val, int from_where) } } /* Positive shell_exiting means we have been here before */ - if (from_where == 2 || (shell_exiting++ && from_where)) + if (from_where == ZEXIT_DEFERRED || + (shell_exiting++ && from_where != ZEXIT_NORMAL)) return; /* @@ -5824,12 +5826,12 @@ zexit(int val, int from_where) if (isset(MONITOR)) { /* send SIGHUP to any jobs left running */ - killrunjobs(from_where == 1); + killrunjobs(from_where == ZEXIT_SIGNAL); } if (isset(RCS) && interact) { if (!nohistsave) { int writeflags = HFILE_USE_OPTIONS; - if (from_where == 1) + if (from_where == ZEXIT_SIGNAL) writeflags |= HFILE_NO_REWRITE; saveandpophiststack(1, writeflags); savehistfile(NULL, 1, writeflags); diff --git a/Src/exec.c b/Src/exec.c index 64eee7dc4..0d9d7de7c 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -5949,7 +5949,7 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval) * exit command was handled. */ stopmsg = 1; - zexit(exit_val, 0); + zexit(exit_val, ZEXIT_NORMAL); } } diff --git a/Src/init.c b/Src/init.c index 2306d7bdf..2e2ef881c 100644 --- a/Src/init.c +++ b/Src/init.c @@ -161,7 +161,7 @@ loop(int toplevel, int justonce) * Handle that now. */ stopmsg = 1; - zexit(exit_val, 0); + zexit(exit_val, ZEXIT_NORMAL); } if (tok == LEXERR && !lastval) lastval = 1; @@ -1371,7 +1371,7 @@ init_misc(char *cmd, char *zsh_name) bshin = fdopen(SHIN, "r"); execstring(cmd, 0, 1, "cmdarg"); stopmsg = 1; - zexit((exit_pending || shell_exiting) ? exit_val : lastval, 0); + zexit((exit_pending || shell_exiting) ? exit_val : lastval, ZEXIT_NORMAL); } if (interact && isset(RCS)) @@ -1778,20 +1778,20 @@ zsh_main(UNUSED(int argc), char **argv) if (!lastval) lastval = 1; stopmsg = 1; - zexit(lastval, 0); + zexit(lastval, ZEXIT_NORMAL); } if (!(isset(IGNOREEOF) && interact)) { #if 0 if (interact) fputs(islogin ? "logout\n" : "exit\n", shout); #endif - zexit(lastval, 0); + zexit(lastval, ZEXIT_NORMAL); continue; } noexitct++; if (noexitct >= 10) { stopmsg = 1; - zexit(lastval, 0); + zexit(lastval, ZEXIT_NORMAL); } /* * Don't print the message if it was already handled by diff --git a/Src/signals.c b/Src/signals.c index 14218177a..96ff9e9b3 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -654,7 +654,7 @@ zhandler(int sig) _exit(SIGPIPE); else if (!isatty(SHTTY)) { stopmsg = 1; - zexit(SIGPIPE, 1); + zexit(SIGPIPE, ZEXIT_SIGNAL); } } break; @@ -662,7 +662,7 @@ zhandler(int sig) case SIGHUP: if (!handletrap(SIGHUP)) { stopmsg = 1; - zexit(SIGHUP, 1); + zexit(SIGHUP, ZEXIT_SIGNAL); } break; @@ -670,7 +670,7 @@ zhandler(int sig) if (!handletrap(SIGINT)) { if ((isset(PRIVILEGED) || isset(RESTRICTED)) && isset(INTERACTIVE) && (noerrexit & NOERREXIT_SIGNAL)) - zexit(SIGINT, 1); + zexit(SIGINT, ZEXIT_SIGNAL); if (list_pipe || chline || simple_pline) { breaks = loops; errflag |= ERRFLAG_INT; @@ -703,7 +703,7 @@ zhandler(int sig) errflag = noerrs = 0; zwarn("timeout"); stopmsg = 1; - zexit(SIGALRM, 1); + zexit(SIGALRM, ZEXIT_SIGNAL); } } break; diff --git a/Src/subst.c b/Src/subst.c index f887dbd24..79efc9ad2 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -3044,7 +3044,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, * shouldn't be any if not interactive. */ stopmsg = 1; - zexit(1, 0); + zexit(1, ZEXIT_NORMAL); } else _exit(1); } diff --git a/Src/zsh.h b/Src/zsh.h index 9194ea82c..657e6d8ec 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -3222,6 +3222,14 @@ enum { /* Hooks in core. */ /***************************************/ +/* The type of zexit()'s second parameter, which see. */ +enum zexit_t { + /* This isn't a bitfield. The values are here just for explicitness. */ + ZEXIT_NORMAL = 0, + ZEXIT_SIGNAL = 1, + ZEXIT_DEFERRED = 2 +}; + #define EXITHOOK (zshhooks + 0) #define BEFORETRAPHOOK (zshhooks + 1) #define AFTERTRAPHOOK (zshhooks + 2) -- cgit v1.2.3 From ae7e291873c1f80c51f53db934a87df2c0eaf821 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Dec 2019 07:44:28 +0000 Subject: 45066: internal: Document forklevel, locallevel, and exit_pending. --- ChangeLog | 3 +++ Src/builtin.c | 6 +++++- Src/exec.c | 4 ++++ Src/params.c | 6 +++++- 4 files changed, 17 insertions(+), 2 deletions(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index 4821b09b6..742ddab9d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2019-12-18 Daniel Shahaf + * 45066: Src/builtin.c, Src/exec.c, Src/params.c: internal: + Document forklevel, locallevel, and exit_pending. + * 45065: Src/Makefile.in: Make 'make -s' print nothing when it does nothing. diff --git a/Src/builtin.c b/Src/builtin.c index 5fe5ea6d1..0ecabf854 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5601,7 +5601,11 @@ bin_getopts(UNUSED(char *name), char **argv, UNUSED(Options ops), UNUSED(int fun return 0; } -/* Flag that we should exit the shell as soon as all functions return. */ +/* Boolean flag that we should exit the shell as soon as all functions return. + * + * Set by the 'exit' builtin. + */ + /**/ mod_export int exit_pending; diff --git a/Src/exec.c b/Src/exec.c index 0d9d7de7c..50027654a 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -971,6 +971,10 @@ hashcmd(char *arg0, char **pp) return cn; } +/* The value that 'locallevel' had when we forked. When we get back to this + * level, the current process (which is a subshell) will terminate. + */ + /**/ int forklevel; diff --git a/Src/params.c b/Src/params.c index da7a6b4c5..5eaafe34e 100644 --- a/Src/params.c +++ b/Src/params.c @@ -44,7 +44,11 @@ #endif #endif -/* what level of localness we are at */ +/* What level of localness we are at. + * + * Hand-wavingly, this is incremented at every function call and decremented + * at every function return. See startparamscope(). + */ /**/ mod_export int locallevel; -- cgit v1.2.3 From faa476a4ed1750f117d76dd8f99f0fa1849ab539 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jan 2020 19:09:54 +0000 Subject: 45302: bin_umask(): Queue signals around umask(). Otherwise, a signal handler might create files while the temporary umask is in effect. --- ChangeLog | 5 +++++ Src/builtin.c | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index ca68e2e4b..02825ae36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-01-15 Daniel Shahaf + + * 45302: Src/builtin.c: bin_umask(): Queue signals around + umask(). + 2020-01-14 Daniel Shahaf * users/24656: Doc/Zsh/mod_zutil.yo: docs: Add an example of diff --git a/Src/builtin.c b/Src/builtin.c index 0ecabf854..aa5767cf1 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -7287,8 +7287,11 @@ bin_umask(char *nam, char **args, Options ops, UNUSED(int func)) char *s = *args; /* Get the current umask. */ - um = umask(0); + queue_signals(); + um = umask(0777); umask(um); + unqueue_signals(); + /* No arguments means to display the current setting. */ if (!s) { if (OPT_ISSET(ops,'S')) { -- cgit v1.2.3