CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Mon Dec 7 19:39:09 UTC 2020 Modified Files: src/bin/sh [netbsd-8]: exec.c Log Message: Pull up following revision(s) (requested by kre in ticket #1629): bin/sh/exec.c: revision 1.54 PR bin/55526 Fix a bug that has existed since the "command" command was added in 2003. "command foo" would cause the definition of a function "foo" to be lost (not freed, simply discarded) if "foo" is (in addition to being a function) a filesystem command. The case where "foo" is a builtin was handled. For now, when a function exists with the same name as a filesystem command, the latter can never appear in the command hash table, and when used (which can only be via "command foo", just "foo" finds the function) will always result in a full PATH search. XXX pullup everything (from NetBSD 2.0 onwards). (really -8 and -9) To generate a diff of this commit: cvs rdiff -u -r1.47.2.4 -r1.47.2.5 src/bin/sh/exec.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/exec.c diff -u src/bin/sh/exec.c:1.47.2.4 src/bin/sh/exec.c:1.47.2.5 --- src/bin/sh/exec.c:1.47.2.4 Sat Aug 25 14:48:22 2018 +++ src/bin/sh/exec.c Mon Dec 7 19:39:09 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: exec.c,v 1.47.2.4 2018/08/25 14:48:22 martin Exp $ */ +/* $NetBSD: exec.c,v 1.47.2.5 2020/12/07 19:39:09 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95"; #else -__RCSID("$NetBSD: exec.c,v 1.47.2.4 2018/08/25 14:48:22 martin Exp $"); +__RCSID("$NetBSD: exec.c,v 1.47.2.5 2020/12/07 19:39:09 martin Exp $"); #endif #endif /* not lint */ @@ -667,6 +667,10 @@ loop: cmdp = _cmd; } else cmdp = cmdlookup(name, 1); + + if (cmdp->cmdtype == CMDFUNCTION) + cmdp = _cmd; + cmdp->cmdtype = CMDNORMAL; cmdp->param.index = idx; INTON;
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Fri Dec 7 13:23:49 UTC 2018 Modified Files: src/bin/sh [netbsd-8]: sh.1 var.c var.h Log Message: Pull up following revision(s) (requested by kre in ticket #1127): bin/sh/var.h: revision 1.38 (via patch) bin/sh/var.c: revision 1.72 bin/sh/sh.1: revision 1.211 (via patch) Alter a design botch when magic (self modifying) variables were added to sh ... in other shells, setting such a variable (for most of them) causes it to lose its special properties, and act the same as any other variable. I had assumed that was just implementor laziness... I was wrong. >From now on the NetBSD shell will act like the others, and if vars like HOSTNAME (and SECONDS, etc) are used as variables in a script or whatever, they will act just like normal variables (and unless this happens when they have been made local, or as a variable-assignment as a prefix to a command, the special properties they would have had otherwise are lost for the remainder of the life of the (sub-)shell in which the variables were set). Importing a value from the environment counts as setting the value for this purpose (so if HOSTNAME is set in the environment, the value there will be the value $HOSTNAME expands to). The two exceptions to this are LINENO and RANDOM. RANDOM needs to be able to be set to (re-)set its seed. LINENO needs to be able to be set (at least in the "local" command) to achieve the desired functionality. It is unlikely that any (sane) script is going to want to use those two as normal vars however. While here, fix a minor bug in popping local vars (fn return) that need to notify the shell of changes in value (like PATH). Change sh(1) to reflect this alteration. Also add doc of the (forgotten) magic var EUSER (which has been there since the others were added), and add a few more vars (which are documented in other places in sh(1) - like ENV) into the defined or used variable list (as well as wherever else they appear). XXX pullup -8 To generate a diff of this commit: cvs rdiff -u -r1.146.2.5 -r1.146.2.6 src/bin/sh/sh.1 cvs rdiff -u -r1.55.2.3 -r1.55.2.4 src/bin/sh/var.c cvs rdiff -u -r1.28.8.1 -r1.28.8.2 src/bin/sh/var.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/sh.1 diff -u src/bin/sh/sh.1:1.146.2.5 src/bin/sh/sh.1:1.146.2.6 --- src/bin/sh/sh.1:1.146.2.5 Wed Oct 25 07:03:10 2017 +++ src/bin/sh/sh.1 Fri Dec 7 13:23:49 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.146.2.5 2017/10/25 07:03:10 snj Exp $ +.\" $NetBSD: sh.1,v 1.146.2.6 2018/12/07 13:23:49 martin Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -2315,6 +2315,21 @@ Making local causes any shell options that are changed via the set command inside the function to be restored to their original values when the function returns. +If any of the shell's magic variables +(those which return a value which may vary without +the variable being explicitly altered, +e.g.: +.Dv SECONDS +or +.Dv HOSTNAME ) +are made local in a function, +they will lose their special properties when set +within the function, including by the +.Ic local +command itself +(if not to be set in the function, there is little point +in making a variable local) +but those properties will be restored when the function returns. .Pp It is an error to use .Ic local @@ -2985,6 +3000,30 @@ above, which are documented further abov If unset .Dq $HOME/.editrc is used. +.It Ev ENV +Names the file sourced at startup by the shell. +Unused by this shell after initialization, +but is usually passed through the environment to +descendant shells. +.It Ev EUSER +Set to the login name of the effective user id running the shell, +as returned by +.Bd -compact -literal -offset indent +getpwuid(geteuid())->pw_name +.Ed +.Po +See +.Xr getpwuid 3 +and +.Xr geteuid 2 +for more details. +.Pc +This is obtained each time +.Ev EUSER +is expanded, so changes to the shell's execution identity +cause updates without further action. +If unset, it returns nothing. +If set it loses its special properties, and is simply a variable. .It Ev HISTSIZE The number of lines in the history buffer for the shell. .It Ev HOME @@ -3003,8 +3042,7 @@ This is obtained each time is expanded, so changes to the system's name are reflected without further action. If unset, it returns nothing. -Setting it does nothing except reverse the effect of an earlier -.Ic unset . +If set it loses its special properties, and is simply a variable. .It Ev IFS Input Field Separators. This is normally set to @@ -3056,6 +3094,22 @@ The default search path for executables. See the .Sx Path Search section above. +.It Ev POSIXLY_CORRECT +If set in the environment upon initialization of the shell, +then the shell option +.Ic posix +will be set. +.Po +See the description of the +.Ic set
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Fri Dec 7 13:14:42 UTC 2018 Modified Files: src/bin/sh [netbsd-8]: alias.c Log Message: Pull up following revision(s) (requested by kre in ticket #1126): bin/sh/alias.c: revision 1.19 Fix the worst of the bugs in alias processing. This has been in sh since this code was first imported (May 1994) (ie: before 4.4-Lite) There is (much) more coming soon (the big ugly comment is going away). This one has been separated out, as it can easily cause sh core dumps, so needs: XXX pullup-8 (the other changes to aliases probably will not get that.) To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.15.16.1 src/bin/sh/alias.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/alias.c diff -u src/bin/sh/alias.c:1.15 src/bin/sh/alias.c:1.15.16.1 --- src/bin/sh/alias.c:1.15 Wed Jun 18 18:17:30 2014 +++ src/bin/sh/alias.c Fri Dec 7 13:14:42 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: alias.c,v 1.15 2014/06/18 18:17:30 christos Exp $ */ +/* $NetBSD: alias.c,v 1.15.16.1 2018/12/07 13:14:42 martin Exp $ */ /*- * Copyright (c) 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)alias.c 8.3 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: alias.c,v 1.15 2014/06/18 18:17:30 christos Exp $"); +__RCSID("$NetBSD: alias.c,v 1.15.16.1 2018/12/07 13:14:42 martin Exp $"); #endif #endif /* not lint */ @@ -67,17 +67,9 @@ setalias(char *name, char *val) { struct alias *ap, **app; + (void) unalias(name); /* old one (if any) is now gone */ app = hashalias(name); - for (ap = *app; ap; ap = ap->next) { - if (equal(name, ap->name)) { - INTOFF; - ckfree(ap->val); - ap->val = savestr(val); - INTON; - return; - } - } - /* not found */ + INTOFF; ap = ckmalloc(sizeof (struct alias)); ap->name = savestr(name);
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Fri Dec 7 13:12:02 UTC 2018 Modified Files: src/bin/sh [netbsd-8]: redir.c Log Message: Pull up following revision(s) (requested by kre in ticket #1125): bin/sh/redir.c: revision 1.61 Fix the <> redirection operator, which has been broken since it was first implemented in response to PR bin/4966 (PR Feb 1998, fix Feb 1999). The file named should not be truncated. No other shell truncates the file (<> was added to FreeBSD sh in Oct 2000, and did not include O_TRUNC) and POSIX certainly does not suggest that should happen (just that the file is to be created if it does not exist.) Bug pointed out in off-list e-mail by Martijn Dekker To generate a diff of this commit: cvs rdiff -u -r1.57.2.1 -r1.57.2.2 src/bin/sh/redir.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/redir.c diff -u src/bin/sh/redir.c:1.57.2.1 src/bin/sh/redir.c:1.57.2.2 --- src/bin/sh/redir.c:1.57.2.1 Sun Jul 23 14:58:14 2017 +++ src/bin/sh/redir.c Fri Dec 7 13:12:02 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: redir.c,v 1.57.2.1 2017/07/23 14:58:14 snj Exp $ */ +/* $NetBSD: redir.c,v 1.57.2.2 2018/12/07 13:12:02 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)redir.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: redir.c,v 1.57.2.1 2017/07/23 14:58:14 snj Exp $"); +__RCSID("$NetBSD: redir.c,v 1.57.2.2 2018/12/07 13:12:02 martin Exp $"); #endif #endif /* not lint */ @@ -283,7 +283,7 @@ openredirect(union node *redir, char mem break; case NFROMTO: fname = redir->nfile.expfname; - if ((f = open(fname, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) + if ((f = open(fname, O_RDWR|O_CREAT, 0666)) < 0) goto ecreate; break; case NTO:
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Mon Nov 12 08:46:54 UTC 2018 Modified Files: src/bin/sh [netbsd-8]: parser.c Log Message: Pull up following revision(s) (requested by kre in ticket #1086): bin/sh/parser.c: revision 1.152 PR bin/53712 Avoid crash from redirect on null compound command. To generate a diff of this commit: cvs rdiff -u -r1.132.2.6 -r1.132.2.7 src/bin/sh/parser.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/parser.c diff -u src/bin/sh/parser.c:1.132.2.6 src/bin/sh/parser.c:1.132.2.7 --- src/bin/sh/parser.c:1.132.2.6 Mon Sep 10 15:45:11 2018 +++ src/bin/sh/parser.c Mon Nov 12 08:46:54 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: parser.c,v 1.132.2.6 2018/09/10 15:45:11 martin Exp $ */ +/* $NetBSD: parser.c,v 1.132.2.7 2018/11/12 08:46:54 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95"; #else -__RCSID("$NetBSD: parser.c,v 1.132.2.6 2018/09/10 15:45:11 martin Exp $"); +__RCSID("$NetBSD: parser.c,v 1.132.2.7 2018/11/12 08:46:54 martin Exp $"); #endif #endif /* not lint */ @@ -597,7 +597,7 @@ command(void) tokpushback++; *rpp = NULL; if (redir) { - if (n1->type != NSUBSHELL) { + if (n1 == NULL || n1->type != NSUBSHELL) { n2 = stalloc(sizeof(struct nredir)); n2->type = NREDIR; n2->nredir.n = n1;
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Sun Oct 21 12:00:33 UTC 2018 Modified Files: src/bin/sh [netbsd-8]: mkinit.sh Log Message: Pull up following revision(s) (requested by kre in ticket #1067): bin/sh/mkinit.sh: revision 1.9 Dynamically detect the way the shell matches \ in a pattern, and use whatever works for the sh running this script. Previously we were using the (broken, and incorrect) method that worked in old broken NetBSD sh's (and some others) and not the method that works with the current (fixed) /bin/sh and other correct shells (like bash). (For an exotic reason, in the particular use case, both methods work with ksh93, but it is also generally correct). This hasn't really mattered, as the difference is only significant (only causes actual issues - the build fails) when compiling with DEBUG enabled, which is something that most sane humans would never do, if they want to retain that sanity. The problem was detected by Patrick Welche when looking for an unrelated problem, which was once considered to be a possible sh problem, but turned out to be something entirely different. XXX pullup -8 To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.7.8.1 src/bin/sh/mkinit.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/mkinit.sh diff -u src/bin/sh/mkinit.sh:1.7 src/bin/sh/mkinit.sh:1.7.8.1 --- src/bin/sh/mkinit.sh:1.7 Sun Mar 27 14:34:46 2016 +++ src/bin/sh/mkinit.sh Sun Oct 21 12:00:32 2018 @@ -1,5 +1,5 @@ #! /bin/sh -# $NetBSD: mkinit.sh,v 1.7 2016/03/27 14:34:46 christos Exp $ +# $NetBSD: mkinit.sh,v 1.7.8.1 2018/10/21 12:00:32 martin Exp $ # Copyright (c) 2003 The NetBSD Foundation, Inc. # All rights reserved. @@ -33,7 +33,37 @@ srcs="$*" nl=' ' openparen='(' -backslash='\' + +# shells have bugs (including older NetBSD sh) in how \ is +# used in pattern matching. So work out what the shell +# running this script expects. We could also just use a +# literal \ in the pattern, which would need to be quoted +# of course, but then we'd run into a whole host of potential +# other shell bugs (both with the quoting in the pattern, and +# with the matching that follows if that works as inended). +# Far easier, and more reliable, is to just work out what works, +# and then use it, which more or less mandates using a variable... +backslash='\\' +var='abc\' # dummy test case. +if [ "$var" = "${var%$backslash}" ] +then + # buggy sh, try the broken way + backslash='\' + if [ "$var" = "${var%$backslash}" ] + then + printf >&2 "$0: %s\n" 'No pattern match with \ (broken shell)' + exit 1 + fi +fi +# We know we can detect the presence of a trailing \, which is all we need. +# Now to confirm we will not generate false matches. +var='abc' +if [ "$var" != "${var%$backslash}" ] +then + printf >&2 "$0: %s\n" 'Bogus pattern match with \ (broken shell)' + exit 1 +fi +unset var includes=' "shell.h" "mystring.h" "init.h" ' defines=
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Tue Oct 9 09:51:57 UTC 2018 Modified Files: src/bin/sh [netbsd-8]: jobs.c Log Message: Pull up following revision(s) (requested by kre in ticket #1050): bin/sh/jobs.c: revision 1.101 A change in rev 1.91 interacted badly with the way that showjobs() worked, preventing $(jobs) (and more usefully $(jobs -p) from working. Fix that. XXX pullup -8 To generate a diff of this commit: cvs rdiff -u -r1.85.2.2 -r1.85.2.3 src/bin/sh/jobs.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/jobs.c diff -u src/bin/sh/jobs.c:1.85.2.2 src/bin/sh/jobs.c:1.85.2.3 --- src/bin/sh/jobs.c:1.85.2.2 Fri Nov 17 14:56:52 2017 +++ src/bin/sh/jobs.c Tue Oct 9 09:51:57 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: jobs.c,v 1.85.2.2 2017/11/17 14:56:52 martin Exp $ */ +/* $NetBSD: jobs.c,v 1.85.2.3 2018/10/09 09:51:57 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: jobs.c,v 1.85.2.2 2017/11/17 14:56:52 martin Exp $"); +__RCSID("$NetBSD: jobs.c,v 1.85.2.3 2018/10/09 09:51:57 martin Exp $"); #endif #endif /* not lint */ @@ -578,14 +578,13 @@ showjobs(struct output *out, int mode) silent = 1; } #endif - if (jobs_invalid) - return; for (jobno = 1, jp = jobtab ; jobno <= njobs ; jobno++, jp++) { if (!jp->used) continue; if (jp->nprocs == 0) { - freejob(jp); + if (!jobs_invalid) +freejob(jp); continue; } if ((mode & SHOW_CHANGED) && !jp->changed)
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Mon Sep 10 15:45:11 UTC 2018 Modified Files: src/bin/sh [netbsd-8]: expand.c parser.c syntax.c syntax.h Log Message: Pull up following revision(s) via patch (requested by kre in ticket #1015): bin/sh/expand.c: revision 1.124 bin/sh/expand.c: revision 1.127 bin/sh/parser.c: revision 1.148 bin/sh/parser.c: revision 1.149 bin/sh/syntax.c: revision 1.6 bin/sh/syntax.h: revision 1.9 (partial) First pass at fixing some of the more arcane pattern matching possibilities that we do not currently handle all that well. This mostly means (for now) making sure that quoted pattern magic characters (as well as quoted sh syntax magic chars) are properly marked, so they remain known as being quoted, and do not turn into pattern magic. Also, make sure that an unquoted \ in a pattern always quotes whatever comes next (which, unlike in regular expressions, includes inside [] matches), - Part 2 of pattern matching (glob etc) fixes. Attempt to correctly deal with \ (both when it is a literal, in appropriate cases, and when it appears as CTLESC when it was detected as a quoting character during parsing). In a pattern, in sh, no quoted character can ever be anything other than a literal character. This is quite different than regular expressions, and even different than other uses of glob matching, where shell quoting is not an issue. In something like ls ?\*.c the ? is a meta-character, the * is a literal (it was quoted). This is nothing new, sh has handled that properly for ever. But the same happens with VAR='?\*.c' and ls $VAR which has not always been handled correctly. Of course, in ls "$VAR" nothing in VAR is a meta-character (the entire expansion is quoted) so even the '\' must match literally (or more accurately, no matching happens - VAR simply contains an "unusual" filename). But if it had been ls *"$VAR" then we would be looking for filenames that end with the literal 5 characters that make up $VAR. The same kinds of things are requires of matching patterns in case statements, and sub-strings with the % and # operators in variable expansions. While here, the final remnant of the ancient !! pattern matching hack has been removed (the code that actually implemented it was long gone, but one small piece remained, not doing any real harm, but potentially wasting time - if someone gave a pattern which would once have invoked that hack.) To generate a diff of this commit: cvs rdiff -u -r1.110.2.4 -r1.110.2.5 src/bin/sh/expand.c cvs rdiff -u -r1.132.2.5 -r1.132.2.6 src/bin/sh/parser.c cvs rdiff -u -r1.3.26.1 -r1.3.26.2 src/bin/sh/syntax.c cvs rdiff -u -r1.7.2.1 -r1.7.2.2 src/bin/sh/syntax.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/expand.c diff -u src/bin/sh/expand.c:1.110.2.4 src/bin/sh/expand.c:1.110.2.5 --- src/bin/sh/expand.c:1.110.2.4 Fri Jul 13 14:32:01 2018 +++ src/bin/sh/expand.c Mon Sep 10 15:45:11 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: expand.c,v 1.110.2.4 2018/07/13 14:32:01 martin Exp $ */ +/* $NetBSD: expand.c,v 1.110.2.5 2018/09/10 15:45:11 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95"; #else -__RCSID("$NetBSD: expand.c,v 1.110.2.4 2018/07/13 14:32:01 martin Exp $"); +__RCSID("$NetBSD: expand.c,v 1.110.2.5 2018/09/10 15:45:11 martin Exp $"); #endif #endif /* not lint */ @@ -924,7 +924,9 @@ evalvar(const char *p, int flag) varlen++; } else { while (*val) { - if (quotes && syntax[(int)*val] == CCTL) + if (quotes && (varflags & VSQUOTE) && + (syntax[(int)*val] == CCTL || + syntax[(int)*val] == CBACK)) STPUTC(CTLESC, expdest); STPUTC(*val++, expdest); } @@ -1106,7 +1108,7 @@ varvalue(const char *name, int quoted, i int num; char *p; int i; - char sep; + int sep; char **ap; char const *syntax; @@ -1164,10 +1166,14 @@ varvalue(const char *name, int quoted, i STRTODEST(p); if (!*ap) break; - if (sep) + if (sep) { +if (quoted && (flag & (EXP_GLOB|EXP_CASE)) && +(SQSYNTAX[sep] == CCTL || SQSYNTAX[sep] == CSBACK)) + STPUTC(CTLESC, expdest); STPUTC(sep, expdest); - else if ((flag & (EXP_SPLIT|EXP_IN_QUOTES)) == EXP_SPLIT - && !quoted && **ap != '\0') + } else + if ((flag & (EXP_SPLIT|EXP_IN_QUOTES)) == EXP_SPLIT + && !quoted && **ap != '\0') STPUTC('\0', expdest); } return; @@ -1457,22 +1463,59 @@ expmeta(char *enddir, char *name) metaflag = 1; else if (*p == '[') { q = p + 1; - if (*q == '!') + if (*q == '!' || *q == '^') q++; for (;;) { while (*q == CTLQUOTEMARK || *q == CTLNONL) q++; -if (*q == CTLESC) +if (*q == ']') { q++; -if (*q == '/' || *q == '\0')
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Sat Aug 25 17:14:39 UTC 2018 Modified Files: src/bin/sh [netbsd-8]: eval.c Log Message: Fix merge mishap due to #983 / #989 pullup order. To generate a diff of this commit: cvs rdiff -u -r1.140.2.6 -r1.140.2.7 src/bin/sh/eval.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/eval.c diff -u src/bin/sh/eval.c:1.140.2.6 src/bin/sh/eval.c:1.140.2.7 --- src/bin/sh/eval.c:1.140.2.6 Sat Aug 25 14:48:22 2018 +++ src/bin/sh/eval.c Sat Aug 25 17:14:38 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: eval.c,v 1.140.2.6 2018/08/25 14:48:22 martin Exp $ */ +/* $NetBSD: eval.c,v 1.140.2.7 2018/08/25 17:14:38 martin Exp $ */ /*- * Copyright (c) 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95"; #else -__RCSID("$NetBSD: eval.c,v 1.140.2.6 2018/08/25 14:48:22 martin Exp $"); +__RCSID("$NetBSD: eval.c,v 1.140.2.7 2018/08/25 17:14:38 martin Exp $"); #endif #endif /* not lint */ @@ -1058,7 +1058,6 @@ evalcommand(union node *cmd, int flgs, s switch (cmdentry.cmdtype) { case CMDFUNCTION: VXTRACE(DBG_EVAL, ("Shell function: "), trargs(argv)); - redirect(cmd->ncmd.redirect, flags & EV_MORE ? REDIR_PUSH : 0); redirect(cmd->ncmd.redirect, REDIR_PUSH); saveparam = shellparam; shellparam.malloc = 0;
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Sat Aug 25 14:48:22 UTC 2018 Modified Files: src/bin/sh [netbsd-8]: eval.c eval.h exec.c Log Message: Pull up following revision(s) (requested by kre in ticket #989): bin/sh/eval.c: revision 1.156 bin/sh/eval.h: revision 1.20 bin/sh/exec.c: revision 1.53 Fix several bugs in the command / type builtin ( including PR bin/48499 ) 1. Make command -pv (and -pV) work (which is not as easy as the PR suggests it might be (the "check and cause error" was there because it did not work, not in order to prevent it from working). 2. Stop -v and -V being both used (that makes no sense). 3. Stop the "type" builtin inheriting the args (-pvV) that "command" has (which it did, as when -v -or -V is used with command, it and type are implemented using the same code). 4. make "command -v word" DTRT for sh keywords (was treating them as an error). 5. Require at least one arg for "command -[vV]" or "type" else usage & error. Strictly this should also apply to "command" and "command -p" (no -v) but that's handled elsewhere, so perhaps some other time. Perhaps "command -v" (and -V) should be limited to 1 command name (where "type" can have many) as in the POSIX definitions, but I don't think that matters. 6. With "command -V alias", (or "type alias" which is the same thing), (but not "command -v alias") alter the output format, so we get ll is an alias for: ls -al instead of the old ll is an alias for ls -al (and note there was a space, for some reason, after "for") That is, unless the alias value contains any \n characters, in which case (something approximating) the old multi-line format is retained. Also note: that if code wants to parse/use the value of an alias, it should be using the output of "alias name", not command or type. Note that none of the above affects "command [-p] cmd" (no -v or -V options) only "command -[vV]" and "type". Note also that the changes to eval.[ch] are merely to make syspath() visible in exec.c rather than static in eval.c To generate a diff of this commit: cvs rdiff -u -r1.140.2.5 -r1.140.2.6 src/bin/sh/eval.c cvs rdiff -u -r1.19.8.1 -r1.19.8.2 src/bin/sh/eval.h cvs rdiff -u -r1.47.2.3 -r1.47.2.4 src/bin/sh/exec.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/eval.c diff -u src/bin/sh/eval.c:1.140.2.5 src/bin/sh/eval.c:1.140.2.6 --- src/bin/sh/eval.c:1.140.2.5 Sat Aug 25 14:22:49 2018 +++ src/bin/sh/eval.c Sat Aug 25 14:48:22 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: eval.c,v 1.140.2.5 2018/08/25 14:22:49 martin Exp $ */ +/* $NetBSD: eval.c,v 1.140.2.6 2018/08/25 14:48:22 martin Exp $ */ /*- * Copyright (c) 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95"; #else -__RCSID("$NetBSD: eval.c,v 1.140.2.5 2018/08/25 14:22:49 martin Exp $"); +__RCSID("$NetBSD: eval.c,v 1.140.2.6 2018/08/25 14:48:22 martin Exp $"); #endif #endif /* not lint */ @@ -696,7 +696,7 @@ evalbackcmd(union node *n, struct backcm result->fd, result->buf, result->nleft, result->jp)); } -static const char * +const char * syspath(void) { static char *sys_path = NULL; Index: src/bin/sh/eval.h diff -u src/bin/sh/eval.h:1.19.8.1 src/bin/sh/eval.h:1.19.8.2 --- src/bin/sh/eval.h:1.19.8.1 Sat Aug 25 14:22:49 2018 +++ src/bin/sh/eval.h Sat Aug 25 14:48:22 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: eval.h,v 1.19.8.1 2018/08/25 14:22:49 martin Exp $ */ +/* $NetBSD: eval.h,v 1.19.8.2 2018/08/25 14:48:22 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -52,6 +52,8 @@ union node; /* BLETCH for ansi C */ void evaltree(union node *, int); void evalbackcmd(union node *, struct backcmd *); +const char *syspath(void); + /* in_function returns nonzero if we are currently evaluating a function */ int in_function(void); /* return non-zero, if evaluating a function */ Index: src/bin/sh/exec.c diff -u src/bin/sh/exec.c:1.47.2.3 src/bin/sh/exec.c:1.47.2.4 --- src/bin/sh/exec.c:1.47.2.3 Fri Jul 13 14:29:15 2018 +++ src/bin/sh/exec.c Sat Aug 25 14:48:22 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: exec.c,v 1.47.2.3 2018/07/13 14:29:15 martin Exp $ */ +/* $NetBSD: exec.c,v 1.47.2.4 2018/08/25 14:48:22 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95"; #else -__RCSID("$NetBSD: exec.c,v 1.47.2.3 2018/07/13 14:29:15 martin Exp $"); +__RCSID("$NetBSD: exec.c,v 1.47.2.4 2018/08/25 14:48:22 martin Exp $"); #endif #endif /* not lint */ @@ -1064,8 +1064,15 @@ typecmd(int argc, char **argv) } } - if (p_flag && (v_flag || V_flag)) - error("cannot specify -p with -v or -V"); + if (argv[0][0] != 'c' && v_flag | V_flag | p_flag) + error("usage: %s name...", argv[0]); + + if (v_flag && V_flag) + error("-v and -V cannot both be specified"); + + if
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Sat Aug 25 14:45:37 UTC 2018 Modified Files: src/bin/sh [netbsd-8]: histedit.c mystring.c options.c parser.c var.c Log Message: Pull up following revision(s) (requested by kre in ticket #988): bin/sh/parser.c: revision 1.147 bin/sh/var.c: revision 1.70 bin/sh/mystring.c: revision 1.18 bin/sh/options.c: revision 1.53 bin/sh/histedit.c: revision 1.53 Remove atoi() Mostly use number() (no longer implemented using atoi()) when an unsigned integer is required, but use strtoXXX() when a conversion is wanted, without the possibility or error (like setting OPTIND and RANDOM). Always init OPTIND to 1 when sh starts (overriding anything in environ.) To generate a diff of this commit: cvs rdiff -u -r1.48.8.1 -r1.48.8.2 src/bin/sh/histedit.c cvs rdiff -u -r1.17 -r1.17.22.1 src/bin/sh/mystring.c cvs rdiff -u -r1.49 -r1.49.2.1 src/bin/sh/options.c cvs rdiff -u -r1.132.2.4 -r1.132.2.5 src/bin/sh/parser.c cvs rdiff -u -r1.55.2.2 -r1.55.2.3 src/bin/sh/var.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/histedit.c diff -u src/bin/sh/histedit.c:1.48.8.1 src/bin/sh/histedit.c:1.48.8.2 --- src/bin/sh/histedit.c:1.48.8.1 Sun Jul 23 14:58:14 2017 +++ src/bin/sh/histedit.c Sat Aug 25 14:45:37 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.c,v 1.48.8.1 2017/07/23 14:58:14 snj Exp $ */ +/* $NetBSD: histedit.c,v 1.48.8.2 2018/08/25 14:45:37 martin Exp $ */ /*- * Copyright (c) 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)histedit.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: histedit.c,v 1.48.8.1 2017/07/23 14:58:14 snj Exp $"); +__RCSID("$NetBSD: histedit.c,v 1.48.8.2 2018/08/25 14:45:37 martin Exp $"); #endif #endif /* not lint */ @@ -210,8 +210,8 @@ sethistsize(const char *hs) HistEvent he; if (hist != NULL) { - if (hs == NULL || *hs == '\0' || - (histsize = atoi(hs)) < 0) + if (hs == NULL || *hs == '\0' || *hs == '-' || + (histsize = number(hs)) < 0) histsize = 100; history(hist, , H_SETSIZE, histsize); history(hist, , H_SETUNIQUE, 1); @@ -529,7 +529,7 @@ str_to_event(const char *str, int last) s++; } if (is_number(s)) { - i = atoi(s); + i = number(s); if (relative) { while (retval != -1 && i--) { retval = history(hist, , H_NEXT); Index: src/bin/sh/mystring.c diff -u src/bin/sh/mystring.c:1.17 src/bin/sh/mystring.c:1.17.22.1 --- src/bin/sh/mystring.c:1.17 Sun Apr 28 17:01:28 2013 +++ src/bin/sh/mystring.c Sat Aug 25 14:45:37 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: mystring.c,v 1.17 2013/04/28 17:01:28 dholland Exp $ */ +/* $NetBSD: mystring.c,v 1.17.22.1 2018/08/25 14:45:37 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)mystring.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: mystring.c,v 1.17 2013/04/28 17:01:28 dholland Exp $"); +__RCSID("$NetBSD: mystring.c,v 1.17.22.1 2018/08/25 14:45:37 martin Exp $"); #endif #endif /* not lint */ @@ -51,6 +51,8 @@ __RCSID("$NetBSD: mystring.c,v 1.17 2013 * is_number(s) Return true if s is a string of digits. */ +#include +#include #include #include "shell.h" #include "syntax.h" @@ -110,10 +112,15 @@ prefix(const char *pfx, const char *stri int number(const char *s) { + char *ep = NULL; + intmax_t n; - if (! is_number(s)) - error("Illegal number: %s", s); - return atoi(s); + if (!is_digit(*s) || ((n = strtoimax(s, , 10)), + (ep == NULL || ep == s || *ep != '\0'))) + error("Illegal number: '%s'", s); + if (n < INT_MIN || n > INT_MAX) + error("Number out of range: %s", s); + return (int)n; } Index: src/bin/sh/options.c diff -u src/bin/sh/options.c:1.49 src/bin/sh/options.c:1.49.2.1 --- src/bin/sh/options.c:1.49 Mon May 29 14:03:23 2017 +++ src/bin/sh/options.c Sat Aug 25 14:45:37 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: options.c,v 1.49 2017/05/29 14:03:23 kre Exp $ */ +/* $NetBSD: options.c,v 1.49.2.1 2018/08/25 14:45:37 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: options.c,v 1.49 2017/05/29 14:03:23 kre Exp $"); +__RCSID("$NetBSD: options.c,v 1.49.2.1 2018/08/25 14:45:37 martin Exp $"); #endif #endif /* not lint */ @@ -60,6 +60,7 @@ __RCSID("$NetBSD: options.c,v 1.49 2017/ #include "memalloc.h" #include "error.h" #include "mystring.h" +#include "syntax.h" #ifndef SMALL #include "myhistedit.h" #endif @@ -444,7 +445,12 @@ setcmd(int argc, char **argv) void getoptsreset(const char *value) { - if (number(value) == 1) { + /* + * This is just to detect the case where OPTIND=1 + * is executed. Any other string assigned to OPTIND + * is OK, but is not a reset. No errors, so cannot use number() + */ + if (is_digit(*value) && strtol(value, NULL, 10) == 1) { shellparam.optnext = NULL;
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Sat Aug 25 14:41:22 UTC 2018 Modified Files: src/bin/sh [netbsd-8]: trap.c Log Message: Pull up following revision(s) (requested by kre in ticket #987): bin/sh/trap.c: revision 1.44 PR bin/36532 (perhaps) This is more or less the same patch as provided in the PR (just 11 years later, so changed a bit) by woods@... Since there is no known way to actually cause the reported crash, we may never know if this change actually fixes anything. But even if it doesn't it certainly cannot hurt. There is a potential race which could possibly explain the issue (see commentary in the PR) which is not easy to avoid - if that is the actual cause, this should provide a defence, if not really a fix. To generate a diff of this commit: cvs rdiff -u -r1.40.2.1 -r1.40.2.2 src/bin/sh/trap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/trap.c diff -u src/bin/sh/trap.c:1.40.2.1 src/bin/sh/trap.c:1.40.2.2 --- src/bin/sh/trap.c:1.40.2.1 Sun Jul 23 14:58:14 2017 +++ src/bin/sh/trap.c Sat Aug 25 14:41:21 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.40.2.1 2017/07/23 14:58:14 snj Exp $ */ +/* $NetBSD: trap.c,v 1.40.2.2 2018/08/25 14:41:21 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95"; #else -__RCSID("$NetBSD: trap.c,v 1.40.2.1 2017/07/23 14:58:14 snj Exp $"); +__RCSID("$NetBSD: trap.c,v 1.40.2.2 2018/08/25 14:41:21 martin Exp $"); #endif #endif /* not lint */ @@ -523,9 +523,11 @@ dotrap(void) savestatus=exitstatus; CTRACE(DBG_TRAP|DBG_SIG, ("dotrap %d: \"%s\"\n", i, trap[i] ? trap[i] : "-NULL-")); - tr = savestr(trap[i]); /* trap code may free trap[i] */ - evalstring(tr, 0); - ckfree(tr); + if ((tr = trap[i]) != NULL) { + tr = savestr(tr); /* trap code may free trap[i] */ + evalstring(tr, 0); + ckfree(tr); + } exitstatus=savestatus; } }
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Sat Aug 25 14:22:50 UTC 2018 Modified Files: src/bin/sh [netbsd-8]: eval.c eval.h main.c Log Message: Pull up following revision(s) (requested by kre in ticket #983): bin/sh/eval.c: revision 1.158 bin/sh/eval.h: revision 1.21 bin/sh/main.c: revision 1.74 PR bin/48875 Revert the changes that were made 19 May 2016 (principally eval.c 1.125) and the bug fixes in subsequent days (eval.c 1.126 and 1.127) and also update some newer code that was added more recently which acted in accordance with those changes (make that code be as it would have been if the changes now being reverted had never been made). While the changes made did solve the problem, in a sense, they were never correct (see the PR for some discussion) and it had always been intended that they be reverted. However, in practical sh code, no issues were reported - until just recently - so nothing was done, until now... After this commit, the validate_fn_redirects test case of the sh ATF test t_redir will fail. In particular, the subtest of that test case which is described in the source (of the test) as: This one is the real test for PR bin/48875 will fail. Alternative changes, not to "fix" the problem in the PR, but to often avoid it will be coming very soon - after which that ATF test will succeed again. XXX pullup-8 To generate a diff of this commit: cvs rdiff -u -r1.140.2.4 -r1.140.2.5 src/bin/sh/eval.c cvs rdiff -u -r1.19 -r1.19.8.1 src/bin/sh/eval.h cvs rdiff -u -r1.70.2.1 -r1.70.2.2 src/bin/sh/main.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/eval.c diff -u src/bin/sh/eval.c:1.140.2.4 src/bin/sh/eval.c:1.140.2.5 --- src/bin/sh/eval.c:1.140.2.4 Sat Aug 25 11:45:40 2018 +++ src/bin/sh/eval.c Sat Aug 25 14:22:49 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: eval.c,v 1.140.2.4 2018/08/25 11:45:40 martin Exp $ */ +/* $NetBSD: eval.c,v 1.140.2.5 2018/08/25 14:22:49 martin Exp $ */ /*- * Copyright (c) 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95"; #else -__RCSID("$NetBSD: eval.c,v 1.140.2.4 2018/08/25 11:45:40 martin Exp $"); +__RCSID("$NetBSD: eval.c,v 1.140.2.5 2018/08/25 14:22:49 martin Exp $"); #endif #endif /* not lint */ @@ -221,7 +221,7 @@ evalstring(char *s, int flag) while ((n = parsecmd(0)) != NEOF) { XTRACE(DBG_EVAL, ("evalstring: "), showtree(n)); if (n && nflag == 0) - evaltree(n, flag | EV_MORE); + evaltree(n, flag); popstackmark(); } popfile(); @@ -256,20 +256,19 @@ evaltree(union node *n, int flags) getpid(), n, NODETYPENAME(n->type), n->type, flags)); switch (n->type) { case NSEMI: - evaltree(n->nbinary.ch1, (sflags & EV_TESTED) | - (n->nbinary.ch2 ? EV_MORE : 0)); + evaltree(n->nbinary.ch1, flags & EV_TESTED); if (nflag || evalskip) goto out; evaltree(n->nbinary.ch2, flags); break; case NAND: - evaltree(n->nbinary.ch1, EV_TESTED | EV_MORE); + evaltree(n->nbinary.ch1, EV_TESTED); if (nflag || evalskip || exitstatus != 0) goto out; evaltree(n->nbinary.ch2, flags); break; case NOR: - evaltree(n->nbinary.ch1, EV_TESTED | EV_MORE); + evaltree(n->nbinary.ch1, EV_TESTED); if (nflag || evalskip || exitstatus == 0) goto out; evaltree(n->nbinary.ch2, flags); @@ -296,14 +295,14 @@ evaltree(union node *n, int flags) } break; case NSUBSHELL: - evalsubshell(n, flags & ~EV_MORE); + evalsubshell(n, flags); do_etest = !(flags & EV_TESTED); break; case NBACKGND: - evalsubshell(n, flags & ~EV_MORE); + evalsubshell(n, flags); break; case NIF: { - evaltree(n->nif.test, EV_TESTED | EV_MORE); + evaltree(n->nif.test, EV_TESTED); if (nflag || evalskip) goto out; if (exitstatus == 0) @@ -331,11 +330,11 @@ evaltree(union node *n, int flags) exitstatus = 0; break; case NNOT: - evaltree(n->nnot.com, (sflags & EV_MORE) | EV_TESTED); + evaltree(n->nnot.com, EV_TESTED); exitstatus = !exitstatus; break; case NDNOT: - evaltree(n->nnot.com, (sflags & EV_MORE) | EV_TESTED); + evaltree(n->nnot.com, EV_TESTED); if (exitstatus != 0) exitstatus = 1; break; @@ -379,7 +378,7 @@ evalloop(union node *n, int flags) CTRACE(DBG_EVAL, ("\n")); for (;;) { - evaltree(n->nbinary.ch1, EV_TESTED | EV_MORE); + evaltree(n->nbinary.ch1, EV_TESTED); if (nflag) break; if (evalskip) { @@ -398,7 +397,7 @@ evalloop(union node *n, int flags) if (exitstatus == 0) break; } - evaltree(n->nbinary.ch2, (flags & EV_TESTED) | EV_MORE); + evaltree(n->nbinary.ch2, flags & EV_TESTED); status = exitstatus; if (evalskip) goto skipping; @@ -431,11 +430,6 @@ evalfor(union node *n, int flags) loopnest++; for (sp = arglist.list ; sp ; sp = sp->next) { - int f = flags & (EV_TESTED | EV_MORE); - - if (sp->next) - f |= EV_MORE; - if (xflag) {
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Sat Aug 25 11:45:40 UTC 2018 Modified Files: src/bin/sh [netbsd-8]: eval.c Log Message: Pull up following revision(s) (requested by kre in ticket #982): bin/sh/eval.c: revision 1.157 PR bin/42184 PR bin/52687 (detailing the same bug). Fix "command not found" handling so that the error message goes to stderr (after any redirections are applied). More importantly, in foo > /tmp/junk /tmp/junk should be created, before any attempt is made to execute (the assumed non-existing) "foo". All this was always true for any command (not found command) containing a / in its name foo/bar >/tmp/junk 2>>/tmp/errs would have created /tmp/junk, then complained (in /tmp/errs) about foo/bar not being found. Now that happens for ordinary commands as well. The fix (which I found when I saw differences between our code and FreeBSD's, where, for the benefit of PR 42184, this has been fixed, sometime in the past 9 years) is frighteningly simple. Simply do not short circuit execution (or print any error) when the initial lookup fails to find the command - it will fail anyway when we actually try running it. The cost is a (seemingly unnecessary, except that it really is) fork in this case. This is what I had been planning, but I expected it would be much more difficult than it turned out XXX pullup-8 To generate a diff of this commit: cvs rdiff -u -r1.140.2.3 -r1.140.2.4 src/bin/sh/eval.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/eval.c diff -u src/bin/sh/eval.c:1.140.2.3 src/bin/sh/eval.c:1.140.2.4 --- src/bin/sh/eval.c:1.140.2.3 Fri Jul 13 14:29:15 2018 +++ src/bin/sh/eval.c Sat Aug 25 11:45:40 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: eval.c,v 1.140.2.3 2018/07/13 14:29:15 martin Exp $ */ +/* $NetBSD: eval.c,v 1.140.2.4 2018/08/25 11:45:40 martin Exp $ */ /*- * Copyright (c) 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95"; #else -__RCSID("$NetBSD: eval.c,v 1.140.2.3 2018/07/13 14:29:15 martin Exp $"); +__RCSID("$NetBSD: eval.c,v 1.140.2.4 2018/08/25 11:45:40 martin Exp $"); #endif #endif /* not lint */ @@ -903,7 +903,7 @@ evalcommand(union node *cmd, int flgs, s cmdentry.u.bltin = bltincmd; } else { static const char PATH[] = "PATH="; - int cmd_flags = DO_ERR; + int cmd_flags = 0; /* * Modify the command lookup path, if a PATH= assignment @@ -917,11 +917,20 @@ evalcommand(union node *cmd, int flgs, s int argsused, use_syspath; find_command(argv[0], , cmd_flags, path); +#if 0 + /* + * This short circuits all of the processing that + * should be done (including processing the + * redirects), so just don't ... + * + * (eventually this whole #if'd block will vanish) + */ if (cmdentry.cmdtype == CMDUNKNOWN) { exitstatus = 127; flushout(); goto out; } +#endif /* implement the 'command' builtin here */ if (cmdentry.cmdtype != CMDBUILTIN || @@ -947,9 +956,10 @@ evalcommand(union node *cmd, int flgs, s /* Fork off a child process if necessary. */ if (cmd->ncmd.backgnd || (trap[0] && (flags & EV_EXIT) != 0) - || (cmdentry.cmdtype == CMDNORMAL && (flags & EV_EXIT) == 0) - || ((flags & EV_BACKCMD) != 0 - && ((cmdentry.cmdtype != CMDBUILTIN && cmdentry.cmdtype != CMDSPLBLTIN) + || ((cmdentry.cmdtype == CMDNORMAL || cmdentry.cmdtype == CMDUNKNOWN) + && (flags & EV_EXIT) == 0) + || ((flags & EV_BACKCMD) != 0 && + ((cmdentry.cmdtype != CMDBUILTIN && cmdentry.cmdtype != CMDSPLBLTIN) || cmdentry.u.bltin == dotcmd || cmdentry.u.bltin == evalcmd))) { INTOFF;
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Fri Jul 13 14:32:01 UTC 2018 Modified Files: src/bin/sh [netbsd-8]: expand.c Log Message: Pull up following revision(s) (requested by kre in ticket #907): bin/sh/expand.c: revision 1.122 When matching a char class ([[:name:]]) in a pattern (for filename expansion, case patterrns, etc) do not force '[' to be a member of every class. Before this fix, try: case [ in [[:alpha:]]) echo Huh\?;; esac XXX pullup-8(Perhaps -7 as well, though that shell version has much more relevant bugs than this one.) This bug is not in -6 as that has no charclass support. To generate a diff of this commit: cvs rdiff -u -r1.110.2.3 -r1.110.2.4 src/bin/sh/expand.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/expand.c diff -u src/bin/sh/expand.c:1.110.2.3 src/bin/sh/expand.c:1.110.2.4 --- src/bin/sh/expand.c:1.110.2.3 Wed Oct 25 06:51:36 2017 +++ src/bin/sh/expand.c Fri Jul 13 14:32:01 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: expand.c,v 1.110.2.3 2017/10/25 06:51:36 snj Exp $ */ +/* $NetBSD: expand.c,v 1.110.2.4 2018/07/13 14:32:01 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95"; #else -__RCSID("$NetBSD: expand.c,v 1.110.2.3 2017/10/25 06:51:36 snj Exp $"); +__RCSID("$NetBSD: expand.c,v 1.110.2.4 2018/07/13 14:32:01 martin Exp $"); #endif #endif /* not lint */ @@ -1774,8 +1774,10 @@ patmatch(const char *pattern, const char } if (c == '[' && *p == ':') { found |= match_charclass(p, chr, ); - if (end != NULL) + if (end != NULL) { p = end; + continue; + } } if (c == CTLESC) c = *p++;
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Fri Jul 13 14:29:15 UTC 2018 Modified Files: src/bin/sh [netbsd-8]: eval.c exec.c exec.h mknodes.sh nodes.c.pat Log Message: Pull up following revision(s) (requested by kre in ticket #906): bin/sh/eval.c: revision 1.155 bin/sh/mknodes.sh: revision 1.3 bin/sh/nodes.c.pat: revision 1.14 bin/sh/exec.h: revision 1.27 bin/sh/exec.c: revision 1.52 Deal with ref after free found by ASAN when a function redefines itself, or some other function which is still active. This was a long known bug (fixed ages ago in the FreeBSD sh) which hadn't been fixed as in practice, the situation that causes the problem simply doesn't arise .. ASAN found it in the sh dotcmd tests which do have this odd "feature" in the way they are written (but where it never caused a problem, as the tests are so simple that no mem is ever allocated between when the old version of the function was deleted, and when it finished executing, so its code all remained intact, despite having been freed.) The fix is taken from the FreeBSD sh. XXX -- pullup-8 (after a while to ensure no other problems arise). To generate a diff of this commit: cvs rdiff -u -r1.140.2.2 -r1.140.2.3 src/bin/sh/eval.c cvs rdiff -u -r1.47.2.2 -r1.47.2.3 src/bin/sh/exec.c cvs rdiff -u -r1.24.8.2 -r1.24.8.3 src/bin/sh/exec.h cvs rdiff -u -r1.2 -r1.2.56.1 src/bin/sh/mknodes.sh cvs rdiff -u -r1.13 -r1.13.26.1 src/bin/sh/nodes.c.pat Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/eval.c diff -u src/bin/sh/eval.c:1.140.2.2 src/bin/sh/eval.c:1.140.2.3 --- src/bin/sh/eval.c:1.140.2.2 Sun Jul 23 14:58:14 2017 +++ src/bin/sh/eval.c Fri Jul 13 14:29:15 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: eval.c,v 1.140.2.2 2017/07/23 14:58:14 snj Exp $ */ +/* $NetBSD: eval.c,v 1.140.2.3 2018/07/13 14:29:15 martin Exp $ */ /*- * Copyright (c) 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95"; #else -__RCSID("$NetBSD: eval.c,v 1.140.2.2 2017/07/23 14:58:14 snj Exp $"); +__RCSID("$NetBSD: eval.c,v 1.140.2.3 2018/07/13 14:29:15 martin Exp $"); #endif #endif /* not lint */ @@ -1067,6 +1067,7 @@ evalcommand(union node *cmd, int flgs, s INTOFF; savelocalvars = localvars; localvars = NULL; + reffunc(cmdentry.u.func); INTON; if (setjmp(jmploc.loc)) { if (exception == EXSHELLPROC) { @@ -1076,6 +1077,7 @@ evalcommand(union node *cmd, int flgs, s freeparam(); shellparam = saveparam; } + unreffunc(cmdentry.u.func); poplocalvars(); localvars = savelocalvars; funclinebase = savefuncline; @@ -1094,8 +1096,8 @@ evalcommand(union node *cmd, int flgs, s VTRACE(DBG_EVAL, ("function: node: %d '%s' # %d%s; funclinebase=%d\n", - cmdentry.u.func->type, - NODETYPENAME(cmdentry.u.func->type), + getfuncnode(cmdentry.u.func)->type, + NODETYPENAME(getfuncnode(cmdentry.u.func)->type), cmdentry.lineno, cmdentry.lno_frel?" (=1)":"", funclinebase)); } @@ -1103,9 +1105,10 @@ evalcommand(union node *cmd, int flgs, s /* stop shell blowing its stack */ if (++funcnest > 1000) error("too many nested function calls"); - evaltree(cmdentry.u.func, flags & EV_TESTED); + evaltree(getfuncnode(cmdentry.u.func), flags & EV_TESTED); funcnest--; INTOFF; + unreffunc(cmdentry.u.func); poplocalvars(); localvars = savelocalvars; funclinebase = savefuncline; Index: src/bin/sh/exec.c diff -u src/bin/sh/exec.c:1.47.2.2 src/bin/sh/exec.c:1.47.2.3 --- src/bin/sh/exec.c:1.47.2.2 Sun Jul 23 14:58:14 2017 +++ src/bin/sh/exec.c Fri Jul 13 14:29:15 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: exec.c,v 1.47.2.2 2017/07/23 14:58:14 snj Exp $ */ +/* $NetBSD: exec.c,v 1.47.2.3 2018/07/13 14:29:15 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95"; #else -__RCSID("$NetBSD: exec.c,v 1.47.2.2 2017/07/23 14:58:14 snj Exp $"); +__RCSID("$NetBSD: exec.c,v 1.47.2.3 2018/07/13 14:29:15 martin Exp $"); #endif #endif /* not lint */ @@ -481,8 +481,9 @@ printentry(struct tblentry *cmdp, int ve out1fmt("%s", cmdp->cmdname); if (verbose) { struct procstat ps; + INTOFF; - commandtext(, cmdp->param.func); + commandtext(, getfuncnode(cmdp->param.func)); INTON; out1str("() { "); out1str(ps.cmd); @@ -989,9 +990,8 @@ addcmdentry(char *name, struct cmdentry INTOFF; cmdp = cmdlookup(name, 1); if (cmdp->cmdtype != CMDSPLBLTIN) { - if (cmdp->cmdtype == CMDFUNCTION) { - freefunc(cmdp->param.func); - } + if (cmdp->cmdtype == CMDFUNCTION) + unreffunc(cmdp->param.func); cmdp->cmdtype = entry->cmdtype; cmdp->lineno = entry->lineno; cmdp->fn_ln1 = entry->lno_frel; @@ -1031,7 +1031,7 @@ unsetfunc(char *name) if ((cmdp = cmdlookup(name, 0)) != NULL && cmdp->cmdtype ==
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Sun May 6 09:32:57 UTC 2018 Modified Files: src/bin/sh [netbsd-8]: parser.c Log Message: Pull up following revision(s) (requested by kre in ticket #804): bin/sh/parser.c: revision 1.146 PR bin/53201 Don't synerr on ${var-anything more} The newline in the middle of the var expansion is permitted. Bug reported by Martijn Dekker from his modernish tests. XXX pullup-8 To generate a diff of this commit: cvs rdiff -u -r1.132.2.3 -r1.132.2.4 src/bin/sh/parser.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/parser.c diff -u src/bin/sh/parser.c:1.132.2.3 src/bin/sh/parser.c:1.132.2.4 --- src/bin/sh/parser.c:1.132.2.3 Fri Nov 17 20:33:53 2017 +++ src/bin/sh/parser.c Sun May 6 09:32:57 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: parser.c,v 1.132.2.3 2017/11/17 20:33:53 snj Exp $ */ +/* $NetBSD: parser.c,v 1.132.2.4 2018/05/06 09:32:57 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95"; #else -__RCSID("$NetBSD: parser.c,v 1.132.2.3 2017/11/17 20:33:53 snj Exp $"); +__RCSID("$NetBSD: parser.c,v 1.132.2.4 2018/05/06 09:32:57 martin Exp $"); #endif #endif /* not lint */ @@ -1636,7 +1636,7 @@ readtoken1(int firstc, char const *syn, CHECKSTRSPACE(4, out); /* permit 4 calls to USTPUTC */ switch (syntax[c]) { case CNL: /* '\n' */ - if (syntax == BASESYNTAX) + if (syntax == BASESYNTAX && varnest == 0) break; /* exit loop */ USTPUTC(c, out); plinno++;
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Thu Nov 23 13:26:01 UTC 2017 Modified Files: src/bin/sh [netbsd-8]: output.c Log Message: Pull up following revision(s) (requested by kre in ticket #384): bin/sh/output.c: revision 1.37 Improve quoting in xtrace (-x) output ... if a string ("word") to be output includes a single quote (') then see if using double-quotes to quote it is reasonable (if no chars that are magic in " also appear). If so, and if the string is not entirely the ' character, then use " quoting. This avoids some ugly looking results (occasionally). Also, fix a bug introduced about 20 months ago where null strings in xtrace output are dropped, instead of made explicit (''). To observe this, before you get the fix: set -x; echo '' (or similar.) Move a comment from the wrong place to the right place. To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.36.2.1 src/bin/sh/output.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/output.c diff -u src/bin/sh/output.c:1.36 src/bin/sh/output.c:1.36.2.1 --- src/bin/sh/output.c:1.36 Thu May 18 13:31:10 2017 +++ src/bin/sh/output.c Thu Nov 23 13:26:01 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: output.c,v 1.36 2017/05/18 13:31:10 kre Exp $ */ +/* $NetBSD: output.c,v 1.36.2.1 2017/11/23 13:26:01 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)output.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: output.c,v 1.36 2017/05/18 13:31:10 kre Exp $"); +__RCSID("$NetBSD: output.c,v 1.36.2.1 2017/11/23 13:26:01 martin Exp $"); #endif #endif /* not lint */ @@ -146,6 +146,11 @@ out2shstr(const char *p) } +/* + * ' is in this list, not because it does not require quoting + * (which applies to all the others) but because '' quoting cannot + * be used to quote it. + */ static const char norm_chars [] = \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/+-=_,.'"; @@ -158,25 +163,42 @@ inquote(const char *p) return s == NULL ? p[l] != '\0' : s - p > (off_t)l; } - void outshstr(const char *p, struct output *file) { - /* - * ' is in this list, not because it does not require quoting - * (which applies to all the others) but because '' quoting cannot - * be used to quote it. - */ - int need_q = p[0] == 0 || p[strspn(p, norm_chars)] != 0; + int need_q; int inq; char c; + if (strchr(p, '\'') != NULL && p[1] != '\0') { + /* + * string contains ' in it, and is not only the ' + * see if " quoting will work + */ + size_t i = strcspn(p, "\\\"$`"); + + if (p[i] == '\0') { + /* + * string contains no $ ` \ or " chars, perfect... + * + * We know it contains ' so needs quoting, so + * this is easy... + */ + outc('"', file); + outstr(p, file); + outc('"', file); + return; + } + } + + need_q = p[0] == 0 || p[strspn(p, norm_chars)] != 0; + /* * Don't emit ' unless something needs quoting before closing ' */ - if (need_q) { - if ((inq = inquote(p)) != 0) - outc('\'', file); + if (need_q && (p[0] == 0 || inquote(p) != 0)) { + outc('\'', file); + inq = 1; } else inq = 0;
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: snj Date: Fri Nov 17 20:33:53 UTC 2017 Modified Files: src/bin/sh [netbsd-8]: parser.c Log Message: Pull up following revision(s) (requested by kre in ticket #355): bin/sh/parser.c: revision 1.145 PR bin/52715 Correct a (relatively harmless) use after free in prompt expansion processing [detected by asan.] Relatively harmless: as (while incorrect) the way the data is (was) used more or less guaranteed that the buffer contents would be unaltered until well after they are (were) no longer wanted (this is the expanded prompt string, it is just output (or copied into libedit internal storage) and forgotten. This should make no visible difference to anyone (not using asan or similar.) To generate a diff of this commit: cvs rdiff -u -r1.132.2.2 -r1.132.2.3 src/bin/sh/parser.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/parser.c diff -u src/bin/sh/parser.c:1.132.2.2 src/bin/sh/parser.c:1.132.2.3 --- src/bin/sh/parser.c:1.132.2.2 Wed Aug 9 05:35:18 2017 +++ src/bin/sh/parser.c Fri Nov 17 20:33:53 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: parser.c,v 1.132.2.2 2017/08/09 05:35:18 snj Exp $ */ +/* $NetBSD: parser.c,v 1.132.2.3 2017/11/17 20:33:53 snj Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95"; #else -__RCSID("$NetBSD: parser.c,v 1.132.2.2 2017/08/09 05:35:18 snj Exp $"); +__RCSID("$NetBSD: parser.c,v 1.132.2.3 2017/11/17 20:33:53 snj Exp $"); #endif #endif /* not lint */ @@ -2227,9 +2227,27 @@ getprompt(void *unused) * Expand a string ... used for expanding prompts (PS1...) * * Never return NULL, always some string (return input string if invalid) + * + * The internal routine does the work, leaving the result on the + * stack (or in a static string, or even the input string) and + * handles parser recursion, and cleanup after an error while parsing. + * + * The visible interface copies the result off the stack (if it is there), + * and handles stack management, leaving the stack in the exact same + * state it was when expandstr() was called (so it can be used part way + * through building a stack data structure - as in when PS2 is being + * expanded half way through reading a "command line") + * + * on error, expandonstack() cleans up the parser state, but then + * simply jumps out through expandstr() withut doing any stack cleanup, + * which is OK, as the error handler must deal with that anyway. + * + * The split into two funcs is to avoid problems with setjmp/longjmp + * and local variables which could otherwise be optimised into bizarre + * behaviour. */ -const char * -expandstr(char *ps, int lineno) +static const char * +expandonstack(char *ps, int lineno) { union node n; struct jmploc jmploc; @@ -2238,20 +2256,8 @@ expandstr(char *ps, int lineno) const int save_x = xflag; struct parse_state new_state = init_parse_state; struct parse_state *const saveparser = psp.v_current_parser; - struct stackmark smark; const char *result = NULL; - setstackmark(); - /* - * At this point we anticipate that there may be a string - * growing on the stack, but we have no idea how big it is. - * However we know that it cannot be bigger than the current - * allocated stack block, so simply reserve the whole thing, - * then we can use the stack without barfing all over what - * is there already... (the stack mark undoes this later.) - */ - (void) stalloc(stackblocksize()); - if (!setjmp(jmploc.loc)) { handler = @@ -2278,7 +2284,6 @@ expandstr(char *ps, int lineno) xflag = save_x; popfilesupto(savetopfile); handler = savehandler; - popstackmark(); if (result != NULL) { INTON; @@ -2290,3 +2295,71 @@ expandstr(char *ps, int lineno) return result; } + +const char * +expandstr(char *ps, int lineno) +{ + const char *result = NULL; + struct stackmark smark; + static char *buffer = NULL; /* storage for prompt, never freed */ + static size_t bufferlen = 0; + + setstackmark(); + /* + * At this point we anticipate that there may be a string + * growing on the stack, but we have no idea how big it is. + * However we know that it cannot be bigger than the current + * allocated stack block, so simply reserve the whole thing, + * then we can use the stack without barfing all over what + * is there already... (the stack mark undoes this later.) + */ + (void) stalloc(stackblocksize()); + + result = expandonstack(ps, lineno); + + if (__predict_true(result == stackblock())) { + size_t len = strlen(result) + 1; + + /* + * the result (usual case) is on the stack, which we + * are just about to discard (popstackmark()) so we + * need to move it somewhere safe first. + */ + + if (__predict_false(len > bufferlen)) { + char *new; + size_t newlen = bufferlen; + + if (__predict_false(len > (SIZE_MAX >> 4))) { +result =
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Fri Nov 17 14:56:52 UTC 2017 Modified Files: src/bin/sh [netbsd-8]: jobs.c Log Message: Pull up following revision(s) (requested by kre in ticket #337): bin/sh/jobs.c: revision 1.91 (patch) PR bin/52640 PR bin/52641 Don't delete jobs from the jobs table merely because they finished, if they are not the job we are waiting upon. (bin/52640 part 1) In a sub-shell environment, don't allow wait to find jobs from the parent shell that had already exited (before the sub-shell was created) and return status for them as if they are our children. (bin/52640 part 2) Don't have the "jobs" command also be an implicit "wait" command in non-interactive shells. (bin/52641) Use WCONTINUED (when it exists) so we can report on stopped jobs that "mysteriously" move back to running state without the user issuing a "bg" command (eg: kill -CONT ) Previously they would keep being reported as stopped until they exited. When a job is detected as having changed status just as we're issuing a "jobs" command (i.e.: the change occurred between the last prompt and the jobs command being entered) don't report it twice, once from the status change, and then again in the jobs command output. Once is enough (keep the jobs output, suppress the other). Apply some sanity to the way jobs_invalid is processed - ignore it in getjob() instead of just ignoring it most of the time there, and instead always check it before calling getjob() in situations where we can handle only children of the current shell. This allows the (totally broken) save/clear/restore of jobs_invalid in jobscmd() to be done away with (previously an error while in the clear state would have left jobs_invalid incorrectly cleared - shouldn't have mattered since jobs_invalid => subshell => error causes exit, but better to be safe). Add/improve the DEBUG more tracing. To generate a diff of this commit: cvs rdiff -u -r1.85.2.1 -r1.85.2.2 src/bin/sh/jobs.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/jobs.c diff -u src/bin/sh/jobs.c:1.85.2.1 src/bin/sh/jobs.c:1.85.2.2 --- src/bin/sh/jobs.c:1.85.2.1 Sun Jul 23 14:58:14 2017 +++ src/bin/sh/jobs.c Fri Nov 17 14:56:52 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: jobs.c,v 1.85.2.1 2017/07/23 14:58:14 snj Exp $ */ +/* $NetBSD: jobs.c,v 1.85.2.2 2017/11/17 14:56:52 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: jobs.c,v 1.85.2.1 2017/07/23 14:58:14 snj Exp $"); +__RCSID("$NetBSD: jobs.c,v 1.85.2.2 2017/11/17 14:56:52 martin Exp $"); #endif #endif /* not lint */ @@ -82,6 +82,14 @@ __RCSID("$NetBSD: jobs.c,v 1.85.2.1 2017 #include "mystring.h" +#ifndef WCONTINUED +#define WCONTINUED 0 /* So we can compile on old systems */ +#endif +#ifndef WIFCONTINUED +#define WIFCONTINUED(x) (0) /* ditto */ +#endif + + static struct job *jobtab; /* array of jobs */ static int njobs; /* size of array */ static int jobs_invalid; /* set in child */ @@ -98,6 +106,7 @@ STATIC struct job *getjob(const char *, STATIC int dowait(int, struct job *); #define WBLOCK 1 #define WNOFREE 2 +#define WSILENT 4 STATIC int waitproc(int, struct job *, int *); STATIC void cmdtxt(union node *); STATIC void cmdlist(union node *, int); @@ -246,6 +255,8 @@ do_fgcmd(const char *arg_ptr) int i; int status; + if (jobs_invalid) + error("No current jobs"); jp = getjob(arg_ptr, 0); if (jp->jobctl == 0) error("job not created under job control"); @@ -338,6 +349,8 @@ bgcmd(int argc, char **argv) int i; nextopt(""); + if (jobs_invalid) + error("No current jobs"); do { jp = getjob(*argptr, 0); if (jp->jobctl == 0) @@ -467,7 +480,7 @@ showjob(struct output *out, struct job * fmtstr(s + col, 16, "Done"); } else { #if JOBS - if (WIFSTOPPED(ps->status)) + if (WIFSTOPPED(ps->status)) st = WSTOPSIG(ps->status); else /* WIFSIGNALED(ps->status) */ #endif @@ -511,22 +524,21 @@ int jobscmd(int argc, char **argv) { int mode, m; - int sv = jobs_invalid; - jobs_invalid = 0; mode = 0; while ((m = nextopt("lp"))) if (m == 'l') mode = SHOW_PID; else mode = SHOW_PGID; + if (!iflag) + mode |= SHOW_NO_FREE; if (*argptr) do showjob(out1, getjob(*argptr,0), mode); while (*++argptr); else showjobs(out1, mode); - jobs_invalid = sv; return 0; } @@ -550,8 +562,8 @@ showjobs(struct output *out, int mode) CTRACE(DBG_JOBS, ("showjobs(%x) called\n", mode)); /* If not even one one job changed, there is nothing to do */ - gotpid = dowait(0, NULL); - while (dowait(0, NULL) > 0) + gotpid = dowait(WSILENT, NULL); + while (dowait(WSILENT, NULL) > 0) continue; #ifdef JOBS /* @@ -617,11 +629,20 @@ waitcmd(int argc, char **argv) nextopt(""); + /* + * If we have forked, and not yet created
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: snj Date: Wed Oct 25 07:03:10 UTC 2017 Modified Files: src/bin/sh [netbsd-8]: sh.1 Log Message: Pull up following revision(s) (requested by kre in ticket #323): bin/sh/sh.1: revision 1.168 Fix typo: s/one or mode/one or more/ To generate a diff of this commit: cvs rdiff -u -r1.146.2.4 -r1.146.2.5 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/sh.1 diff -u src/bin/sh/sh.1:1.146.2.4 src/bin/sh/sh.1:1.146.2.5 --- src/bin/sh/sh.1:1.146.2.4 Wed Oct 25 06:51:36 2017 +++ src/bin/sh/sh.1 Wed Oct 25 07:03:10 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.146.2.4 2017/10/25 06:51:36 snj Exp $ +.\" $NetBSD: sh.1,v 1.146.2.5 2017/10/25 07:03:10 snj Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -1895,7 +1895,7 @@ exit status of the preceding command (th .It export Oo Fl npx Oc Ar name ... .It export Fl p Oo Fl x Oc With no options, -but one or mode names, +but one or more names, the specified names are exported so that they will appear in the environment of subsequent commands. With
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: snj Date: Wed Oct 25 06:51:36 UTC 2017 Modified Files: src/bin/sh [netbsd-8]: expand.c sh.1 Log Message: Pull up following revision(s) (requested by kre in ticket #310): bin/sh/expand.c: revision 1.121 bin/sh/sh.1: revision 1.167 via patch Three fixes and a change to ~ expansions 1. A serious bug introduced 3 1/2 months ago (approx) (rev 1.116) which broke all but the simple cases of ~ expansions is fixed (amazingly, given the magnitude of this problem, no-one noticed!) 2. An ancient bug (probably from when ~ expansion was first addedin 1994, and certainly is in NetBSD-6 vintage shells) where ${UnSeT:-~} (and similar) does not expand the ~ is fixed (note that ${UnSeT:-~/} does expand, this should give a clue to the cause of the problem. 3. A fix/change to make the effects of ~ expansions on ${UnSeT:=whatever} identical to those in UnSeT=whatever In particular, with HOME=/foo ${UnSeT:=~:~} now assigns, and expands to, /foo:/foo rather than ~:~ just as VAR=~:~ assigns /foo:/foo to VAR. Note this is even after the previous fix (ie: appending a '/' would not change the results here.) It is hard to call this one a bug fix for certain (though I believe it is) as many other shells also produce different results for the ${V:=...} expansions than they do for V=... (though not all the same as we did). POSIX is not clear about this, expanding ~ after : in VAR=whatever assignments is clear, whether ${U:=whatever} assignments should be treated the same way is not stated, one way or the other. 4. Change to make ':' terminate the user name in a ~ expansion in all cases, not only in assignments. This makes sense, as ':' is one character that cannot occur in user names, no matter how otherwise weird they become. bash (incl in posix mode) ksh93 and bosh all act this way, whereas most other shells (and POSIX) do not. Because this is clearly an extension to POSIX, do this one only when not in posix mode (not set -o posix). To generate a diff of this commit: cvs rdiff -u -r1.110.2.2 -r1.110.2.3 src/bin/sh/expand.c cvs rdiff -u -r1.146.2.3 -r1.146.2.4 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/expand.c diff -u src/bin/sh/expand.c:1.110.2.2 src/bin/sh/expand.c:1.110.2.3 --- src/bin/sh/expand.c:1.110.2.2 Sun Jul 23 14:58:14 2017 +++ src/bin/sh/expand.c Wed Oct 25 06:51:36 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: expand.c,v 1.110.2.2 2017/07/23 14:58:14 snj Exp $ */ +/* $NetBSD: expand.c,v 1.110.2.3 2017/10/25 06:51:36 snj Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95"; #else -__RCSID("$NetBSD: expand.c,v 1.110.2.2 2017/07/23 14:58:14 snj Exp $"); +__RCSID("$NetBSD: expand.c,v 1.110.2.3 2017/10/25 06:51:36 snj Exp $"); #endif #endif /* not lint */ @@ -358,6 +358,7 @@ exptilde(const char *p, int flag) #endif setstackmark(); + (void) grabstackstr(expdest); user = stackblock(); /* we will just borrow top of stack */ while ((c = *++p) != '\0') { @@ -369,16 +370,16 @@ exptilde(const char *p, int flag) case CTLARI: /* just leave original unchanged */ case CTLENDARI: case CTLQUOTEMARK: - case CTLENDVAR: case '\n': popstackmark(); return (startp); case CTLNONL: continue; case ':': - if (flag & EXP_VARTILDE) + if (!posix || flag & EXP_VARTILDE) goto done; break; + case CTLENDVAR: case '/': goto done; } @@ -679,7 +680,7 @@ subevalvar(const char *p, const char *st herefd = -1; VTRACE(DBG_EXPAND, ("subevalvar(%d) \"%.20s\" ${%.*s} sloc=%d vf=%x\n", subtype, p, p-str, str, startloc, varflags)); - argstr(p, EXP_TILDE); + argstr(p, subtype == VSASSIGN ? EXP_VARTILDE : EXP_TILDE); STACKSTRNUL(expdest); herefd = saveherefd; argbackq = saveargbackq; Index: src/bin/sh/sh.1 diff -u src/bin/sh/sh.1:1.146.2.3 src/bin/sh/sh.1:1.146.2.4 --- src/bin/sh/sh.1:1.146.2.3 Sun Jul 23 14:58:14 2017 +++ src/bin/sh/sh.1 Wed Oct 25 06:51:36 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.146.2.3 2017/07/23 14:58:14 snj Exp $ +.\" $NetBSD: sh.1,v 1.146.2.4 2017/10/25 06:51:36 snj Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -31,7 +31,7 @@ .\" .\" @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" -.Dd July 1, 2017 +.Dd October 6, 2017 .Dt SH 1 .\" everything except c o and s (keep them ordered) .ds flags abCEeFfhIiLmnpquVvx @@ -472,6 +472,10 @@ opened using the built-in command are passed on to utilities executed .Dq ( yes in posix mode), +whether a colon (:) terminates the user name in tilde (~) expansions +other than in assignment statements +.Dq ( no +in posix mode), and whether the shell treats an empty brace-list compound statement as a syntax error (expected by POSIX) or
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: martin Date: Thu Aug 31 11:43:44 UTC 2017 Modified Files: src/bin/sh [netbsd-8]: var.c Log Message: Pull up following revision(s) (requested by kre in ticket #250): bin/sh/var.c: revision 1.67 Fix a bug noticed by Soren Jacobsen running the netbsd-6-0 build.sh which causes a core dump in some exotic circumstances (when restoring local variables when a function returns). ("build.sh makewrapper" exposed it.) This was introduced in 1.63 - not as part of the substance of that change (addition) but as an unrelated "must be the right thing to do" cleanup, which wasn't... To generate a diff of this commit: cvs rdiff -u -r1.55.2.1 -r1.55.2.2 src/bin/sh/var.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/var.c diff -u src/bin/sh/var.c:1.55.2.1 src/bin/sh/var.c:1.55.2.2 --- src/bin/sh/var.c:1.55.2.1 Sun Jul 23 14:58:14 2017 +++ src/bin/sh/var.c Thu Aug 31 11:43:44 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.55.2.1 2017/07/23 14:58:14 snj Exp $ */ +/* $NetBSD: var.c,v 1.55.2.2 2017/08/31 11:43:44 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: var.c,v 1.55.2.1 2017/07/23 14:58:14 snj Exp $"); +__RCSID("$NetBSD: var.c,v 1.55.2.2 2017/08/31 11:43:44 martin Exp $"); #endif #endif /* not lint */ @@ -472,7 +472,7 @@ setvareq(char *s, int flags) return; } vp = ckmalloc(sizeof (*vp)); - vp->flags = flags & ~(VNOFUNC|VFUNCREF|VSTRFIXED); + vp->flags = flags & ~(VNOFUNC|VFUNCREF); vp->text = s; vp->name_len = nlen; vp->next = *vpp;
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: snj Date: Wed Aug 9 05:35:19 UTC 2017 Modified Files: src/bin/sh [netbsd-8]: input.c parser.c Log Message: Pull up following revision(s) (requested by kre in ticket #199): bin/sh/input.c: revision 1.61 bin/sh/parser.c: revision 1.143 PR bin/52458 Avoid mangling history when editing is enabled, and the prompt contains a \n Also, allow empty input lines into history when they are being appended to a previous (partial) command (but not when they would just make an empty entry) . For all the gory details, see the PR. Note nothing here actually makes prompts containing \n work correctly when editing is enabled, that's a libedit issue, which will be addressed some other time. To generate a diff of this commit: cvs rdiff -u -r1.56.2.1 -r1.56.2.2 src/bin/sh/input.c cvs rdiff -u -r1.132.2.1 -r1.132.2.2 src/bin/sh/parser.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/input.c diff -u src/bin/sh/input.c:1.56.2.1 src/bin/sh/input.c:1.56.2.2 --- src/bin/sh/input.c:1.56.2.1 Sun Jul 23 14:58:14 2017 +++ src/bin/sh/input.c Wed Aug 9 05:35:18 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: input.c,v 1.56.2.1 2017/07/23 14:58:14 snj Exp $ */ +/* $NetBSD: input.c,v 1.56.2.2 2017/08/09 05:35:18 snj Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)input.c 8.3 (Berkeley) 6/9/95"; #else -__RCSID("$NetBSD: input.c,v 1.56.2.1 2017/07/23 14:58:14 snj Exp $"); +__RCSID("$NetBSD: input.c,v 1.56.2.2 2017/08/09 05:35:18 snj Exp $"); #endif #endif /* not lint */ @@ -310,10 +310,11 @@ preadbuffer(void) *q = '\0'; #ifndef SMALL - if (parsefile->fd == 0 && hist && something) { + if (parsefile->fd == 0 && hist && (something || whichprompt == 2)) { HistEvent he; + INTOFF; - history(hist, , whichprompt == 1? H_ENTER : H_APPEND, + history(hist, , whichprompt != 2 ? H_ENTER : H_APPEND, parsenextc); INTON; } Index: src/bin/sh/parser.c diff -u src/bin/sh/parser.c:1.132.2.1 src/bin/sh/parser.c:1.132.2.2 --- src/bin/sh/parser.c:1.132.2.1 Sun Jul 23 14:58:14 2017 +++ src/bin/sh/parser.c Wed Aug 9 05:35:18 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: parser.c,v 1.132.2.1 2017/07/23 14:58:14 snj Exp $ */ +/* $NetBSD: parser.c,v 1.132.2.2 2017/08/09 05:35:18 snj Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95"; #else -__RCSID("$NetBSD: parser.c,v 1.132.2.1 2017/07/23 14:58:14 snj Exp $"); +__RCSID("$NetBSD: parser.c,v 1.132.2.2 2017/08/09 05:35:18 snj Exp $"); #endif #endif /* not lint */ @@ -2191,13 +2191,14 @@ getprompt(void *unused) { char *p; const char *cp; + int wp; if (!doprompt) return ""; VTRACE(DBG_PARSE|DBG_EXPAND, ("getprompt %d\n", whichprompt)); - switch (whichprompt) { + switch (wp = whichprompt) { case 0: return ""; case 1: @@ -2215,6 +2216,7 @@ getprompt(void *unused) VTRACE(DBG_PARSE|DBG_EXPAND, ("prompt <<%s>>\n", p)); cp = expandstr(p, plinno); + whichprompt = wp; /* history depends on it not changing */ VTRACE(DBG_PARSE|DBG_EXPAND, ("prompt -> <<%s>>\n", cp));
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: snj Date: Fri Jun 9 16:53:39 UTC 2017 Modified Files: src/bin/sh [netbsd-8]: sh.1 Log Message: Pull up following revision(s) (requested by kre in ticket #15): bin/sh/sh.1: revision 1.148 Fix a typo (or rather a remnant of an earlier intent). To generate a diff of this commit: cvs rdiff -u -r1.146.2.1 -r1.146.2.2 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/sh.1 diff -u src/bin/sh/sh.1:1.146.2.1 src/bin/sh/sh.1:1.146.2.2 --- src/bin/sh/sh.1:1.146.2.1 Mon Jun 5 08:10:24 2017 +++ src/bin/sh/sh.1 Fri Jun 9 16:53:39 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.146.2.1 2017/06/05 08:10:24 snj Exp $ +.\" $NetBSD: sh.1,v 1.146.2.2 2017/06/09 16:53:39 snj Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -2219,7 +2219,7 @@ assign a value to a read-only variable. Note that either .Fl I or -.Fl U +.Fl N should always be used, or variables made local should always be given a value, or explicitly unset, as the default behavior (inheriting the earlier value, or starting unset after
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: snj Date: Mon Jun 5 08:15:16 UTC 2017 Modified Files: src/bin/sh [netbsd-8]: expand.c Log Message: Pull up following revision(s) (requested by kre in ticket #7): bin/sh/expand.c: revisions 1.111, 1.112 PR bin/52272 - fix an off-by one that broke ~ expansions. -- Another arithmetic expansion recordregion() fix, this time calculate the lenght (used to calculate the end) based upon the correct starting point. Thanks to John Klos for finding and reporting this one. To generate a diff of this commit: cvs rdiff -u -r1.110 -r1.110.2.1 src/bin/sh/expand.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/expand.c diff -u src/bin/sh/expand.c:1.110 src/bin/sh/expand.c:1.110.2.1 --- src/bin/sh/expand.c:1.110 Sat Jun 3 21:52:05 2017 +++ src/bin/sh/expand.c Mon Jun 5 08:15:16 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: expand.c,v 1.110 2017/06/03 21:52:05 kre Exp $ */ +/* $NetBSD: expand.c,v 1.110.2.1 2017/06/05 08:15:16 snj Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95"; #else -__RCSID("$NetBSD: expand.c,v 1.110 2017/06/03 21:52:05 kre Exp $"); +__RCSID("$NetBSD: expand.c,v 1.110.2.1 2017/06/05 08:15:16 snj Exp $"); #endif #endif /* not lint */ @@ -159,6 +159,7 @@ expandarg(union node *arg, struct arglis struct strlist *sp; char *p; + CTRACE(DBG_EXPAND, ("expandarg(fl=%#x)\n", flag)); if (fflag) /* no filename expandsion */ flag &= ~EXP_GLOB; @@ -169,9 +170,13 @@ expandarg(union node *arg, struct arglis argstr(arg->narg.text, flag); if (arglist == NULL) { STACKSTRNUL(expdest); + CTRACE(DBG_EXPAND, ("expandarg: no arglist, done (%d) \"%s\"\n", + expdest - stackblock(), stackblock())); return; /* here document expanded */ } STPUTC('\0', expdest); + CTRACE(DBG_EXPAND, ("expandarg: arglist got (%d) \"%s\"\n", + expdest - stackblock() - 1, stackblock())); p = grabstackstr(expdest); exparg.lastp = /* @@ -321,7 +326,7 @@ exptilde(const char *p, int flag) char *user; user = expdest; /* we will just borrow top of stack */ - while ((c = *p) != '\0') { + while ((c = *++p) != '\0') { switch(c) { case CTLESC: case CTLVAR: @@ -339,12 +344,11 @@ exptilde(const char *p, int flag) goto done; } STPUTC(c, user); - p++; } done: STACKSTRNUL(user); - CTRACE(DBG_EXPAND, ("exptilde, found \"~%s\" :", expdest)); + CTRACE(DBG_EXPAND, ("exptilde, found \"%s\" :", expdest)); if (*expdest == '\0') home = lookupvar("HOME"); else if ((pw = getpwnam(expdest)) == NULL) @@ -369,10 +373,15 @@ exptilde(const char *p, int flag) STATIC void removerecordregions(int endoff) { - if (ifslastp == NULL) + + VTRACE(DBG_EXPAND, ("removerecordregions(%d):", endoff)); + if (ifslastp == NULL) { + VTRACE(DBG_EXPAND, (" none\n", endoff)); return; + } if (ifsfirst.endoff > endoff) { + VTRACE(DBG_EXPAND, (" first(%d)", ifsfirst.endoff)); while (ifsfirst.next != NULL) { struct ifsregion *ifsp; INTOFF; @@ -384,15 +393,18 @@ removerecordregions(int endoff) if (ifsfirst.begoff > endoff) ifslastp = NULL; else { + VTRACE(DBG_EXPAND,("->(%d,%d)",ifsfirst.begoff,endoff)); ifslastp = ifsfirst.endoff = endoff; } + VTRACE(DBG_EXPAND, ("\n")); return; } ifslastp = while (ifslastp->next && ifslastp->next->begoff < endoff) ifslastp=ifslastp->next; + VTRACE(DBG_EXPAND, (" found(%d,%d)", ifslastp->begoff,ifslastp->endoff)); while (ifslastp->next != NULL) { struct ifsregion *ifsp; INTOFF; @@ -403,6 +415,7 @@ removerecordregions(int endoff) } if (ifslastp->endoff > endoff) ifslastp->endoff = endoff; + VTRACE(DBG_EXPAND, ("->(%d,%d)", ifslastp->begoff,ifslastp->endoff)); } @@ -485,7 +498,7 @@ expari(const char *p, int flag) ; if (quoted == 0) /* allow weird splitting */ - recordregion(begoff, begoff + q - 1 - start, 0); + recordregion(begoff, begoff + q - 1 - expdest, 0); adjustment = q - expdest - 1; STADJUST(adjustment, expdest); VTRACE(DBG_EXPAND, ("expari: adding %d ed \"%.*s\", " @@ -1107,6 +1120,7 @@ recordregion(int start, int end, int inq { struct ifsregion *ifsp; + VTRACE(DBG_EXPAND, ("recordregion(%d,%d,%d)\n", start, end, inquotes)); if (ifslastp == NULL) { ifsp = } else {
CVS commit: [netbsd-8] src/bin/sh
Module Name:src Committed By: snj Date: Mon Jun 5 08:10:24 UTC 2017 Modified Files: src/bin/sh [netbsd-8]: cd.c eval.c exec.c exec.h mail.c sh.1 Log Message: Pull up following revision(s) (requested by kre in ticket #5): bin/sh/cd.c: revision 1.48 bin/sh/eval.c: revision 1.141 bin/sh/exec.c: revision 1.48 bin/sh/exec.h: revision 1.25 bin/sh/mail.c: revisions 1.17, 1.18 bin/sh/sh.1: revision 1.147 Make cd (really) do cd -P, and not just claim that is what it is doing while doing a half-hearted, broken, partial, version of cd -L instead. The latter (as the manual says) is not supported, what's more, it is an abomination, and should never be supported (anywhere.) Fix the doc so that the pretense that we notice when a path given crosses a symlink (and turns on printing of the destination directory) is claimed no more (that used to be true until late Dec 2016, but was changed). Now the print happens if -o cdprint is set, or if an entry from CDPATH that is not "" or "." is used (or if the "cd dest repl" cd cmd variant is used.) Fix CDPATH processing: avoid the magic '%' processing that is used for PATH and MAILPATH from corrupting CDPATH. The % magic (both variants) remains undocumented. Also, don't double the '/' if an entry in PATH or CDPATH ends in '/' (as in CDPATH=":/usr/src/"). A "cd usr.bin" used to do chdir("/usr/src//usr.bin"). No more. This is almost invisible, and relatively harmless, either way Also fix a bug where if a plausible destination directory in CDPATH was located, but the chdir() failed (eg: permission denied) and then a later "." or "" CDPATH entry succeeded, "print" mode was turned on. That is: cd /tmp; mkdir bin mkdir -p P/bin; chmod 0 P/bin CDPATH=/tmp/P: cd bin would cd to /tmp/bin (correctly) but print it (incorrectly). Also when in "cd dest replace" mode, if the result of the replacement generates '-' as the path named, as in: cd $PWD - then simply change to '-' (or attempt to, with CDPATH search), rather than having this being equivalent to "cd -") Because of these changes, the pwd command (and $PWD) essentially always acts as pwd -P, even when called as pwd -L (which is still the default.) That is, even more than it did before. Also fixed a (kind of minor) mem management error (CDPATH related) "whosoever shall padvance must stunalloc before repeating" (and the same for MAILPATH). -- If we are going to keep the MAILPATH % hack, then at least do something rational. Since it isn't documented, what "rational" is is up for discussion, but what it did before was not it (it was nonsense...). To generate a diff of this commit: cvs rdiff -u -r1.47 -r1.47.6.1 src/bin/sh/cd.c cvs rdiff -u -r1.140 -r1.140.2.1 src/bin/sh/eval.c cvs rdiff -u -r1.47 -r1.47.2.1 src/bin/sh/exec.c cvs rdiff -u -r1.24 -r1.24.8.1 src/bin/sh/exec.h cvs rdiff -u -r1.16 -r1.16.90.1 src/bin/sh/mail.c cvs rdiff -u -r1.146 -r1.146.2.1 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/sh/cd.c diff -u src/bin/sh/cd.c:1.47 src/bin/sh/cd.c:1.47.6.1 --- src/bin/sh/cd.c:1.47 Mon Dec 26 02:27:57 2016 +++ src/bin/sh/cd.c Mon Jun 5 08:10:24 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: cd.c,v 1.47 2016/12/26 02:27:57 christos Exp $ */ +/* $NetBSD: cd.c,v 1.47.6.1 2017/06/05 08:10:24 snj Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)cd.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: cd.c,v 1.47 2016/12/26 02:27:57 christos Exp $"); +__RCSID("$NetBSD: cd.c,v 1.47.6.1 2017/06/05 08:10:24 snj Exp $"); #endif #endif /* not lint */ @@ -80,10 +80,11 @@ int cdcmd(int argc, char **argv) { const char *dest; - const char *path, *p; + const char *path, *cp; + char *p; char *d; struct stat statb; - int print = cdprint; /* set -cdprint to enable */ + int print = cdprint; /* set -o cdprint to enable */ while (nextopt("P") != '\0') ; @@ -98,46 +99,46 @@ cdcmd(int argc, char **argv) dest = bltinlookup("HOME", 1); if (dest == NULL) error("HOME not set"); - } else { - if (argptr[1]) { - /* Do 'ksh' style substitution */ - if (!curdir) -error("PWD not set"); - p = strstr(curdir, dest); - if (!p) -error("bad substitution"); - d = stalloc(strlen(curdir) + strlen(argptr[1]) + 1); - memcpy(d, curdir, p - curdir); - strcpy(d + (p - curdir), argptr[1]); - strcat(d, p + strlen(dest)); - dest = d; - print = 1; - } - } - - if (dest[0] == '-' && dest[1] == '\0') { + } else if (argptr[1]) { + /* Do 'ksh' style substitution */ + if (!curdir) + error("PWD not set"); + p = strstr(curdir, dest); + if (!p) + error("bad substitution"); + d = stalloc(strlen(curdir) + strlen(argptr[1]) + 1); + memcpy(d, curdir, p - curdir); + strcpy(d + (p - curdir), argptr[1]); + strcat(d, p + strlen(dest)); + dest = d; + print = 1;