CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Tue Jan 30 19:05:07 UTC 2024 Modified Files: src/bin/sh: jobs.c Log Message: PR bin/57894 For jobs -p for a non-job-control job, avoid just printing 0 (as there is no process group pid) and instead output what we used to, the pid of one of the processes in the job (usually the right one!) XXX pullup -10 (9 and earlier not affected). To generate a diff of this commit: cvs rdiff -u -r1.118 -r1.119 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.118 src/bin/sh/jobs.c:1.119 --- src/bin/sh/jobs.c:1.118 Fri Apr 7 10:34:13 2023 +++ src/bin/sh/jobs.c Tue Jan 30 19:05:07 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: jobs.c,v 1.118 2023/04/07 10:34:13 kre Exp $ */ +/* $NetBSD: jobs.c,v 1.119 2024/01/30 19:05:07 kre 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.118 2023/04/07 10:34:13 kre Exp $"); +__RCSID("$NetBSD: jobs.c,v 1.119 2024/01/30 19:05:07 kre Exp $"); #endif #endif /* not lint */ @@ -439,7 +439,8 @@ showjob(struct output *out, struct job * #if JOBS if (mode & SHOW_PGID) { /* output only the process group ID (lead process ID) */ - outfmt(out, "%ld\n", (long)jp->pgrp); + outfmt(out, "%ld\n", + jp->pgrp != 0 ? (long)jp->pgrp : (long)jp->ps->pid); return; } #endif
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Tue Jan 30 19:05:07 UTC 2024 Modified Files: src/bin/sh: jobs.c Log Message: PR bin/57894 For jobs -p for a non-job-control job, avoid just printing 0 (as there is no process group pid) and instead output what we used to, the pid of one of the processes in the job (usually the right one!) XXX pullup -10 (9 and earlier not affected). To generate a diff of this commit: cvs rdiff -u -r1.118 -r1.119 src/bin/sh/jobs.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Tue Jan 16 14:30:22 UTC 2024 Modified Files: src/bin/sh: sh.1 Log Message: Remove an ancient incorrect notion which somehow survived intact for ages. "$@" is (as it is in double quotes) not subject to field splitting. "$@" generates (potentially) multiple words, but field splitting has nothing to do with it. While here, rename the section from "White Space Splitting (Field Splitting)" to simply be "Field Splitting" as white space is only relevant if it happens to occur in IFS (which is the default case, but IFS can be anything, and isn't required to contain any white space at all). To generate a diff of this commit: cvs rdiff -u -r1.258 -r1.259 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.258 src/bin/sh/sh.1:1.259 --- src/bin/sh/sh.1:1.258 Thu Oct 12 01:45:07 2023 +++ src/bin/sh/sh.1 Tue Jan 16 14:30:22 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.258 2023/10/12 01:45:07 uwe Exp $ +.\" $NetBSD: sh.1,v 1.259 2024/01/16 14:30:22 kre Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -2299,14 +2299,11 @@ and .Dq \&[ . .\" .\" -.Ss White Space Splitting (Field Splitting) +.Ss Field Splitting .\" After parameter expansion, command substitution, and arithmetic expansion the shell scans the results of expansions and substitutions that did not occur in double quotes, -and -.Dq Li $@ -even if it did, for field splitting and multiple fields can result. .Pp The shell treats each character of the
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Tue Jan 16 14:30:22 UTC 2024 Modified Files: src/bin/sh: sh.1 Log Message: Remove an ancient incorrect notion which somehow survived intact for ages. "$@" is (as it is in double quotes) not subject to field splitting. "$@" generates (potentially) multiple words, but field splitting has nothing to do with it. While here, rename the section from "White Space Splitting (Field Splitting)" to simply be "Field Splitting" as white space is only relevant if it happens to occur in IFS (which is the default case, but IFS can be anything, and isn't required to contain any white space at all). To generate a diff of this commit: cvs rdiff -u -r1.258 -r1.259 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Dec 29 15:49:24 UTC 2023 Modified Files: src/bin/sh: expand.c Log Message: PR bin/57773 Fix another bug reported by Jarle Fredrik Greipsland and added to PR bin/57773, which relates to calculating the length of a positional parameter which contains CTL chars -- yes, this one really is that specific, though it would also affect the special param $0 if it were to contain CTL chars, and its length was requested - that is fixed with the same change. And note: $0 is not affected because it looks like a positional param (it isn't, ${00} would be, but is always unset, ${0} isn't) all special parame would be affected the same way, but the only one that can ever contain a CTL char is $0 I believe. ($@ and $* were affected, but just because they're expanding the positional params ... ${#@} and ${#*} are both technically unspecified expansions - and different shells produce different results. See the PR for the details of this one (and the previous). Thanks for the PR. XXX pullup to everything. To generate a diff of this commit: cvs rdiff -u -r1.143 -r1.144 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.143 src/bin/sh/expand.c:1.144 --- src/bin/sh/expand.c:1.143 Mon Dec 25 02:28:47 2023 +++ src/bin/sh/expand.c Fri Dec 29 15:49:23 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: expand.c,v 1.143 2023/12/25 02:28:47 kre Exp $ */ +/* $NetBSD: expand.c,v 1.144 2023/12/29 15:49:23 kre 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.143 2023/12/25 02:28:47 kre Exp $"); +__RCSID("$NetBSD: expand.c,v 1.144 2023/12/29 15:49:23 kre Exp $"); #endif #endif /* not lint */ @@ -1206,7 +1206,7 @@ varvalue(const char *name, int quoted, i quoted ? ", quoted" : "", subtype, flag)); if (subtype == VSLENGTH) /* no magic required ... */ - flag &= ~EXP_FULL; + flag &= ~(EXP_FULL | EXP_QNEEDED); #define STRTODEST(p) \ do {\ @@ -1218,7 +1218,7 @@ varvalue(const char *name, int quoted, i } \ } else \ while (*p) { \ -if (ISCTL(*p)) \ +if ((flag & EXP_QNEEDED) && ISCTL(*p)) \ STPUTC(CTLESC, expdest); \ STPUTC(*p++, expdest); \ } \
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Dec 29 15:49:24 UTC 2023 Modified Files: src/bin/sh: expand.c Log Message: PR bin/57773 Fix another bug reported by Jarle Fredrik Greipsland and added to PR bin/57773, which relates to calculating the length of a positional parameter which contains CTL chars -- yes, this one really is that specific, though it would also affect the special param $0 if it were to contain CTL chars, and its length was requested - that is fixed with the same change. And note: $0 is not affected because it looks like a positional param (it isn't, ${00} would be, but is always unset, ${0} isn't) all special parame would be affected the same way, but the only one that can ever contain a CTL char is $0 I believe. ($@ and $* were affected, but just because they're expanding the positional params ... ${#@} and ${#*} are both technically unspecified expansions - and different shells produce different results. See the PR for the details of this one (and the previous). Thanks for the PR. XXX pullup to everything. To generate a diff of this commit: cvs rdiff -u -r1.143 -r1.144 src/bin/sh/expand.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Mon Dec 25 04:52:38 UTC 2023 Modified Files: src/bin/sh: eval.c Log Message: PR bin/57773 Fix a bug reported by Jarle Fredrik Greipsland in PR bin/57773, where a substring expansion where the substring to be removed from a variable expansion is itself a var expansion where the value contains one (or more) of sh's CTLxxx chars - the pattern had CTLESC inserted, the string to be matched against did not. Fail. We fix that by always inserting CTLESC in var assign expansions. See the PR for all the gory details. Thanks for the PR. XXX pullup to everything. To generate a diff of this commit: cvs rdiff -u -r1.190 -r1.191 src/bin/sh/eval.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Mon Dec 25 04:52:38 UTC 2023 Modified Files: src/bin/sh: eval.c Log Message: PR bin/57773 Fix a bug reported by Jarle Fredrik Greipsland in PR bin/57773, where a substring expansion where the substring to be removed from a variable expansion is itself a var expansion where the value contains one (or more) of sh's CTLxxx chars - the pattern had CTLESC inserted, the string to be matched against did not. Fail. We fix that by always inserting CTLESC in var assign expansions. See the PR for all the gory details. Thanks for the PR. XXX pullup to everything. To generate a diff of this commit: cvs rdiff -u -r1.190 -r1.191 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.190 src/bin/sh/eval.c:1.191 --- src/bin/sh/eval.c:1.190 Sat Jun 24 05:17:02 2023 +++ src/bin/sh/eval.c Mon Dec 25 04:52:38 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: eval.c,v 1.190 2023/06/24 05:17:02 msaitoh Exp $ */ +/* $NetBSD: eval.c,v 1.191 2023/12/25 04:52:38 kre 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.190 2023/06/24 05:17:02 msaitoh Exp $"); +__RCSID("$NetBSD: eval.c,v 1.191 2023/12/25 04:52:38 kre Exp $"); #endif #endif /* not lint */ @@ -932,7 +932,8 @@ evalcommand(union node *cmd, int flgs, s line_number = argp->narg.lineno; if (!isassignment(argp->narg.text)) break; - expandarg(argp, , EXP_VARTILDE); + /* EXP_CASE handles CTL* chars in expansions properly */ + expandarg(argp, , EXP_VARTILDE | EXP_CASE); } *varlist.lastp = NULL;
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Mon Dec 25 02:28:47 UTC 2023 Modified Files: src/bin/sh: expand.c Log Message: Correct a bizarre piece of source formatting that crept in by accident several years ago (change a space into newline tab). NFC To generate a diff of this commit: cvs rdiff -u -r1.142 -r1.143 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.142 src/bin/sh/expand.c:1.143 --- src/bin/sh/expand.c:1.142 Mon Mar 6 05:54:34 2023 +++ src/bin/sh/expand.c Mon Dec 25 02:28:47 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: expand.c,v 1.142 2023/03/06 05:54:34 kre Exp $ */ +/* $NetBSD: expand.c,v 1.143 2023/12/25 02:28:47 kre 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.142 2023/03/06 05:54:34 kre Exp $"); +__RCSID("$NetBSD: expand.c,v 1.143 2023/12/25 02:28:47 kre Exp $"); #endif #endif /* not lint */ @@ -465,7 +465,8 @@ exptilde(const char *p, int flag) if (home == NULL) { CTRACE(DBG_EXPAND, (": returning unused \"%s\"\n", startp)); return startp; - } while ((c = *home++) != '\0') { + } + while ((c = *home++) != '\0') { if ((quotes && NEEDESC(c)) || ISCTL(c)) STPUTC(CTLESC, expdest); STPUTC(c, expdest);
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Mon Dec 25 02:28:47 UTC 2023 Modified Files: src/bin/sh: expand.c Log Message: Correct a bizarre piece of source formatting that crept in by accident several years ago (change a space into newline tab). NFC To generate a diff of this commit: cvs rdiff -u -r1.142 -r1.143 src/bin/sh/expand.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Oct 20 22:08:52 UTC 2023 Modified Files: src/bin/sh: parser.c Log Message: Work around a probably gcc12 bug in detecting "potentially clobbered" variables after longjmp() for some architectures (sh3 at least). This should allow the workaround to disable those warnings for this file to be removed. In the affected function the extra var & assignment added should simply be deleted by any good optimiser, but if not, it doesn't matter, as performance of this function (expandonstack()) is almost irrelevant. To generate a diff of this commit: cvs rdiff -u -r1.180 -r1.181 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.180 src/bin/sh/parser.c:1.181 --- src/bin/sh/parser.c:1.180 Fri Apr 7 10:34:13 2023 +++ src/bin/sh/parser.c Fri Oct 20 22:08:52 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: parser.c,v 1.180 2023/04/07 10:34:13 kre Exp $ */ +/* $NetBSD: parser.c,v 1.181 2023/10/20 22:08:52 kre 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.180 2023/04/07 10:34:13 kre Exp $"); +__RCSID("$NetBSD: parser.c,v 1.181 2023/10/20 22:08:52 kre Exp $"); #endif #endif /* not lint */ @@ -2689,6 +2689,7 @@ expandonstack(char *ps, int cmdsub, int struct jmploc jmploc; struct jmploc *const savehandler = handler; struct parsefile *const savetopfile = getcurrentfile(); + char * const save_ps = ps; const int save_x = xflag; const int save_e_s = errors_suppressed; struct parse_state new_state = init_parse_state; @@ -2740,7 +2741,7 @@ expandonstack(char *ps, int cmdsub, int errors_suppressed = save_e_s; if (result == NULL) - result = ps; + result = save_ps; return result; }
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Oct 20 22:08:52 UTC 2023 Modified Files: src/bin/sh: parser.c Log Message: Work around a probably gcc12 bug in detecting "potentially clobbered" variables after longjmp() for some architectures (sh3 at least). This should allow the workaround to disable those warnings for this file to be removed. In the affected function the extra var & assignment added should simply be deleted by any good optimiser, but if not, it doesn't matter, as performance of this function (expandonstack()) is almost irrelevant. To generate a diff of this commit: cvs rdiff -u -r1.180 -r1.181 src/bin/sh/parser.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: mrg Date: Thu Oct 19 04:27:24 UTC 2023 Modified Files: src/bin/sh: Makefile Log Message: convert gcc12 -O1 into -Wno-error=clobbered. parser.c wants all the optimisation, and this is very likely a false positive. To generate a diff of this commit: cvs rdiff -u -r1.122 -r1.123 src/bin/sh/Makefile 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/Makefile diff -u src/bin/sh/Makefile:1.122 src/bin/sh/Makefile:1.123 --- src/bin/sh/Makefile:1.122 Sat Oct 14 06:53:56 2023 +++ src/bin/sh/Makefile Thu Oct 19 04:27:24 2023 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.122 2023/10/14 06:53:56 mrg Exp $ +# $NetBSD: Makefile,v 1.123 2023/10/19 04:27:24 mrg Exp $ # @(#)Makefile 8.4 (Berkeley) 5/5/95 .include @@ -94,7 +94,7 @@ COPTS.jobs.c = -Wno-format-nonliteral COPTS.var.c = -Wno-format-nonliteral # XXXGCC12 - only on some targets -COPTS.parser.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 12:? -O1 :} +COPTS.parser.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 12:? -Wno-error=clobbered :} .include .include
CVS commit: src/bin/sh
Module Name:src Committed By: mrg Date: Thu Oct 19 04:27:24 UTC 2023 Modified Files: src/bin/sh: Makefile Log Message: convert gcc12 -O1 into -Wno-error=clobbered. parser.c wants all the optimisation, and this is very likely a false positive. To generate a diff of this commit: cvs rdiff -u -r1.122 -r1.123 src/bin/sh/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: mrg Date: Sat Oct 14 06:53:56 UTC 2023 Modified Files: src/bin/sh: Makefile Log Message: the parser.c longjmp vs gcc12 issue affects a few ports, make the workaround global. To generate a diff of this commit: cvs rdiff -u -r1.121 -r1.122 src/bin/sh/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: mrg Date: Sat Oct 14 06:53:56 UTC 2023 Modified Files: src/bin/sh: Makefile Log Message: the parser.c longjmp vs gcc12 issue affects a few ports, make the workaround global. To generate a diff of this commit: cvs rdiff -u -r1.121 -r1.122 src/bin/sh/Makefile 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/Makefile diff -u src/bin/sh/Makefile:1.121 src/bin/sh/Makefile:1.122 --- src/bin/sh/Makefile:1.121 Mon Aug 14 03:18:14 2023 +++ src/bin/sh/Makefile Sat Oct 14 06:53:56 2023 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.121 2023/08/14 03:18:14 mrg Exp $ +# $NetBSD: Makefile,v 1.122 2023/10/14 06:53:56 mrg Exp $ # @(#)Makefile 8.4 (Berkeley) 5/5/95 .include @@ -94,9 +94,7 @@ COPTS.jobs.c = -Wno-format-nonliteral COPTS.var.c = -Wno-format-nonliteral # XXXGCC12 - only on some targets -.if ${MACHINE_CPU} == "sh3" COPTS.parser.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 12:? -O1 :} -.endif .include .include
CVS commit: src/bin/sh
Module Name:src Committed By: uwe Date: Thu Oct 12 01:45:07 UTC 2023 Modified Files: src/bin/sh: sh.1 Log Message: sh(1): touch up markup for the ENV example Don't use Dq in a literal display, ascii quotes are \*q While here mark up as literal a few things around this example. To generate a diff of this commit: cvs rdiff -u -r1.257 -r1.258 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.257 src/bin/sh/sh.1:1.258 --- src/bin/sh/sh.1:1.257 Fri Sep 1 01:57:54 2023 +++ src/bin/sh/sh.1 Thu Oct 12 01:45:07 2023 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.257 2023/09/01 01:57:54 kre Exp $ +.\" $NetBSD: sh.1,v 1.258 2023/10/12 01:45:07 uwe Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -136,14 +136,14 @@ automatically by the system when the user first logs in. A login shell first reads commands (as if by using the -.Dq \&. +.Ql \&. command) from the files .Pa /etc/profile and .Pa .profile in the user's home directory -.Pq \&$HOME , +.Pq Li \&$HOME , if they exist. If the environment variable .Ev ENV @@ -164,7 +164,7 @@ Note that no error messages result from expansions, to verify that .Ev ENV is correct, as desired, use: -.Dl eval printf '%s\e\en' Dq \&${ENV} +.Dl eval printf '%s\e\en' \*q${ENV}\*q Otherwise if .Ev ENV appears to contain a command substitution, @@ -188,7 +188,7 @@ of your home directory .Dl ENV=$HOME/.shinit; export ENV .Pp substituting for -.Dq .shinit +.Pa .shinit any filename you wish. Since the .Ev ENV
CVS commit: src/bin/sh
Module Name:src Committed By: uwe Date: Thu Oct 12 01:45:07 UTC 2023 Modified Files: src/bin/sh: sh.1 Log Message: sh(1): touch up markup for the ENV example Don't use Dq in a literal display, ascii quotes are \*q While here mark up as literal a few things around this example. To generate a diff of this commit: cvs rdiff -u -r1.257 -r1.258 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Thu Oct 5 20:33:31 UTC 2023 Modified Files: src/bin/sh: miscbltin.c Log Message: If the read builtin is told to read into IFS, we must avoid doing that until all current uses of IFS are complete (as we have IFS's value cached in ifs - if IFS alters, ifs might point anywhere). Handle this by deferring assignments to IFS until everything is done. This makes us appear to comply with the (currently) proposed requirement for read by POSIX that field splitting complete before vars are assigned. (Other shells, like dash, ksh93, yash, bosh behave like this) That might end up being unspecified though, as other shells (bosh, mksh) assign each field to its var as it is delimited (though bosh appears to have bugs). If we wanted to go that route, the issue here could have been handled by re-doing the init of ifs after every setvar() that is performed here (except the last, after which it is no longer needed). XXX pullup -10 To generate a diff of this commit: cvs rdiff -u -r1.53 -r1.54 src/bin/sh/miscbltin.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Thu Oct 5 20:33:31 UTC 2023 Modified Files: src/bin/sh: miscbltin.c Log Message: If the read builtin is told to read into IFS, we must avoid doing that until all current uses of IFS are complete (as we have IFS's value cached in ifs - if IFS alters, ifs might point anywhere). Handle this by deferring assignments to IFS until everything is done. This makes us appear to comply with the (currently) proposed requirement for read by POSIX that field splitting complete before vars are assigned. (Other shells, like dash, ksh93, yash, bosh behave like this) That might end up being unspecified though, as other shells (bosh, mksh) assign each field to its var as it is delimited (though bosh appears to have bugs). If we wanted to go that route, the issue here could have been handled by re-doing the init of ifs after every setvar() that is performed here (except the last, after which it is no longer needed). XXX pullup -10 To generate a diff of this commit: cvs rdiff -u -r1.53 -r1.54 src/bin/sh/miscbltin.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/miscbltin.c diff -u src/bin/sh/miscbltin.c:1.53 src/bin/sh/miscbltin.c:1.54 --- src/bin/sh/miscbltin.c:1.53 Sun Dec 11 08:23:10 2022 +++ src/bin/sh/miscbltin.c Thu Oct 5 20:33:31 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: miscbltin.c,v 1.53 2022/12/11 08:23:10 kre Exp $ */ +/* $NetBSD: miscbltin.c,v 1.54 2023/10/05 20:33:31 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)miscbltin.c 8.4 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: miscbltin.c,v 1.53 2022/12/11 08:23:10 kre Exp $"); +__RCSID("$NetBSD: miscbltin.c,v 1.54 2023/10/05 20:33:31 kre Exp $"); #endif #endif /* not lint */ @@ -102,6 +102,8 @@ readcmd(int argc, char **argv) int is_ifs; int saveall = 0; ptrdiff_t wordlen = 0; + char *newifs = NULL; + struct stackmark mk; end = '\n';/* record delimiter */ rflag = 0; @@ -132,6 +134,7 @@ readcmd(int argc, char **argv) if ((ifs = bltinlookup("IFS", 1)) == NULL) ifs = " \t\n"; + setstackmark(); status = 0; startword = 2; STARTSTACKSTR(p); @@ -198,8 +201,22 @@ readcmd(int argc, char **argv) continue; } - STACKSTRNUL(p); - setvar(*ap, stackblock(), 0); + if (equal(*ap, "IFS")) { + /* + * we must not alter the value of IFS, as our + * local "ifs" var is (perhaps) pointing at it, + * at best we would be using data after free() + * the next time we reference ifs - but that mem + * may have been reused for something different. + * + * note that this might occur several times + */ + STPUTC('\0', p); + newifs = grabstackstr(p); + } else { + STACKSTRNUL(p); + setvar(*ap, stackblock(), 0); + } ap++; STARTSTACKSTR(p); wordlen = 0; @@ -217,11 +234,25 @@ readcmd(int argc, char **argv) /* Don't remove non-whitespace unless it was naked */ break; } + + /* + * If IFS was one of the variables named, we can finally set it now + * (no further references to ifs will be made) + */ + if (newifs != NULL) + setvar("IFS", newifs, 0); + + /* + * Now we can assign to the final variable (which might + * also be IFS, hence the ordering here) + */ setvar(*ap, stackblock(), 0); /* Set any remaining args to "" */ while (*++ap != NULL) setvar(*ap, nullstr, 0); + + popstackmark(); return status; }
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Sep 1 01:57:54 UTC 2023 Modified Files: src/bin/sh: sh.1 Log Message: At the request of bad@ enhance the synopsis of the set built-in command to include explicit mention of the -o opt and +o opt forms. Fix the synopsis to have the 4 forms that the description of the utility discusses, rather than expecting users to understand that the 3rd and 4th forms of the command were combined into the 3rd synopsis format. After doing that, the options in the 3rd format no longer need to be optional, so now all 4 formats are distinct (previously, the third, omitting everything that was optional, and the first, could not be distinguished). While here, some wording and formatting "improvements" as well (nothing too serious). To generate a diff of this commit: cvs rdiff -u -r1.256 -r1.257 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.256 src/bin/sh/sh.1:1.257 --- src/bin/sh/sh.1:1.256 Fri Aug 4 15:31:40 2023 +++ src/bin/sh/sh.1 Fri Sep 1 01:57:54 2023 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.256 2023/08/04 15:31:40 jschauma Exp $ +.\" $NetBSD: sh.1,v 1.257 2023/09/01 01:57:54 kre Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -3725,9 +3725,10 @@ command instead, if you want to return f your shell. .\" .Pp -.It set -.It set { Fl o | Cm +o } -.It Ic set Oo { Fl options | Cm +options } ... Oc Oo Cm \-\|\- Oc Oo Ar arg ... Oc +.It Ic set +.It Ic set No { Fl o | Cm +o No } +.It Ic set No { Fl options | Cm +options | Fl o Ar opt | Cm +o Ar opt } ... Oo Cm \-\|\- Oc Oo Ar arg ... Oc +.It Ic set \-\|\- Oo Ar arg ... Oc .Pp The .Ic set @@ -3751,8 +3752,10 @@ In the form, the shell outputs a string that can later be used as a command to reset all options to their current values. .Pp -If options are given, it sets the specified option -flags, or clears them as described in the +If options are given, +.Nm +sets the specified option flags, +or clears them as described in the .Sx Argument List Processing section. Note that not all options available on the command @@ -3762,6 +3765,7 @@ built-in command. However, in addition to the options listed there, when the .Dq "option name" +.Pq Ar opt given to .Ic set Fl o is @@ -3786,20 +3790,41 @@ parameters with no possibility of changi .Dq \-\|\- as the first argument to .Ic set . -If no following arguments are present, the +If no following +.Ar arg Ns s +are present, the .Ic set command will clear all the positional parameters (equivalent to executing .Dq Li shift $# . ) -Otherwise the following arguments become +Otherwise the following +.Ar arg Ns s +become .Li \&$1 , .Li \&$2 , \&..., and .Li \&$# -is set to the number of arguments present. +is set to the number of +.Ar arg Ns s +present. The third and fourth forms may be combined, to set options, -and the argument list, in one operation. +and the positional parameters, in one operation. +Note that if it is possible that no +.Ar arg Ns uments +might be present, +or if the first +.Ar arg +might begin with a minus +.Pq Sq \&\- +then the +.Dq \-\|\- +is required to distinguish this case from the first +and third variants of this command, and an +.Ar arg +beginning with +.Sq \&\- +from being an attempt to set options. .\" .Pp .It Ic setvar Ar variable Ar value
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Sep 1 01:57:54 UTC 2023 Modified Files: src/bin/sh: sh.1 Log Message: At the request of bad@ enhance the synopsis of the set built-in command to include explicit mention of the -o opt and +o opt forms. Fix the synopsis to have the 4 forms that the description of the utility discusses, rather than expecting users to understand that the 3rd and 4th forms of the command were combined into the 3rd synopsis format. After doing that, the options in the 3rd format no longer need to be optional, so now all 4 formats are distinct (previously, the third, omitting everything that was optional, and the first, could not be distinguished). While here, some wording and formatting "improvements" as well (nothing too serious). To generate a diff of this commit: cvs rdiff -u -r1.256 -r1.257 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: mrg Date: Mon Aug 14 03:18:15 UTC 2023 Modified Files: src/bin/sh: Makefile Log Message: use -O1 on sh3, GCC 12 and parser.c. this triggers clobbered vs. longjmp/setjmp warnings with -Os that sh3 uses. To generate a diff of this commit: cvs rdiff -u -r1.120 -r1.121 src/bin/sh/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: mrg Date: Mon Aug 14 03:18:15 UTC 2023 Modified Files: src/bin/sh: Makefile Log Message: use -O1 on sh3, GCC 12 and parser.c. this triggers clobbered vs. longjmp/setjmp warnings with -Os that sh3 uses. To generate a diff of this commit: cvs rdiff -u -r1.120 -r1.121 src/bin/sh/Makefile 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/Makefile diff -u src/bin/sh/Makefile:1.120 src/bin/sh/Makefile:1.121 --- src/bin/sh/Makefile:1.120 Sun Oct 10 08:35:34 2021 +++ src/bin/sh/Makefile Mon Aug 14 03:18:14 2023 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.120 2021/10/10 08:35:34 rillig Exp $ +# $NetBSD: Makefile,v 1.121 2023/08/14 03:18:14 mrg Exp $ # @(#)Makefile 8.4 (Berkeley) 5/5/95 .include @@ -93,5 +93,10 @@ COPTS.printf.c = -Wno-format-nonliteral COPTS.jobs.c = -Wno-format-nonliteral COPTS.var.c = -Wno-format-nonliteral +# XXXGCC12 - only on some targets +.if ${MACHINE_CPU} == "sh3" +COPTS.parser.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 12:? -O1 :} +.endif + .include .include
CVS commit: src/bin/sh
Module Name:src Committed By: jschauma Date: Fri Aug 4 15:31:40 UTC 2023 Modified Files: src/bin/sh: sh.1 Log Message: tyops: * redicection -> redirection * escaoed -> escaped Noted by J. Lewis Muir on netbsd-docs@ To generate a diff of this commit: cvs rdiff -u -r1.255 -r1.256 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.255 src/bin/sh/sh.1:1.256 --- src/bin/sh/sh.1:1.255 Tue Dec 20 17:51:54 2022 +++ src/bin/sh/sh.1 Fri Aug 4 15:31:40 2023 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.255 2022/12/20 17:51:54 kre Exp $ +.\" $NetBSD: sh.1,v 1.256 2023/08/04 15:31:40 jschauma Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -1000,7 +1000,7 @@ If not explicitly present, .Ar n will be 0 (standard input) or 1 (standard output) -depending upon the redicection operator used. +depending upon the redirection operator used. If file descriptor .Ar n was open prior to the redirection, its previous use is closed. @@ -3632,7 +3632,7 @@ which is processed as if it had been par This includes reading yet more input if necessary, until a line is read that contains or ends with an unescaped copy of the delimiter character. -If the end delimiter (when it is not a newline) is escaoed, +If the end delimiter (when it is not a newline) is escaped, it is treated as a normal character, and .Ic read continues looking for an unescaped end delimiter character.
CVS commit: src/bin/sh
Module Name:src Committed By: jschauma Date: Fri Aug 4 15:31:40 UTC 2023 Modified Files: src/bin/sh: sh.1 Log Message: tyops: * redicection -> redirection * escaoed -> escaped Noted by J. Lewis Muir on netbsd-docs@ To generate a diff of this commit: cvs rdiff -u -r1.255 -r1.256 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: msaitoh Date: Sat Jun 24 05:17:02 UTC 2023 Modified Files: src/bin/sh: eval.c Log Message: Fix typo in a debug message. To generate a diff of this commit: cvs rdiff -u -r1.189 -r1.190 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.189 src/bin/sh/eval.c:1.190 --- src/bin/sh/eval.c:1.189 Fri Apr 7 10:34:13 2023 +++ src/bin/sh/eval.c Sat Jun 24 05:17:02 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: eval.c,v 1.189 2023/04/07 10:34:13 kre Exp $ */ +/* $NetBSD: eval.c,v 1.190 2023/06/24 05:17:02 msaitoh 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.189 2023/04/07 10:34:13 kre Exp $"); +__RCSID("$NetBSD: eval.c,v 1.190 2023/06/24 05:17:02 msaitoh Exp $"); #endif #endif /* not lint */ @@ -1002,7 +1002,7 @@ evalcommand(union node *cmd, int flgs, s */ cmdentry.cmdtype = CMDBUILTIN; cmdentry.u.bltin = bltincmd; - VTRACE(DBG_CMDS, ("No command name, assume \"comamnd\"\n")); + VTRACE(DBG_CMDS, ("No command name, assume \"command\"\n")); } else { static const char PATH[] = "PATH=";
CVS commit: src/bin/sh
Module Name:src Committed By: msaitoh Date: Sat Jun 24 05:17:02 UTC 2023 Modified Files: src/bin/sh: eval.c Log Message: Fix typo in a debug message. To generate a diff of this commit: cvs rdiff -u -r1.189 -r1.190 src/bin/sh/eval.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Apr 7 10:42:28 UTC 2023 Modified Files: src/bin/sh: memalloc.c Log Message: Remove an end of file trailing blank line that served no purpose. NFCI To generate a diff of this commit: cvs rdiff -u -r1.38 -r1.39 src/bin/sh/memalloc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Apr 7 10:42:28 UTC 2023 Modified Files: src/bin/sh: memalloc.c Log Message: Remove an end of file trailing blank line that served no purpose. NFCI To generate a diff of this commit: cvs rdiff -u -r1.38 -r1.39 src/bin/sh/memalloc.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/memalloc.c diff -u src/bin/sh/memalloc.c:1.38 src/bin/sh/memalloc.c:1.39 --- src/bin/sh/memalloc.c:1.38 Fri Apr 7 10:34:13 2023 +++ src/bin/sh/memalloc.c Fri Apr 7 10:42:28 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: memalloc.c,v 1.38 2023/04/07 10:34:13 kre Exp $ */ +/* $NetBSD: memalloc.c,v 1.39 2023/04/07 10:42:28 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)memalloc.c 8.3 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: memalloc.c,v 1.38 2023/04/07 10:34:13 kre Exp $"); +__RCSID("$NetBSD: memalloc.c,v 1.39 2023/04/07 10:42:28 kre Exp $"); #endif #endif /* not lint */ @@ -402,4 +402,3 @@ ststrcat(size_t *lp, ...) return str; } -
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Apr 7 10:34:13 UTC 2023 Modified Files: src/bin/sh: eval.c histedit.c jobs.c jobs.h main.c memalloc.c mktokens mystring.c output.c parser.c show.c src/bin/sh/funcs: dirs popd pushd Log Message: The great shell trailing whitespace cleanup of 2023... Inspired by private e-mail comments from mouse@ NFCI. To generate a diff of this commit: cvs rdiff -u -r1.188 -r1.189 src/bin/sh/eval.c cvs rdiff -u -r1.65 -r1.66 src/bin/sh/histedit.c cvs rdiff -u -r1.117 -r1.118 src/bin/sh/jobs.c cvs rdiff -u -r1.25 -r1.26 src/bin/sh/jobs.h cvs rdiff -u -r1.89 -r1.90 src/bin/sh/main.c cvs rdiff -u -r1.37 -r1.38 src/bin/sh/memalloc.c cvs rdiff -u -r1.14 -r1.15 src/bin/sh/mktokens cvs rdiff -u -r1.19 -r1.20 src/bin/sh/mystring.c cvs rdiff -u -r1.40 -r1.41 src/bin/sh/output.c cvs rdiff -u -r1.179 -r1.180 src/bin/sh/parser.c cvs rdiff -u -r1.54 -r1.55 src/bin/sh/show.c cvs rdiff -u -r1.8 -r1.9 src/bin/sh/funcs/dirs src/bin/sh/funcs/popd \ src/bin/sh/funcs/pushd 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.188 src/bin/sh/eval.c:1.189 --- src/bin/sh/eval.c:1.188 Wed Jan 5 15:25:44 2022 +++ src/bin/sh/eval.c Fri Apr 7 10:34:13 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: eval.c,v 1.188 2022/01/05 15:25:44 kre Exp $ */ +/* $NetBSD: eval.c,v 1.189 2023/04/07 10:34:13 kre 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.188 2022/01/05 15:25:44 kre Exp $"); +__RCSID("$NetBSD: eval.c,v 1.189 2023/04/07 10:34:13 kre Exp $"); #endif #endif /* not lint */ @@ -96,7 +96,7 @@ STATIC int funcnest; /* depth of functi STATIC int builtin_flags; /* evalcommand flags for builtins */ /* * Base function nesting level inside a dot command. Set to 0 initially - * and to (funcnest + 1) before every dot command to enable + * and to (funcnest + 1) before every dot command to enable * 1) detection of being in a file sourced by a dot command and * 2) counting of function nesting in that file for the implementation * of the return command. @@ -1398,7 +1398,7 @@ evalcommand(union node *cmd, int flgs, s default: VXTRACE(DBG_EVAL, ("normal command%s: ", vforked?" VF":""), trargs(argv)); - redirect(cmd->ncmd.redirect, + redirect(cmd->ncmd.redirect, (vforked ? REDIR_VFORK : 0) | REDIR_KEEP); if (!vforked) for (sp = varlist.list ; sp ; sp = sp->next) Index: src/bin/sh/histedit.c diff -u src/bin/sh/histedit.c:1.65 src/bin/sh/histedit.c:1.66 --- src/bin/sh/histedit.c:1.65 Mon Aug 22 17:33:11 2022 +++ src/bin/sh/histedit.c Fri Apr 7 10:34:13 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.c,v 1.65 2022/08/22 17:33:11 kre Exp $ */ +/* $NetBSD: histedit.c,v 1.66 2023/04/07 10:34:13 kre 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.65 2022/08/22 17:33:11 kre Exp $"); +__RCSID("$NetBSD: histedit.c,v 1.66 2023/04/07 10:34:13 kre Exp $"); #endif #endif /* not lint */ @@ -189,7 +189,7 @@ bad: el_set(el, EL_EDITOR, "emacs"); VTRACE(DBG_HISTORY, ("reading $EDITRC\n")); el_source(el, lookupvar("EDITRC")); - el_set(el, EL_BIND, "^I", + el_set(el, EL_BIND, "^I", tabcomplete ? "rl-complete" : "ed-insert", NULL); INTON; } Index: src/bin/sh/jobs.c diff -u src/bin/sh/jobs.c:1.117 src/bin/sh/jobs.c:1.118 --- src/bin/sh/jobs.c:1.117 Sun Oct 30 01:46:16 2022 +++ src/bin/sh/jobs.c Fri Apr 7 10:34:13 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: jobs.c,v 1.117 2022/10/30 01:46:16 kre Exp $ */ +/* $NetBSD: jobs.c,v 1.118 2023/04/07 10:34:13 kre 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.117 2022/10/30 01:46:16 kre Exp $"); +__RCSID("$NetBSD: jobs.c,v 1.118 2023/04/07 10:34:13 kre Exp $"); #endif #endif /* not lint */ @@ -857,7 +857,7 @@ waitcmd(int argc, char **argv) * (eg: a child of the executable that exec'd us) * Simply go back and start all over again * (this is rare). - */ + */ if (job == NULL) continue; @@ -894,9 +894,8 @@ waitcmd(int argc, char **argv) * (that is, no pid args) */ snprintf(idstring, sizeof idstring, - "%d", job->ps[ job->nprocs ? - job->nprocs-1 : - 0 ].pid); + "%d", job->ps[ job->nprocs ? + job->nprocs-1 : 0 ].pid); fpid = idstring; } VTRACE(DBG_WAIT, (" (for %s)", fpid)); Index: src/bin/sh/jobs.h diff -u src/bin/sh/jobs.h:1.25 src/bin/sh/jobs.h:1.26 --- src/bin/sh/jobs.h:1.25 Sat Sep 11 20:43:32 2021 +++ src/bin/sh/jobs.h Fri Apr 7 10:34:13 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: jobs.h,v
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Apr 7 10:34:13 UTC 2023 Modified Files: src/bin/sh: eval.c histedit.c jobs.c jobs.h main.c memalloc.c mktokens mystring.c output.c parser.c show.c src/bin/sh/funcs: dirs popd pushd Log Message: The great shell trailing whitespace cleanup of 2023... Inspired by private e-mail comments from mouse@ NFCI. To generate a diff of this commit: cvs rdiff -u -r1.188 -r1.189 src/bin/sh/eval.c cvs rdiff -u -r1.65 -r1.66 src/bin/sh/histedit.c cvs rdiff -u -r1.117 -r1.118 src/bin/sh/jobs.c cvs rdiff -u -r1.25 -r1.26 src/bin/sh/jobs.h cvs rdiff -u -r1.89 -r1.90 src/bin/sh/main.c cvs rdiff -u -r1.37 -r1.38 src/bin/sh/memalloc.c cvs rdiff -u -r1.14 -r1.15 src/bin/sh/mktokens cvs rdiff -u -r1.19 -r1.20 src/bin/sh/mystring.c cvs rdiff -u -r1.40 -r1.41 src/bin/sh/output.c cvs rdiff -u -r1.179 -r1.180 src/bin/sh/parser.c cvs rdiff -u -r1.54 -r1.55 src/bin/sh/show.c cvs rdiff -u -r1.8 -r1.9 src/bin/sh/funcs/dirs src/bin/sh/funcs/popd \ src/bin/sh/funcs/pushd Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: hannken Date: Tue Mar 21 08:31:30 UTC 2023 Modified Files: src/bin/sh: error.h Log Message: Use "sigjmp_buf loc" after switch to sigsetjmp()/siglongjmp(). Fixes errors and aborts on sparc at least. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/bin/sh/error.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/error.h diff -u src/bin/sh/error.h:1.24 src/bin/sh/error.h:1.25 --- src/bin/sh/error.h:1.24 Sun Mar 19 17:47:48 2023 +++ src/bin/sh/error.h Tue Mar 21 08:31:30 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: error.h,v 1.24 2023/03/19 17:47:48 kre Exp $ */ +/* $NetBSD: error.h,v 1.25 2023/03/21 08:31:30 hannken Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -58,7 +58,7 @@ #include struct jmploc { - jmp_buf loc; + sigjmp_buf loc; }; extern volatile int errors_suppressed;
CVS commit: src/bin/sh
Module Name:src Committed By: hannken Date: Tue Mar 21 08:31:30 UTC 2023 Modified Files: src/bin/sh: error.h Log Message: Use "sigjmp_buf loc" after switch to sigsetjmp()/siglongjmp(). Fixes errors and aborts on sparc at least. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/bin/sh/error.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sun Mar 19 17:55:57 UTC 2023 Modified Files: src/bin/sh: error.c exec.c Log Message: Do a better job handling EACCES errors from exec() calls. If the EACCES is from the namei(), treat it just like ENOENT or ENOTDIR (and if that is the final error, the exit status from a failed exec will be 127). If the EACCES is from the exec() itself, that indicates the file to be run exists, but has no 'x' permission. That's a meaningful error (as distinct from just "yet another PATH element search failure"). While here, return the first meaingful error we encountered while searching PATH, rather than the last (and ENOENT if there are none of those). This change results in some failed command executions returning status 127 now, where they returned 126 before - which better reflects the intent of those values (127 is simply "not found" whereas 126 is "found but couldn't be executed"). We still do nothing to distinguish errors encountered looking up the command name give, with errors encountered (by the kernel) attempting to run an interpreter needed for the exec to succeed (#! line path, or /libexec/ld.elf_so and similar - or anything else of a similar nature). To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/bin/sh/error.c cvs rdiff -u -r1.57 -r1.58 src/bin/sh/exec.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sun Mar 19 17:55:57 UTC 2023 Modified Files: src/bin/sh: error.c exec.c Log Message: Do a better job handling EACCES errors from exec() calls. If the EACCES is from the namei(), treat it just like ENOENT or ENOTDIR (and if that is the final error, the exit status from a failed exec will be 127). If the EACCES is from the exec() itself, that indicates the file to be run exists, but has no 'x' permission. That's a meaningful error (as distinct from just "yet another PATH element search failure"). While here, return the first meaingful error we encountered while searching PATH, rather than the last (and ENOENT if there are none of those). This change results in some failed command executions returning status 127 now, where they returned 126 before - which better reflects the intent of those values (127 is simply "not found" whereas 126 is "found but couldn't be executed"). We still do nothing to distinguish errors encountered looking up the command name give, with errors encountered (by the kernel) attempting to run an interpreter needed for the exec to succeed (#! line path, or /libexec/ld.elf_so and similar - or anything else of a similar nature). To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/bin/sh/error.c cvs rdiff -u -r1.57 -r1.58 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/error.c diff -u src/bin/sh/error.c:1.44 src/bin/sh/error.c:1.45 --- src/bin/sh/error.c:1.44 Wed Nov 10 15:26:34 2021 +++ src/bin/sh/error.c Sun Mar 19 17:55:57 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: error.c,v 1.44 2021/11/10 15:26:34 kre Exp $ */ +/* $NetBSD: error.c,v 1.45 2023/03/19 17:55:57 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)error.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: error.c,v 1.44 2021/11/10 15:26:34 kre Exp $"); +__RCSID("$NetBSD: error.c,v 1.45 2023/03/19 17:55:57 kre Exp $"); #endif #endif /* not lint */ @@ -310,6 +310,7 @@ struct errname { STATIC const struct errname errormsg[] = { { EINTR, ALL, "interrupted" }, + { EACCES, E_EXEC, "no execute permission" }, { EACCES, ALL, "permission denied" }, { EIO, ALL, "I/O error" }, { EEXIST, ALL, "file exists" }, Index: src/bin/sh/exec.c diff -u src/bin/sh/exec.c:1.57 src/bin/sh/exec.c:1.58 --- src/bin/sh/exec.c:1.57 Tue Nov 16 11:28:29 2021 +++ src/bin/sh/exec.c Sun Mar 19 17:55:57 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: exec.c,v 1.57 2021/11/16 11:28:29 kre Exp $ */ +/* $NetBSD: exec.c,v 1.58 2023/03/19 17:55:57 kre 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.57 2021/11/16 11:28:29 kre Exp $"); +__RCSID("$NetBSD: exec.c,v 1.58 2023/03/19 17:55:57 kre Exp $"); #endif #endif /* not lint */ @@ -125,18 +125,56 @@ void shellexec(char **argv, char **envp, const char *path, int idx, int vforked) { char *cmdname; - int e; + int e, action; + struct stat statb; + + action = E_EXEC; if (strchr(argv[0], '/') != NULL) { tryexec(argv[0], argv, envp, vforked); e = errno; + if (e == EACCES && stat(argv[0], ) == -1) + action = E_OPEN; } else { e = ENOENT; while ((cmdname = padvance(, argv[0], 1)) != NULL) { if (--idx < 0 && pathopt == NULL) { +/* + * tryexec() does not return if it works. + */ tryexec(cmdname, argv, envp, vforked); -if (errno != ENOENT && errno != ENOTDIR) - e = errno; +/* + * If do not already have a meaningful error + * from earlier in the PATH, examine this one + * if it is a simple "not found", just keep + * searching. + */ +if (e == ENOENT && +errno != ENOENT && errno != ENOTDIR) { + /* + * If the error is from permission + * denied on the path search (a call + * to stat() also fails) ignore it + * (just continue with the search) + * If it is EACCESS and the file exists + * (the stat succeeds) that means no + * 'x' perm on the file itself, which + * is a meaningful error, this will be + * the one reported if no later PATH + * element actually succeeds. + */ + if (errno == EACCES) { + if (stat(cmdname, ) != -1) + e = EACCES; + } else { + /* + * any other error we will + * remember as the significant + * error + */ + e = errno; + } +} } stunalloc(cmdname); } @@ -145,11 +183,17 @@ shellexec(char **argv, char **envp, cons /* Map to POSIX errors */ switch (e) { case EACCES: /* particularly this (unless no search perm) */ - /* - * should perhaps check if this EACCES is an exec() - * EACESS or a namei() EACESS - the latter should be 127 - * - but not today - */ + if (action == E_OPEN) { + /* + * this is an EACCES from
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sun Mar 19 17:47:48 UTC 2023 Modified Files: src/bin/sh: error.h Log Message: Switch from using _setjmp()/_longjmp() (on BSD systems which aren't SVR4) (and setjmp()/longjmp() elsewhere) to using sigsetjmp()/siglongjmp() everywhere. NFCI. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/bin/sh/error.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/error.h diff -u src/bin/sh/error.h:1.23 src/bin/sh/error.h:1.24 --- src/bin/sh/error.h:1.23 Sun Mar 19 17:45:29 2023 +++ src/bin/sh/error.h Sun Mar 19 17:47:48 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: error.h,v 1.23 2023/03/19 17:45:29 kre Exp $ */ +/* $NetBSD: error.h,v 1.24 2023/03/19 17:47:48 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -114,10 +114,9 @@ void sh_exit(int) __dead; /* * BSD setjmp saves the signal mask, which violates ANSI C and takes time, - * so we use _setjmp instead. + * so we use sigsetjmp instead, and explicitly do not save it. + * sh does a lot of setjmp() calls (fewer longjmp though). */ -#if defined(BSD) && !defined(__SVR4) -#define setjmp(jmploc) _setjmp(jmploc) -#define longjmp(jmploc, val) _longjmp(jmploc, val) -#endif +#define setjmp(jmploc) sigsetjmp((jmploc), 0) +#define longjmp(jmploc, val) siglongjmp((jmploc), (val))
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sun Mar 19 17:47:48 UTC 2023 Modified Files: src/bin/sh: error.h Log Message: Switch from using _setjmp()/_longjmp() (on BSD systems which aren't SVR4) (and setjmp()/longjmp() elsewhere) to using sigsetjmp()/siglongjmp() everywhere. NFCI. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/bin/sh/error.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sun Mar 19 17:45:30 UTC 2023 Modified Files: src/bin/sh: error.h Log Message: Change a few #defines from octal to hex (pdp11 days are long gone). Improve the layout of those definitions at the same time. NFC. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/bin/sh/error.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/error.h diff -u src/bin/sh/error.h:1.22 src/bin/sh/error.h:1.23 --- src/bin/sh/error.h:1.22 Mon Feb 4 11:16:41 2019 +++ src/bin/sh/error.h Sun Mar 19 17:45:29 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: error.h,v 1.22 2019/02/04 11:16:41 kre Exp $ */ +/* $NetBSD: error.h,v 1.23 2023/03/19 17:45:29 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -40,9 +40,9 @@ * Types of operations (passed to the errmsg routine). */ -#define E_OPEN 01 /* opening a file */ -#define E_CREAT 02 /* creating a file */ -#define E_EXEC 04 /* executing a program */ +#define E_OPEN 0x1 /* opening a file */ +#define E_CREAT 0x2 /* creating a file */ +#define E_EXEC 0x4 /* executing a program */ /*
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sun Mar 19 17:45:30 UTC 2023 Modified Files: src/bin/sh: error.h Log Message: Change a few #defines from octal to hex (pdp11 days are long gone). Improve the layout of those definitions at the same time. NFC. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/bin/sh/error.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Mon Mar 6 05:54:34 UTC 2023 Modified Files: src/bin/sh: expand.c Log Message: Adjust tilde expansion as will be documented in the forthcoming version of the POSIX standard (Issue 8). I believe we were already compliant with what is to be required, but POSIX is now encouraging (and will likely require in a later version) that if a tilde expansion produces a string which ends in a '/' and the '~' that was expanded is immediately followed by a '/' in the input word, that one of those two slashes be omitted. The worst (current) example of this is when HOME=/ and we expand ~/foo - previously producing //foo which is (in POSIX) a path with implementation defined semantics, and so not what we should be generating by accident. Change that, so now if the ~ prefix expansion ends in a '/' and there is a '/' following immediately after, the resulting word contains only one of those chars (in the example just given, we will now produce /foo instead). POSIX is also making it clear that the expansion that results from the tilde expansion is treated as quoted (not subject to pathname expansion, or field splitting, or any var/arith/command substitutions) and that if HOME="" the expansion of ~ must generate "" (not nothing). Our implementation did all of that already (though older versions used to treat an empty expansion of HOME the same as if HOME was unset - that was fixed some time ago). The actual modification made here is probably smaller than this log entry, and without added comments, certainly is! To generate a diff of this commit: cvs rdiff -u -r1.141 -r1.142 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.141 src/bin/sh/expand.c:1.142 --- src/bin/sh/expand.c:1.141 Mon Nov 22 05:17:43 2021 +++ src/bin/sh/expand.c Mon Mar 6 05:54:34 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: expand.c,v 1.141 2021/11/22 05:17:43 kre Exp $ */ +/* $NetBSD: expand.c,v 1.142 2023/03/06 05:54:34 kre 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.141 2021/11/22 05:17:43 kre Exp $"); +__RCSID("$NetBSD: expand.c,v 1.142 2023/03/06 05:54:34 kre Exp $"); #endif #endif /* not lint */ @@ -388,7 +388,7 @@ argstr(const char *p, int flag) STATIC const char * exptilde(const char *p, int flag) { - char c; + char c, last; const char *startp = p; struct passwd *pw; const char *home; @@ -457,15 +457,35 @@ exptilde(const char *p, int flag) * Posix XCU 2.6.1: The value of $HOME (for ~) or the initial * working directory from getpwnam() for ~user * Nothing there about "except if a null string". So do what it wants. + * In later drafts (to become Issue 8), it is even required that in + * this case, (where HOME='') a bare ~ expands to "" (which must not + * be reduced to nothing). */ - if (home == NULL /* || *home == '\0' */) { + last = '\0'; /* just in case *home == '\0' (already) */ + if (home == NULL) { CTRACE(DBG_EXPAND, (": returning unused \"%s\"\n", startp)); return startp; } while ((c = *home++) != '\0') { if ((quotes && NEEDESC(c)) || ISCTL(c)) STPUTC(CTLESC, expdest); STPUTC(c, expdest); + last = c; } + + /* + * If HOME (or whatver) ended in a '/' (last == '/'), and + * the ~prefix was terminated by a '/', then only keep one + * of them - since we already took the one from HOME, just + * skip over the one that ended the tilde prefix. + * + * Current (Issue 8) drafts say this is permitted, and recommend + * it - a later version of the standard will probably require it. + * This is to prevent ~/foo generating //foo when HOME=/ (and + * other cases like it, but that's the important one). + */ + if (last == '/' && *p == '/') + p++; + CTRACE(DBG_EXPAND, (": added %d \"%.*s\" returning \"%s\"\n", expdest - stackblock() - offs, expdest - stackblock() - offs, stackblock() + offs, p));
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Mon Mar 6 05:54:34 UTC 2023 Modified Files: src/bin/sh: expand.c Log Message: Adjust tilde expansion as will be documented in the forthcoming version of the POSIX standard (Issue 8). I believe we were already compliant with what is to be required, but POSIX is now encouraging (and will likely require in a later version) that if a tilde expansion produces a string which ends in a '/' and the '~' that was expanded is immediately followed by a '/' in the input word, that one of those two slashes be omitted. The worst (current) example of this is when HOME=/ and we expand ~/foo - previously producing //foo which is (in POSIX) a path with implementation defined semantics, and so not what we should be generating by accident. Change that, so now if the ~ prefix expansion ends in a '/' and there is a '/' following immediately after, the resulting word contains only one of those chars (in the example just given, we will now produce /foo instead). POSIX is also making it clear that the expansion that results from the tilde expansion is treated as quoted (not subject to pathname expansion, or field splitting, or any var/arith/command substitutions) and that if HOME="" the expansion of ~ must generate "" (not nothing). Our implementation did all of that already (though older versions used to treat an empty expansion of HOME the same as if HOME was unset - that was fixed some time ago). The actual modification made here is probably smaller than this log entry, and without added comments, certainly is! To generate a diff of this commit: cvs rdiff -u -r1.141 -r1.142 src/bin/sh/expand.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Feb 24 19:04:54 UTC 2023 Modified Files: src/bin/sh: alias.c Log Message: Allow (but do not require) the magic '--' option terminator in the builtin 'alias' command. This allows portability (not that anyone should really care with aliases) for scripts from other shells in which the alias command has options, and the -- is required to allow the first alias name to begin with a '-'. That is, for us, alias -x='echo x' works fine, always has, and still does. But other shells treat that as an attempt to use the -x option (and maybe -= etc), and require alias -- -x='echo x'. For us that variant used to complain about the alias -- not existing (as an arg with no '=' is treated as a request to extract the value of the alias). Posix also generally requires all standard commands (or which "alias" is one, unfortunately) to support '--' even if they have no options, for precisely this reason. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 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.21 src/bin/sh/alias.c:1.22 --- src/bin/sh/alias.c:1.21 Sat Feb 9 09:11:07 2019 +++ src/bin/sh/alias.c Fri Feb 24 19:04:54 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: alias.c,v 1.21 2019/02/09 09:11:07 kre Exp $ */ +/* $NetBSD: alias.c,v 1.22 2023/02/24 19:04:54 kre 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.21 2019/02/09 09:11:07 kre Exp $"); +__RCSID("$NetBSD: alias.c,v 1.22 2023/02/24 19:04:54 kre Exp $"); #endif #endif /* not lint */ @@ -253,18 +253,20 @@ countaliases(void) } int -aliascmd(int argc, char **argv) +aliascmd(int argc, char **argv) /* ARGSUSED */ { char *n, *v; int ret = 0; struct alias *ap; - if (argc == 1) { + (void) nextopt(NULL); /* consume possible "--" */ + + if (*argptr == NULL) { list_aliases(); return 0; } - while ((n = *++argv) != NULL) { + while ((n = *argptr++) != NULL) { if ((v = strchr(n+1, '=')) == NULL) { /* n+1: funny ksh stuff */ if ((ap = lookupalias(n, 0)) == NULL) { outfmt(out2, "alias: %s not found\n", n);
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Feb 24 19:04:54 UTC 2023 Modified Files: src/bin/sh: alias.c Log Message: Allow (but do not require) the magic '--' option terminator in the builtin 'alias' command. This allows portability (not that anyone should really care with aliases) for scripts from other shells in which the alias command has options, and the -- is required to allow the first alias name to begin with a '-'. That is, for us, alias -x='echo x' works fine, always has, and still does. But other shells treat that as an attempt to use the -x option (and maybe -= etc), and require alias -- -x='echo x'. For us that variant used to complain about the alias -- not existing (as an arg with no '=' is treated as a request to extract the value of the alias). Posix also generally requires all standard commands (or which "alias" is one, unfortunately) to support '--' even if they have no options, for precisely this reason. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/bin/sh/alias.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Tue Dec 20 17:51:54 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: More markup errors. \+ was intended to be \&+ and .EV .Ev of course. As best I can tell, the rest of what mandoc -Wall complains about is incorrect (it could probably be avoided by adding more markup, but there doesn't seem to be any point). To generate a diff of this commit: cvs rdiff -u -r1.254 -r1.255 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.254 src/bin/sh/sh.1:1.255 --- src/bin/sh/sh.1:1.254 Tue Dec 20 16:48:57 2022 +++ src/bin/sh/sh.1 Tue Dec 20 17:51:54 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.254 2022/12/20 16:48:57 kre Exp $ +.\" $NetBSD: sh.1,v 1.255 2022/12/20 17:51:54 kre Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -122,7 +122,7 @@ When first starting, if neither the .Fl l nor -.Cm \+l +.Cm \&+l options were given on the command line, the shell inspects argument 0, and if it begins with a dash .Sq \- , @@ -1782,7 +1782,7 @@ field with the value of each parameter s the .Ev IFS variable (possibly nothing if -.EV IFS +.Ev IFS has a null value), or by a .Aq space if
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Tue Dec 20 17:51:54 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: More markup errors. \+ was intended to be \&+ and .EV .Ev of course. As best I can tell, the rest of what mandoc -Wall complains about is incorrect (it could probably be avoided by adding more markup, but there doesn't seem to be any point). To generate a diff of this commit: cvs rdiff -u -r1.254 -r1.255 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Tue Dec 20 16:48:57 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: Using .Cm Cm makes no sense at all - no idea what I was thinking there (perhaps just an editing error). To generate a diff of this commit: cvs rdiff -u -r1.253 -r1.254 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.253 src/bin/sh/sh.1:1.254 --- src/bin/sh/sh.1:1.253 Tue Dec 20 01:18:42 2022 +++ src/bin/sh/sh.1 Tue Dec 20 16:48:57 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.253 2022/12/20 01:18:42 uwe Exp $ +.\" $NetBSD: sh.1,v 1.254 2022/12/20 16:48:57 kre Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -424,7 +424,7 @@ a login shell. When reset on the command line .Po Cm \&+l or -.Cm Cm \&+o Em login Pc , +.Cm \&+o Em login Pc , the shell will not be considered a login shell, even if the command name parameter .Po Va argv[0] Pc
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Tue Dec 20 16:48:57 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: Using .Cm Cm makes no sense at all - no idea what I was thinking there (perhaps just an editing error). To generate a diff of this commit: cvs rdiff -u -r1.253 -r1.254 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: uwe Date: Tue Dec 20 01:18:42 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: sh(1): Fix markup. -compact must be last. To generate a diff of this commit: cvs rdiff -u -r1.252 -r1.253 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.252 src/bin/sh/sh.1:1.253 --- src/bin/sh/sh.1:1.252 Sun Dec 11 08:23:10 2022 +++ src/bin/sh/sh.1 Tue Dec 20 01:18:42 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.252 2022/12/11 08:23:10 kre Exp $ +.\" $NetBSD: sh.1,v 1.253 2022/12/20 01:18:42 uwe Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -2767,7 +2767,7 @@ before the command is invoked. With the default value for .Dv IFS : -.Bd -unfilled -compact -offset indent +.Bd -unfilled -offset indent -compact X='a b c' export Y=$X .Ed @@ -4752,7 +4752,7 @@ in the circumstances described. Any present will always appear in ASCII lexical order, as they appear below (to make testing the value easier to code). .Pp -.Bl -compact -tag -width M__ -offset indent +.Bl -tag -width M__ -offset indent -compact .It \&! Always present when set by .Nm ,
CVS commit: src/bin/sh
Module Name:src Committed By: uwe Date: Tue Dec 20 01:18:42 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: sh(1): Fix markup. -compact must be last. To generate a diff of this commit: cvs rdiff -u -r1.252 -r1.253 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sun Dec 11 08:23:11 UTC 2022 Modified Files: src/bin/sh: miscbltin.c sh.1 Log Message: It appears that POSIX intends to add a -d X option to the read command in its next version, so it can be used as -d '' (to specify a \0 end character for the record read, rather than the default \n) to accompany find -print0 and xargs -0 options (also likely to be added). Add support for -d now. While here fix a bug where escaped nul chars (\ \0) in non-raw mode were not being dropped, as they are when not escaped (if not dropped, they're still not used in any useful way, they just ended the value at that point). To generate a diff of this commit: cvs rdiff -u -r1.52 -r1.53 src/bin/sh/miscbltin.c cvs rdiff -u -r1.251 -r1.252 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/miscbltin.c diff -u src/bin/sh/miscbltin.c:1.52 src/bin/sh/miscbltin.c:1.53 --- src/bin/sh/miscbltin.c:1.52 Fri Aug 19 12:52:31 2022 +++ src/bin/sh/miscbltin.c Sun Dec 11 08:23:10 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: miscbltin.c,v 1.52 2022/08/19 12:52:31 kre Exp $ */ +/* $NetBSD: miscbltin.c,v 1.53 2022/12/11 08:23:10 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)miscbltin.c 8.4 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: miscbltin.c,v 1.52 2022/08/19 12:52:31 kre Exp $"); +__RCSID("$NetBSD: miscbltin.c,v 1.53 2022/12/11 08:23:10 kre Exp $"); #endif #endif /* not lint */ @@ -91,6 +91,7 @@ readcmd(int argc, char **argv) { char **ap; char c; + char end; int rflag; char *prompt; const char *ifs; @@ -102,13 +103,21 @@ readcmd(int argc, char **argv) int saveall = 0; ptrdiff_t wordlen = 0; + end = '\n';/* record delimiter */ rflag = 0; prompt = NULL; - while ((i = nextopt("p:r")) != '\0') { - if (i == 'p') + while ((i = nextopt("d:p:r")) != '\0') { + switch (i) { + case 'd': + end = *optionarg; /* even if '\0' */ + break; + case 'p': prompt = optionarg; - else + break; + case 'r': rflag = 1; + break; + } } if (*(ap = argptr) == NULL) @@ -131,19 +140,19 @@ readcmd(int argc, char **argv) status = 1; break; } - if (c == '\0') - continue; - if (c == '\\' && !rflag) { + if (c == '\\' && c != end && !rflag) { if (read(0, , 1) != 1) { status = 1; break; } - if (c != '\n') + if (c != '\n') /* \ \n is always just removed */ goto wdch; continue; } - if (c == '\n') + if (c == end) break; + if (c == '\0') + continue; if (strchr(ifs, c)) is_ifs = strchr(" \t\n", c) ? 1 : 2; else @@ -167,6 +176,8 @@ readcmd(int argc, char **argv) if (is_ifs == 0) { wdch:; + if (c == '\0') /* always ignore attempts to input \0 */ +continue; /* append this character to the current variable */ startword = 0; if (saveall) Index: src/bin/sh/sh.1 diff -u src/bin/sh/sh.1:1.251 src/bin/sh/sh.1:1.252 --- src/bin/sh/sh.1:1.251 Sun Oct 30 01:19:08 2022 +++ src/bin/sh/sh.1 Sun Dec 11 08:23:10 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.251 2022/10/30 01:19:08 kre Exp $ +.\" $NetBSD: sh.1,v 1.252 2022/12/11 08:23:10 kre Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -31,8 +31,7 @@ .\" .\" @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" -.\" RIP Noi, October 6, 1959 -- -.Dd August 26, 2022 +.Dd December 9, 2022 .Dt SH 1 .\" everything except c o and s (keep them ordered) .ds flags abCEeFfhIiLlmnpquVvXx @@ -3583,15 +3582,21 @@ the program will use and the built-in uses a separately cached value. .\" .Pp -.It Ic read Oo Fl p Ar prompt Oc Oo Fl r Oc Ar variable Op Ar ... +.It Ic read Oo Fl d Ar delim Oc Oo Fl p Ar prompt Oc Oo Fl r Oc Ar variable Op Ar ... The .Ar prompt is printed on standard error if the .Fl p option is specified and the standard input is a terminal. -Then a line is read from the standard input. -The trailing newline is deleted from the -line and the line is split as described in the field splitting section of the +Then a record, terminated by the +first character of +.Ar delim +if the +.Fl d +option was given, or a newline character otherwise, +is read from the standard input. +The ending delimiter is deleted from the +record which is then split as described in the field splitting section of the .Sx Word Expansions section above. The pieces are assigned to the @@ -3614,17 +3619,41 @@ which case failure is returned. By default, unless the .Fl r option is specified, the backslash -.Dq \e -acts as an escape character, causing the following character to be treated -literally. +.Pq Ql \e +acts as an escape character, +causing the following character, +when that character is the escape character, or end delimiter character, +to be treated literally when reading the record. This is the only form of quoting that applies. If an
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sun Dec 11 08:23:11 UTC 2022 Modified Files: src/bin/sh: miscbltin.c sh.1 Log Message: It appears that POSIX intends to add a -d X option to the read command in its next version, so it can be used as -d '' (to specify a \0 end character for the record read, rather than the default \n) to accompany find -print0 and xargs -0 options (also likely to be added). Add support for -d now. While here fix a bug where escaped nul chars (\ \0) in non-raw mode were not being dropped, as they are when not escaped (if not dropped, they're still not used in any useful way, they just ended the value at that point). To generate a diff of this commit: cvs rdiff -u -r1.52 -r1.53 src/bin/sh/miscbltin.c cvs rdiff -u -r1.251 -r1.252 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sun Oct 30 01:46:17 UTC 2022 Modified Files: src/bin/sh: jobs.c Log Message: PR bin/57053 is related (peripherally) here. sh has been remembering the process group of a job for a while now, but using that for almost nothing. The old way to resume a job, was to try each pid in the job with a SIGCONT (using it as the process group identifier via killpg()) until one worked (or none did, in which case resuming would be impossible, but that never actually happened). This wasn't as bad as it seems, as in practice the first process attempted was *always* the correct one. Why the loop was considered necessary I am not sure. Nothing but the first could possibly work. This worked until a fix for an obscure possible bug was added a while ago - now a process which has already finished, and had its zombie collected via wait*() is no longer ever considered to have a pid which is a candidate for use in any system call. That's because the kernel might have reassigned that pid for some newly created process (we have no idea how much time might have passed since the pid was returned to the kernel for reuse, it might have happened weeks ago). This is where the example in bin/57053 revealed a problem. That PR is really about a quite different problem in zsh (from pksrc) and should be pkg/57053, but as the test case also hit the problem here, it was assumed (by some) they were the same issue. The example is (in a small directory) ls | less which is then suspended (^Z), and resumed (fg). Since the directory is small, ls will be finished, and reaped by sh - so the code would now refuse to use its pid for the killpg() call to send the SIGCONT. The (useless) loop would attempt to use less's pid for this purpose (it is still alive at this point) but that would fail, as that pid is not a process group identifier, of anything. Hence the job could not be resumed. Before the PR (or preceding mailing list discussion) the change here had already been made (part of a much bigger set of changes, some of which might follow - sometime). We now actually use the job's remembered process group identifier when we want the process group identifier, instead of trying to guess which pid it happens to be (which actually never took any guessing, it was, and is always the pid of the first process created for the job). A couple of minor fixes to how the pgrp is obtained, and used, accompany the changes to use it when appropriate. To generate a diff of this commit: cvs rdiff -u -r1.116 -r1.117 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.116 src/bin/sh/jobs.c:1.117 --- src/bin/sh/jobs.c:1.116 Mon Apr 18 06:02:27 2022 +++ src/bin/sh/jobs.c Sun Oct 30 01:46:16 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: jobs.c,v 1.116 2022/04/18 06:02:27 kre Exp $ */ +/* $NetBSD: jobs.c,v 1.117 2022/10/30 01:46:16 kre 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.116 2022/04/18 06:02:27 kre Exp $"); +__RCSID("$NetBSD: jobs.c,v 1.117 2022/10/30 01:46:16 kre Exp $"); #endif #endif /* not lint */ @@ -267,11 +267,7 @@ do_fgcmd(const char *arg_ptr) out1c('\n'); flushall(); - for (i = 0; i < jp->nprocs; i++) - if (tcsetpgrp(ttyfd, jp->ps[i].pid) != -1) - break; - - if (i >= jp->nprocs) { + if (tcsetpgrp(ttyfd, jp->pgrp) == -1) { error("Cannot set tty process group (%s) at %d", strerror(errno), __LINE__); } @@ -376,6 +372,9 @@ restartjob(struct job *jp) if (jp->state == JOBDONE) return; + if (jp->pgrp == 0) + error("Job [%d] does not have a process group", JNUM(jp)); + INTOFF; for (e = i = 0; i < jp->nprocs; i++) { /* @@ -390,13 +389,16 @@ restartjob(struct job *jp) * Otherwise tell it to continue, if it worked, we're done * (we signal the whole process group) */ - if (killpg(jp->ps[i].pid, SIGCONT) != -1) + if (killpg(jp->pgrp, SIGCONT) != -1) break; - if (e == 0 && errno != ESRCH) - e = errno; + e = errno; + break; /* no point trying again */ } - if (i >= jp->nprocs) - error("Cannot continue job (%s)", strerror(e ? e : ESRCH)); + + if (e != 0) + error("Cannot continue job (%s)", strerror(e)); + else if (i >= jp->nprocs) + error("Job [%d] has no stopped processes", JNUM(jp)); /* * Now change state of all stopped processes in the job to running @@ -436,8 +438,8 @@ showjob(struct output *out, struct job * #if JOBS if (mode & SHOW_PGID) { - /* just output process (group) id of pipeline */ - outfmt(out, "%ld\n", (long)jp->ps->pid); + /* output only the process group ID (lead process ID) */ + outfmt(out, "%ld\n", (long)jp->pgrp); return; } #endif @@ -1206,14 +1208,19 @@ forkshell(struct job *jp, union node *n, int
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sun Oct 30 01:46:17 UTC 2022 Modified Files: src/bin/sh: jobs.c Log Message: PR bin/57053 is related (peripherally) here. sh has been remembering the process group of a job for a while now, but using that for almost nothing. The old way to resume a job, was to try each pid in the job with a SIGCONT (using it as the process group identifier via killpg()) until one worked (or none did, in which case resuming would be impossible, but that never actually happened). This wasn't as bad as it seems, as in practice the first process attempted was *always* the correct one. Why the loop was considered necessary I am not sure. Nothing but the first could possibly work. This worked until a fix for an obscure possible bug was added a while ago - now a process which has already finished, and had its zombie collected via wait*() is no longer ever considered to have a pid which is a candidate for use in any system call. That's because the kernel might have reassigned that pid for some newly created process (we have no idea how much time might have passed since the pid was returned to the kernel for reuse, it might have happened weeks ago). This is where the example in bin/57053 revealed a problem. That PR is really about a quite different problem in zsh (from pksrc) and should be pkg/57053, but as the test case also hit the problem here, it was assumed (by some) they were the same issue. The example is (in a small directory) ls | less which is then suspended (^Z), and resumed (fg). Since the directory is small, ls will be finished, and reaped by sh - so the code would now refuse to use its pid for the killpg() call to send the SIGCONT. The (useless) loop would attempt to use less's pid for this purpose (it is still alive at this point) but that would fail, as that pid is not a process group identifier, of anything. Hence the job could not be resumed. Before the PR (or preceding mailing list discussion) the change here had already been made (part of a much bigger set of changes, some of which might follow - sometime). We now actually use the job's remembered process group identifier when we want the process group identifier, instead of trying to guess which pid it happens to be (which actually never took any guessing, it was, and is always the pid of the first process created for the job). A couple of minor fixes to how the pgrp is obtained, and used, accompany the changes to use it when appropriate. To generate a diff of this commit: cvs rdiff -u -r1.116 -r1.117 src/bin/sh/jobs.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sun Oct 30 01:19:08 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: Note in the description of "jobs -p" that the process id returned is also the process group identifier (that's a requirement from POSIX, and is what we have always done - just not been explicit about in sh.1). Add a note that this value and $! are not necessarily the same (currently, and perhaps forever, never the same in a pipeline with 2 or more elements). To generate a diff of this commit: cvs rdiff -u -r1.250 -r1.251 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sun Oct 30 01:19:08 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: Note in the description of "jobs -p" that the process id returned is also the process group identifier (that's a requirement from POSIX, and is what we have always done - just not been explicit about in sh.1). Add a note that this value and $! are not necessarily the same (currently, and perhaps forever, never the same in a pipeline with 2 or more elements). To generate a diff of this commit: cvs rdiff -u -r1.250 -r1.251 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.250 src/bin/sh/sh.1:1.251 --- src/bin/sh/sh.1:1.250 Sun Sep 18 06:03:19 2022 +++ src/bin/sh/sh.1 Sun Oct 30 01:19:08 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.250 2022/09/18 06:03:19 kre Exp $ +.\" $NetBSD: sh.1,v 1.251 2022/10/30 01:19:08 kre Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -3310,7 +3310,11 @@ status of each process, rather than the With the .Fl p flag, the output contains only the process identifier of the lead -process. +process (which is also the process group identifier). +Note that this is not necessarily the same process identifier as +reported in the special parameter +.Dv \&! +when a background job is started. .Pp With the .Fl Z
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sun Sep 18 17:11:33 UTC 2022 Modified Files: src/bin/sh: var.c Log Message: Oops, somehow managed to commit an older version where NBSH_INVOCATION start char was '@' rather than '!' (which meant not lexically ordered). This is how it was intended to be (and is documented). To generate a diff of this commit: cvs rdiff -u -r1.81 -r1.82 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.81 src/bin/sh/var.c:1.82 --- src/bin/sh/var.c:1.81 Sun Sep 18 06:03:19 2022 +++ src/bin/sh/var.c Sun Sep 18 17:11:33 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.81 2022/09/18 06:03:19 kre Exp $ */ +/* $NetBSD: var.c,v 1.82 2022/09/18 17:11:33 kre 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.81 2022/09/18 06:03:19 kre Exp $"); +__RCSID("$NetBSD: var.c,v 1.82 2022/09/18 17:11:33 kre Exp $"); #endif #endif /* not lint */ @@ -538,7 +538,7 @@ setvar_invocation(int argc, char **argv) */ v = value; - *v++ = '@'; /* never empty, and the '-' is not first */ + *v++ = '!'; /* never empty, and the '-' is not first */ if (argc > 0 && argv[0] != NULL && argv[0][0] == '-') *v++ = '-';
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sun Sep 18 17:11:33 UTC 2022 Modified Files: src/bin/sh: var.c Log Message: Oops, somehow managed to commit an older version where NBSH_INVOCATION start char was '@' rather than '!' (which meant not lexically ordered). This is how it was intended to be (and is documented). To generate a diff of this commit: cvs rdiff -u -r1.81 -r1.82 src/bin/sh/var.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sun Sep 18 06:03:19 UTC 2022 Modified Files: src/bin/sh: main.c option.list options.c sh.1 var.c var.h Log Message: Add the -l option (aka -o login): be a login shell. Meaningful only on the command line (with both - and + forms) - overrides the presence (or otherwise) of a '-' as argv[0][0]. Since this allows any shell to be a login shell (which simply means that it runs /etc/profile and ~/.profile at shell startup - there are no other side effects) add a new, always set at startup, variable NBSH_INVOCATION which has a char string as its value, where each char has a meaning, more or less related to how the shell was started. See sh(1). This is intended to allow those startup scripts to tailor their behaviour to the nature of this particular login shell (it is possible to detect whether a shell is a login shell merely because of -l, or whether it would have been anyway, before the -l option was added - and more). The var could also be used to set different values for $ENV for different uses of the shell. To generate a diff of this commit: cvs rdiff -u -r1.88 -r1.89 src/bin/sh/main.c cvs rdiff -u -r1.9 -r1.10 src/bin/sh/option.list cvs rdiff -u -r1.57 -r1.58 src/bin/sh/options.c cvs rdiff -u -r1.249 -r1.250 src/bin/sh/sh.1 cvs rdiff -u -r1.80 -r1.81 src/bin/sh/var.c cvs rdiff -u -r1.38 -r1.39 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/main.c diff -u src/bin/sh/main.c:1.88 src/bin/sh/main.c:1.89 --- src/bin/sh/main.c:1.88 Tue Oct 26 10:07:20 2021 +++ src/bin/sh/main.c Sun Sep 18 06:03:19 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.88 2021/10/26 10:07:20 kre Exp $ */ +/* $NetBSD: main.c,v 1.89 2022/09/18 06:03:19 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19 #if 0 static char sccsid[] = "@(#)main.c 8.7 (Berkeley) 7/19/95"; #else -__RCSID("$NetBSD: main.c,v 1.88 2021/10/26 10:07:20 kre Exp $"); +__RCSID("$NetBSD: main.c,v 1.89 2022/09/18 06:03:19 kre Exp $"); #endif #endif /* not lint */ @@ -212,6 +212,7 @@ main(int argc, char **argv) initpwd(); setstackmark(); procargs(argc, argv); + setvar_invocation(argc, argv); #if 0 /* This now happens (indirectly) in the procargs() just above */ /* @@ -229,7 +230,7 @@ main(int argc, char **argv) choose_ps1(); #endif - if (argv[0] && argv[0][0] == '-') { + if (loginsh) { state = 1; read_profile("/etc/profile"); state1: Index: src/bin/sh/option.list diff -u src/bin/sh/option.list:1.9 src/bin/sh/option.list:1.10 --- src/bin/sh/option.list:1.9 Fri Nov 23 20:40:06 2018 +++ src/bin/sh/option.list Sun Sep 18 06:03:19 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: option.list,v 1.9 2018/11/23 20:40:06 kre Exp $ */ +/* $NetBSD: option.list,v 1.10 2022/09/18 06:03:19 kre Exp $ */ /* * define the shell's settable options @@ -58,6 +58,7 @@ sflag stdin s # read from standard inp // non-standard options -- 'i' is just a state, not an option in standard. iflag interactive i # interactive shell +loginsh login l # a login shell cdprint cdprint# always print result of a cd usefork fork F # use fork(2) instead of vfork(2) pflag nopriv p # preserve privs if set[ug]id Index: src/bin/sh/options.c diff -u src/bin/sh/options.c:1.57 src/bin/sh/options.c:1.58 --- src/bin/sh/options.c:1.57 Sat Apr 16 14:20:45 2022 +++ src/bin/sh/options.c Sun Sep 18 06:03:19 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: options.c,v 1.57 2022/04/16 14:20:45 kre Exp $ */ +/* $NetBSD: options.c,v 1.58 2022/09/18 06:03:19 kre 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.57 2022/04/16 14:20:45 kre Exp $"); +__RCSID("$NetBSD: options.c,v 1.58 2022/09/18 06:03:19 kre Exp $"); #endif #endif /* not lint */ @@ -122,6 +122,10 @@ procargs(int argc, char **argv) if (debug == 2) debug = 1; #endif + arg0 = argv[0]; + if (loginsh == 2 && arg0 != NULL && arg0[0] == '-') + loginsh = 1; + /* * Any options not dealt with as special cases just above, * and which were not set on the command line, are set to @@ -136,7 +140,6 @@ procargs(int argc, char **argv) optlist[i].dflt = optlist[i].val; } - arg0 = argv[0]; if (sflag == 0 && minusc == NULL) { commandname = argv[0]; arg0 = *argptr++; Index: src/bin/sh/sh.1 diff -u src/bin/sh/sh.1:1.249 src/bin/sh/sh.1:1.250 --- src/bin/sh/sh.1:1.249 Fri Sep 16 19:25:09 2022 +++ src/bin/sh/sh.1 Sun Sep 18 06:03:19 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.249 2022/09/16 19:25:09 kre Exp $ +.\" $NetBSD: sh.1,v 1.250 2022/09/18 06:03:19 kre Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -31,10 +31,11 @@ .\" .\" @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" -.Dd January 7, 2022 +.\" RIP Noi,
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sun Sep 18 06:03:19 UTC 2022 Modified Files: src/bin/sh: main.c option.list options.c sh.1 var.c var.h Log Message: Add the -l option (aka -o login): be a login shell. Meaningful only on the command line (with both - and + forms) - overrides the presence (or otherwise) of a '-' as argv[0][0]. Since this allows any shell to be a login shell (which simply means that it runs /etc/profile and ~/.profile at shell startup - there are no other side effects) add a new, always set at startup, variable NBSH_INVOCATION which has a char string as its value, where each char has a meaning, more or less related to how the shell was started. See sh(1). This is intended to allow those startup scripts to tailor their behaviour to the nature of this particular login shell (it is possible to detect whether a shell is a login shell merely because of -l, or whether it would have been anyway, before the -l option was added - and more). The var could also be used to set different values for $ENV for different uses of the shell. To generate a diff of this commit: cvs rdiff -u -r1.88 -r1.89 src/bin/sh/main.c cvs rdiff -u -r1.9 -r1.10 src/bin/sh/option.list cvs rdiff -u -r1.57 -r1.58 src/bin/sh/options.c cvs rdiff -u -r1.249 -r1.250 src/bin/sh/sh.1 cvs rdiff -u -r1.80 -r1.81 src/bin/sh/var.c cvs rdiff -u -r1.38 -r1.39 src/bin/sh/var.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Sep 16 19:25:10 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: More wording improvements. There might be more to come. To generate a diff of this commit: cvs rdiff -u -r1.248 -r1.249 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.248 src/bin/sh/sh.1:1.249 --- src/bin/sh/sh.1:1.248 Fri Sep 16 17:32:18 2022 +++ src/bin/sh/sh.1 Fri Sep 16 19:25:09 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.248 2022/09/16 17:32:18 kre Exp $ +.\" $NetBSD: sh.1,v 1.249 2022/09/16 19:25:09 kre Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -885,7 +885,8 @@ built-in command. Whenever a reserved word (see above) may occur, and after checking for reserved words, the shell checks the word to see if it matches an alias. -If it does, it replaces it in the input stream with its value. +If it does, the alias word is replaced by its value in the input stream, +as if the value had been entered instead. For example, if there is an alias called .Dq lf with the value @@ -936,7 +937,8 @@ command is located. Any remaining words are considered the arguments of the command. If no command name resulted, then the .Dq Ar name Ns Li = Ns Ar value -variable assignments recognized in item 1 affect the current shell. +variable assignments recognized in item 1 affect the current shell, +but are not automatically added to the environment (are not exported). .It Redirections are performed, from first to last, in the order given, as described in the next section. @@ -968,6 +970,11 @@ that refers to a file descriptor. If present it must occur unquoted, immediately before the redirection operator, with no intervening white space, and becomes a part of that operator. +If not explicitly present, +.Ar n +will be 0 (standard input) +or 1 (standard output) +depending upon the redicection operator used. If file descriptor .Ar n was open prior to the redirection, its previous use is closed. @@ -1117,7 +1124,7 @@ are set to the arguments of the shell fu The variables which are explicitly placed in the environment of the command (by placing assignments to them before the function name) are made local to the function and are set to the values given, -and exported for the benefit of programs executed with the function. +and exported for the benefit of programs executed within the function. Then the command given in the function definition is executed. The positional parameters, and local variables, are restored to their original values when the command completes. @@ -1300,9 +1307,10 @@ sends both the standard output and stand to the standard input of command2. .Pp Note that unlike some other shells, each process in the pipeline is a -child of the invoking shell (unless it is a shell built-in, in which case -it executes in the current shell \(em but any effect it has on the -environment is wiped). +child of the invoking shell, except in the case where the pipeline +is a single simple command (no +.Sq Ic \(ba +characters appear.) .Pp A pipeline is a simple case of an AND-OR-list (described below.) A @@ -1742,11 +1750,14 @@ The value of the parameter is listed nex .It Dv * Expands to the positional parameters, starting from one. When the -expansion occurs within a double-quoted string it expands to a single +expansion occurs in a situation where field splitting is never +performed, such as within a double-quoted string, it expands to a single field with the value of each parameter separated by the first character of the .Ev IFS -variable, or by a +variable (possibly nothing if +.EV IFS +has a null value), or by a .Aq space if .Ev IFS @@ -1755,6 +1766,13 @@ is unset. Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each positional parameter expands as a separate argument. +If the expansion happens in other situations where field splitting +is not performed, whether double quoted or not, the results are undefined. +In most shells, including this one, +.Dv \&$@ +is treated as +.Dv \&$* +in such a context, but this is not universally true. If there are no positional parameters, the expansion of @ generates zero arguments, even when .Dv $@ @@ -1831,8 +1849,8 @@ instances of the expansion, or any of th Unless the .Ev IFS variable has an empty value, -Field Splitting is performed on fields -generated by step (1) except for Tilde Expansion. +Field Splitting is performed on the text resulting from +the expansions in step (1) except for Tilde Expansion. .It Pathname Expansion (unless set .Fl f
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Sep 16 19:25:10 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: More wording improvements. There might be more to come. To generate a diff of this commit: cvs rdiff -u -r1.248 -r1.249 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Sep 16 17:32:18 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: Minor wording improvements. Note these do not alter anything about what the man page specifies, just say a couple of things in a slightly better way, hence no Dd update accompanies this change (deliberately). To generate a diff of this commit: cvs rdiff -u -r1.247 -r1.248 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.247 src/bin/sh/sh.1:1.248 --- src/bin/sh/sh.1:1.247 Fri Sep 16 17:29:21 2022 +++ src/bin/sh/sh.1 Fri Sep 16 17:32:18 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.247 2022/09/16 17:29:21 kre Exp $ +.\" $NetBSD: sh.1,v 1.248 2022/09/16 17:32:18 kre Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -159,7 +159,7 @@ is correct, as desired, use: Otherwise if .Ev ENV appears to contain a command substitution, -which is not performed here, +which is never performed here, or if there were no expansions to expand, the value of .Ev ENV is used as the file name. @@ -258,8 +258,7 @@ The .Ic set Fl o name is provided next to the single letter option in the description below. -Some options have only a long name, they are described after -the flag options, they are used with +Some options have only a long name, and are used with .Fl o or .Cm +o @@ -270,7 +269,7 @@ Those are listed in the table below afte with a one letter, flag, equivalent. .Pp Other options described are for the command line only. -Specifying a dash +Specifying using a dash (or minus) .Dq Cm \- turns the option on, while using a plus .Dq Cm + @@ -411,7 +410,8 @@ For more details see the section .Sx LINENO below. .It Fl m Em monitor -Turn on job control (set automatically at shell startup when interactive). +Turn on job control (set automatically at shell startup, +if not mentioned on the command line, when interactive). .It Fl n Em noexec Read and parse commands, but do not execute them. This is useful for checking the syntax of shell scripts. @@ -1780,7 +1780,7 @@ the two arguments: Expands to the number of positional parameters. .It Dv \&? Expands to the exit status of the most recent pipeline. -.It Dv \- No (hyphen, or minus) +.It Dv \- No (dash, hyphen, or minus) Expands to the current option flags (the single-letter option names concatenated into a string) as specified on invocation, by the set built-in command, or implicitly
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Sep 16 17:32:18 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: Minor wording improvements. Note these do not alter anything about what the man page specifies, just say a couple of things in a slightly better way, hence no Dd update accompanies this change (deliberately). To generate a diff of this commit: cvs rdiff -u -r1.247 -r1.248 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Sep 16 17:29:21 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: Move a comment that used to be in the correct place, once upon a time, back where it belongs, and make it stand out more, so other text is less likely to find itself pushed between the comment and the text to which it appears. This change should make no visible difference to the man page displayed. To generate a diff of this commit: cvs rdiff -u -r1.246 -r1.247 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.246 src/bin/sh/sh.1:1.247 --- src/bin/sh/sh.1:1.246 Fri Sep 16 17:25:09 2022 +++ src/bin/sh/sh.1 Fri Sep 16 17:29:21 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.246 2022/09/16 17:25:09 kre Exp $ +.\" $NetBSD: sh.1,v 1.247 2022/09/16 17:29:21 kre Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -4798,7 +4798,6 @@ has not been set or unset. The default terminal setting for the shell. This is inherited by children of the shell, and is used in the history editing modes. -.\" This is explicitly last, not in sort order - please leave! .It Ev ToD When referenced, uses the value of .Ev ToD_FORMAT @@ -4834,6 +4833,9 @@ to use when formatting .Ev ToD and if exported, other utilities that deal with times. If unset, the system's local wall clock time zone is used. +.\" +.\" == +.\" This is explicitly last, not in sort order - please leave! .It Ev NETBSD_SHELL Unlike the variables previously mentioned, this variable is somewhat strange,
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Sep 16 17:29:21 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: Move a comment that used to be in the correct place, once upon a time, back where it belongs, and make it stand out more, so other text is less likely to find itself pushed between the comment and the text to which it appears. This change should make no visible difference to the man page displayed. To generate a diff of this commit: cvs rdiff -u -r1.246 -r1.247 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Sep 16 17:25:09 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: Whitespace. To generate a diff of this commit: cvs rdiff -u -r1.245 -r1.246 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Sep 16 17:25:09 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: Whitespace. To generate a diff of this commit: cvs rdiff -u -r1.245 -r1.246 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.245 src/bin/sh/sh.1:1.246 --- src/bin/sh/sh.1:1.245 Thu Sep 15 18:00:36 2022 +++ src/bin/sh/sh.1 Fri Sep 16 17:25:09 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.245 2022/09/15 18:00:36 kre Exp $ +.\" $NetBSD: sh.1,v 1.246 2022/09/16 17:25:09 kre Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -3191,7 +3191,7 @@ to set key bindings as defined by .Xr editrc 5 . .\" .Pp -.It Ic jobid Oo Fl g Ns \&| Ns Fl j Ns \&| Ns Fl p Oc Op Ar job +.It Ic jobid Oo Fl g Ns \&| Ns Fl j Ns \&| Ns Fl p Oc Op Ar job With no flags, print the process identifiers of the processes in the job. If the .Ar job @@ -3573,7 +3573,7 @@ If an unescaped backslash is followed by the backslash and the newline will be deleted, and replaced by the contents of the following line, which is processed as if it had been part of the original line. -This includes reading yet more input if necessary, +This includes reading yet more input if necessary, until a line is read that is not terminated by an unescaped backslash immediately before the newline. .\"
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Thu Sep 15 18:00:36 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: Correct spelling of terminal (it doesn't have a 2nd m). To generate a diff of this commit: cvs rdiff -u -r1.244 -r1.245 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Thu Sep 15 18:00:36 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: Correct spelling of terminal (it doesn't have a 2nd m). To generate a diff of this commit: cvs rdiff -u -r1.244 -r1.245 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.244 src/bin/sh/sh.1:1.245 --- src/bin/sh/sh.1:1.244 Fri Aug 19 13:37:03 2022 +++ src/bin/sh/sh.1 Thu Sep 15 18:00:36 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.244 2022/08/19 13:37:03 kre Exp $ +.\" $NetBSD: sh.1,v 1.245 2022/09/15 18:00:36 kre Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -392,7 +392,7 @@ or given at invocation of .Nm ) , and standard input and standard error refer to -terminmal type devices. +terminal type devices. .It Fl L Em local_lineno When set, before a function is defined, causes the variable
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Mon Aug 22 17:33:11 UTC 2022 Modified Files: src/bin/sh: histedit.c Log Message: Add debugging trace points for history and the editline interface. NFC for any normal shell (not compiled with debugging (sh DEBUG) enabled. We have had a defined debug mode for this for years, but since I have not often played in this arena, never used it. Until recently (relatively). This (or a small part of it) played a part in discovering the fc -e bug cause. I have had it in my tree a while now - recent changes kept causing merge conflicts (all because I hadn't bothered to commit this), so I think now is the time... To generate a diff of this commit: cvs rdiff -u -r1.64 -r1.65 src/bin/sh/histedit.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Mon Aug 22 17:33:11 UTC 2022 Modified Files: src/bin/sh: histedit.c Log Message: Add debugging trace points for history and the editline interface. NFC for any normal shell (not compiled with debugging (sh DEBUG) enabled. We have had a defined debug mode for this for years, but since I have not often played in this arena, never used it. Until recently (relatively). This (or a small part of it) played a part in discovering the fc -e bug cause. I have had it in my tree a while now - recent changes kept causing merge conflicts (all because I hadn't bothered to commit this), so I think now is the time... To generate a diff of this commit: cvs rdiff -u -r1.64 -r1.65 src/bin/sh/histedit.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.64 src/bin/sh/histedit.c:1.65 --- src/bin/sh/histedit.c:1.64 Sun Aug 21 21:35:36 2022 +++ src/bin/sh/histedit.c Mon Aug 22 17:33:11 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.c,v 1.64 2022/08/21 21:35:36 nia Exp $ */ +/* $NetBSD: histedit.c,v 1.65 2022/08/22 17:33:11 kre 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.64 2022/08/21 21:35:36 nia Exp $"); +__RCSID("$NetBSD: histedit.c,v 1.65 2022/08/22 17:33:11 kre Exp $"); #endif #endif /* not lint */ @@ -65,6 +65,7 @@ __RCSID("$NetBSD: histedit.c,v 1.64 2022 #ifndef SMALL #include "eval.h" #include "memalloc.h" +#include "show.h" #define MAXHISTLOOPS 4 /* max recursions through fc */ #define DEFEDITOR "ed" /* default editor *should* be $EDITOR */ @@ -97,6 +98,9 @@ histedit(void) #define editing (Eflag || Vflag) + CTRACE(DBG_HISTORY, ("histedit: %cE%cV %sinteractive\n", + Eflag ? '-' : '+', Vflag ? '-' : '+', iflag ? "" : "not ")); + if (iflag == 1) { if (!hist) { /* @@ -152,6 +156,8 @@ histedit(void) else unsetenv("TERM"); el = el_init("sh", el_in, el_out, el_err); + VTRACE(DBG_HISTORY, ("el_init() %sed\n", + el != NULL ? "succeed" : "fail")); if (el != NULL) { if (hist) el_set(el, EL_HIST, history, hist); @@ -172,6 +178,7 @@ bad: INTOFF; el_end(el); el = NULL; + VTRACE(DBG_HISTORY, ("line editing disabled\n")); INTON; } if (el) { @@ -180,6 +187,7 @@ bad: el_set(el, EL_EDITOR, "vi"); else if (Eflag) el_set(el, EL_EDITOR, "emacs"); + VTRACE(DBG_HISTORY, ("reading $EDITRC\n")); el_source(el, lookupvar("EDITRC")); el_set(el, EL_BIND, "^I", tabcomplete ? "rl-complete" : "ed-insert", NULL); @@ -196,6 +204,7 @@ bad: hist = NULL; } INTON; + VTRACE(DBG_HISTORY, ("line editing & history disabled\n")); } } @@ -263,10 +272,13 @@ setterm(const char *term) int inputrc(int argc, char **argv) { + CTRACE(DBG_HISTORY, ("inputrc (%d arg%s)", argc-1, argc==2?"":"s")); if (argc != 2) { + CTRACE(DBG_HISTORY, (" -- bad\n")); out2str("usage: inputrc file\n"); return 1; } + CTRACE(DBG_HISTORY, (" file: \"%s\"\n", argv[1])); if (el != NULL) { INTOFF; if (el_source(el, argv[1])) { @@ -310,6 +322,7 @@ histcmd(volatile int argc, char ** volat if (hist == NULL) error("history not active"); + CTRACE(DBG_HISTORY, ("histcmd (fc) %d arg%s\n", argc, argc==1?"":"s")); if (argc == 1) error("missing history argument"); @@ -319,18 +332,23 @@ histcmd(volatile int argc, char ** volat switch ((char)ch) { case 'e': editor = optarg; + VTRACE(DBG_HISTORY, ("histcmd -e %s\n", editor)); break; case 'l': lflg = 1; + VTRACE(DBG_HISTORY, ("histcmd -l\n")); break; case 'n': nflg = 1; + VTRACE(DBG_HISTORY, ("histcmd -n\n")); break; case 'r': rflg = 1; + VTRACE(DBG_HISTORY, ("histcmd -r\n")); break; case 's': sflg = 1; + VTRACE(DBG_HISTORY, ("histcmd -s\n")); break; case ':': error("option -%c expects argument", optopt); @@ -355,12 +373,17 @@ histcmd(volatile int argc, char ** volat savehandler = handler; if (setjmp(jmploc.loc)) { active = 0; - if (*editfile) + if (*editfile) { +VTRACE(DBG_HISTORY, +("histcmd err jump unlink temp \"%s\"\n", +*editfile)); unlink(editfile); + } handler = savehandler; longjmp(handler->loc, 1); } handler = + VTRACE(DBG_HISTORY, ("histcmd was active %d (++)\n", active)); if (++active > MAXHISTLOOPS) { active = 0; displayhist = 0; @@ -378,6 +401,8 @@ histcmd(volatile int argc, char ** volat sflg = 1; /* no edit */ editor = NULL; } + VTRACE(DBG_HISTORY, ("histcmd using %s as editor\n", + editor == NULL ? "-nothing-" : editor)); } } @@ -389,6 +414,8 @@ histcmd(volatile int argc, char ** volat pat = argv[0]; *repl++ = '\0'; argc--, argv++; + VTRACE(DBG_HISTORY, ("histcmd
CVS commit: src/bin/sh
Module Name:src Committed By: nia Date: Sun Aug 21 21:35:36 UTC 2022 Modified Files: src/bin/sh: histedit.c Log Message: sh(1): revert previous because it interferes with custom user bindings To generate a diff of this commit: cvs rdiff -u -r1.63 -r1.64 src/bin/sh/histedit.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.63 src/bin/sh/histedit.c:1.64 --- src/bin/sh/histedit.c:1.63 Thu Aug 18 14:10:05 2022 +++ src/bin/sh/histedit.c Sun Aug 21 21:35:36 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.c,v 1.63 2022/08/18 14:10:05 nia Exp $ */ +/* $NetBSD: histedit.c,v 1.64 2022/08/21 21:35:36 nia 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.63 2022/08/18 14:10:05 nia Exp $"); +__RCSID("$NetBSD: histedit.c,v 1.64 2022/08/21 21:35:36 nia Exp $"); #endif #endif /* not lint */ @@ -176,11 +176,11 @@ bad: } if (el) { INTOFF; - el_source(el, lookupvar("EDITRC")); if (Vflag) el_set(el, EL_EDITOR, "vi"); else if (Eflag) el_set(el, EL_EDITOR, "emacs"); + el_source(el, lookupvar("EDITRC")); el_set(el, EL_BIND, "^I", tabcomplete ? "rl-complete" : "ed-insert", NULL); INTON;
CVS commit: src/bin/sh
Module Name:src Committed By: nia Date: Sun Aug 21 21:35:36 UTC 2022 Modified Files: src/bin/sh: histedit.c Log Message: sh(1): revert previous because it interferes with custom user bindings To generate a diff of this commit: cvs rdiff -u -r1.63 -r1.64 src/bin/sh/histedit.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Re: CVS commit: src/bin/sh
Date:Fri, 19 Aug 2022 15:37:59 + From:nia Message-ID: | I wish editing mode and whether editing was enabled was more clearly | divorced. That might be arranged, I will take a look and see what would be involved (the major issue is making sure things get updated properly when the user switches preferred editors - like if one is set as default in some startup file, and the user then overrides that in another). If things were to change such that most editing on/off decisions were made by a separate option than emacs/vi mode, that issue would need watching to make sure it is not forgotten/ignored. And wrt: | it "feels right" that runtime commands take precedence over config files. If it was the user manually typing "set -o vi" then yes, I'd agree that generally that should probably take precedence. But it almost never is, those commands are almost always in a "config file" (like .profile or .shrc or whatever the user wants to call the file in $ENV if they have one). So what we really have, most of the time, is competing config files, and and given the brutal nature of what set -o editor does, compared to the more nuanced (at least, can be) EDITRC file, in this instance I think I'd have EDITRC override the option's setup - apart from anything else, that's how it has always been, and people are more likely to have a setup which expects that, than the other way. What might be possible however, is to have a change (or enabling, perhaps) of editing mode, after the shell has issued its first prompt (ie: when it is reading from the terminal - we know it is the terminal since none of this stuff applies in any case other than an interactive shell reading from a tty) have the shell only do the EL_SET "editor" command and not process EDITRC again at all (if editing was enabled in a startup file, that will have already been read, before the first prompt). If the user after manually choosing their editor of choice, wants their .editrc file processed again, they can use the inputrc built in to read an editline config file of their choice (like "inputrc $EDITRC" perhaps), or simply assign a new value to EDITRC (like EDITRC=$EDITRC). Either of those will cause the file to be processed. This ought to be relatively easy to implement, if it is conssidered a worthwhile enhancement (none of this affects me one way or the other, I set vi mode before the prompt, and cetainly never change it again, and I don't use a .editrc file (setting vi command maps, and everything else the default works for me -- I don't use tabcomplete). kre
Re: CVS commit: src/bin/sh
On Fri, Aug 19, 2022 at 04:15:52AM +0700, Robert Elz wrote: > The effect of "set -o editor" (for whichever editor it uses), that > is when the shell does: el_set(el, EL_EDITOR, editor); is to essentially > set up all the key bindings so they match what that editor expects them > to be. Doing that after having processed .editrc seems backwards to me, > as whatever that file did (at least for key bindings) is going to be lost. This makes sense. I have been mulling over whether NetBSD should install an ~/.editrc file by default, and in this case it "feels right" that runtime commands take precedence over config files. However, there's some non-trivial ways this can go wrong, including your example. I wish editing mode and whether editing was enabled was more clearly divorced.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Aug 19 13:37:03 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: Improve the description of the read builtin command. To generate a diff of this commit: cvs rdiff -u -r1.243 -r1.244 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.243 src/bin/sh/sh.1:1.244 --- src/bin/sh/sh.1:1.243 Fri Jan 7 05:30:30 2022 +++ src/bin/sh/sh.1 Fri Aug 19 13:37:03 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.243 2022/01/07 05:30:30 lukem Exp $ +.\" $NetBSD: sh.1,v 1.244 2022/08/19 13:37:03 kre Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -3537,23 +3537,29 @@ and the built-in uses a separately cache .It Ic read Oo Fl p Ar prompt Oc Oo Fl r Oc Ar variable Op Ar ... The .Ar prompt -is printed if the +is printed on standard error if the .Fl p option is specified and the standard input is a terminal. Then a line is read from the standard input. The trailing newline is deleted from the line and the line is split as described in the field splitting section of the .Sx Word Expansions -section above, and the pieces are assigned to the variables in order. -If there are more pieces than variables, the remaining pieces +section above. +The pieces are assigned to the +.Ar variable Ns s +in order. +If there are more pieces than variables, +the remaining pieces (along with the characters in .Ev IFS -that separated them) are assigned to the last variable. +that separated them) are all assigned to the last +.Ar variable . If there are more variables than pieces, the remaining variables are assigned the null string. The .Ic read -built-in will indicate success unless EOF is encountered on input, in +built-in will indicate success unless EOF, or a read error, +is encountered on input, in which case failure is returned. .Pp By default, unless the @@ -3562,8 +3568,14 @@ option is specified, the backslash .Dq \e acts as an escape character, causing the following character to be treated literally. -If a backslash is followed by a newline, the backslash and the -newline will be deleted. +This is the only form of quoting that applies. +If an unescaped backslash is followed by a newline, +the backslash and the newline will be deleted, +and replaced by the contents of the following line, +which is processed as if it had been part of the original line. +This includes reading yet more input if necessary, +until a line is read that is not terminated by +an unescaped backslash immediately before the newline. .\" .Pp .It Ic readonly Ar name Ns Oo =value Oc ...
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Aug 19 13:37:03 UTC 2022 Modified Files: src/bin/sh: sh.1 Log Message: Improve the description of the read builtin command. To generate a diff of this commit: cvs rdiff -u -r1.243 -r1.244 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Aug 19 12:52:32 UTC 2022 Modified Files: src/bin/sh: miscbltin.c Log Message: Don't output the error for bad usage (no var name given) after already writing the prompt (set with the -p option). That results in nonsense like: $ read -p foo fooread: arg count While here, improve the error message so it means something. Now we will get: $ read -p foo read: variable name required Usage: read [-r] [-p prompt] var... [Detected by code reading while doing the work for the previous fix] To generate a diff of this commit: cvs rdiff -u -r1.51 -r1.52 src/bin/sh/miscbltin.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Aug 19 12:52:32 UTC 2022 Modified Files: src/bin/sh: miscbltin.c Log Message: Don't output the error for bad usage (no var name given) after already writing the prompt (set with the -p option). That results in nonsense like: $ read -p foo fooread: arg count While here, improve the error message so it means something. Now we will get: $ read -p foo read: variable name required Usage: read [-r] [-p prompt] var... [Detected by code reading while doing the work for the previous fix] To generate a diff of this commit: cvs rdiff -u -r1.51 -r1.52 src/bin/sh/miscbltin.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/miscbltin.c diff -u src/bin/sh/miscbltin.c:1.51 src/bin/sh/miscbltin.c:1.52 --- src/bin/sh/miscbltin.c:1.51 Fri Aug 19 12:17:18 2022 +++ src/bin/sh/miscbltin.c Fri Aug 19 12:52:31 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: miscbltin.c,v 1.51 2022/08/19 12:17:18 kre Exp $ */ +/* $NetBSD: miscbltin.c,v 1.52 2022/08/19 12:52:31 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)miscbltin.c 8.4 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: miscbltin.c,v 1.51 2022/08/19 12:17:18 kre Exp $"); +__RCSID("$NetBSD: miscbltin.c,v 1.52 2022/08/19 12:52:31 kre Exp $"); #endif #endif /* not lint */ @@ -111,14 +111,15 @@ readcmd(int argc, char **argv) rflag = 1; } + if (*(ap = argptr) == NULL) + error("variable name required\n" + "Usage: read [-r] [-p prompt] var..."); + if (prompt && isatty(0)) { out2str(prompt); flushall(); } - if (*(ap = argptr) == NULL) - error("arg count"); - if ((ifs = bltinlookup("IFS", 1)) == NULL) ifs = " \t\n";
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Aug 19 12:17:18 UTC 2022 Modified Files: src/bin/sh: miscbltin.c Log Message: PR bin/56972 Fix escape ('\') handling in sh read builtin. In 1.35 (March 2005) (the big read fixup), most escape handling and IFS processing in the read builtin was corrected. However 2 cases were missed, one is a word (something to be assigned to any variable but the last) in which every character is escaped (the code was relying on a non-escaped char to set the "in a word" status), and second trailing IFS whitespace at the end of the line was being deleted, even if the chars had been escaped (the escape chars are no longer present). See the PR for more details (including the case that detected the problem). After fixing this, I looked at the FreeBSD code (normally might do it before, but these fixes were trivial) to check their implementation. Their code does similar things to ours now does, but in a completely different way, their read builtin is more complex than ours needs to be (they handle more options). For anyone tempted to simply incorporate their code, note that it relies upon infrastructure changes elsewhere in the shell, so would not be a simple cut and drop in exercise. This needs pullups to -3 -4 -5 -6 -7 -8 and -9 (fortunately this is happening before -10 is branched, so will never be broken this way there). To generate a diff of this commit: cvs rdiff -u -r1.50 -r1.51 src/bin/sh/miscbltin.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Fri Aug 19 12:17:18 UTC 2022 Modified Files: src/bin/sh: miscbltin.c Log Message: PR bin/56972 Fix escape ('\') handling in sh read builtin. In 1.35 (March 2005) (the big read fixup), most escape handling and IFS processing in the read builtin was corrected. However 2 cases were missed, one is a word (something to be assigned to any variable but the last) in which every character is escaped (the code was relying on a non-escaped char to set the "in a word" status), and second trailing IFS whitespace at the end of the line was being deleted, even if the chars had been escaped (the escape chars are no longer present). See the PR for more details (including the case that detected the problem). After fixing this, I looked at the FreeBSD code (normally might do it before, but these fixes were trivial) to check their implementation. Their code does similar things to ours now does, but in a completely different way, their read builtin is more complex than ours needs to be (they handle more options). For anyone tempted to simply incorporate their code, note that it relies upon infrastructure changes elsewhere in the shell, so would not be a simple cut and drop in exercise. This needs pullups to -3 -4 -5 -6 -7 -8 and -9 (fortunately this is happening before -10 is branched, so will never be broken this way there). To generate a diff of this commit: cvs rdiff -u -r1.50 -r1.51 src/bin/sh/miscbltin.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/miscbltin.c diff -u src/bin/sh/miscbltin.c:1.50 src/bin/sh/miscbltin.c:1.51 --- src/bin/sh/miscbltin.c:1.50 Sat Apr 16 14:26:26 2022 +++ src/bin/sh/miscbltin.c Fri Aug 19 12:17:18 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: miscbltin.c,v 1.50 2022/04/16 14:26:26 kre Exp $ */ +/* $NetBSD: miscbltin.c,v 1.51 2022/08/19 12:17:18 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)miscbltin.c 8.4 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: miscbltin.c,v 1.50 2022/04/16 14:26:26 kre Exp $"); +__RCSID("$NetBSD: miscbltin.c,v 1.51 2022/08/19 12:17:18 kre Exp $"); #endif #endif /* not lint */ @@ -100,6 +100,7 @@ readcmd(int argc, char **argv) int i; int is_ifs; int saveall = 0; + ptrdiff_t wordlen = 0; rflag = 0; prompt = NULL; @@ -137,7 +138,7 @@ readcmd(int argc, char **argv) break; } if (c != '\n') -STPUTC(c, p); +goto wdch; continue; } if (c == '\n') @@ -164,12 +165,14 @@ readcmd(int argc, char **argv) } if (is_ifs == 0) { + wdch:; /* append this character to the current variable */ startword = 0; if (saveall) /* Not just a spare terminator */ saveall++; STPUTC(c, p); + wordlen = p - stackblock(); continue; } @@ -187,11 +190,12 @@ readcmd(int argc, char **argv) setvar(*ap, stackblock(), 0); ap++; STARTSTACKSTR(p); + wordlen = 0; } STACKSTRNUL(p); /* Remove trailing IFS chars */ - for (; stackblock() <= --p; *p = 0) { + for (; stackblock() + wordlen <= --p; *p = 0) { if (!strchr(ifs, *p)) break; if (strchr(" \t\n", *p))
Re: CVS commit: src/bin/sh
Date:Thu, 18 Aug 2022 14:10:05 + From:"Nia Alarie" Message-ID: <20220818141005.5005af...@cvs.netbsd.org> | sh(1): Allow an explicit set -o vi or set -o emacs to override ~/.editrc I'm not sure that change is a good idea - but it depends how you view the .editrc file. The effect of "set -o editor" (for whichever editor it uses), that is when the shell does: el_set(el, EL_EDITOR, editor); is to essentially set up all the key bindings so they match what that editor expects them to be. Doing that after having processed .editrc seems backwards to me, as whatever that file did (at least for key bindings) is going to be lost. I'd have expected that normally the idea would be to set the key bindings for the editor of choice, and then use .editrc to override any that the user wants to alter. (editline (libedit) (and readline for that matter) don't actually implement emacs or vi (duh!) what they do is provide a whole set of functions that perform editing micro-actions on a line buffer, and allow key bindings to invoke those functions. The functions provided implement the ability to edit text, using operations that perform similarly to vi or emacs commands. Setting vi or emacs mode simply sets all the key bindings so that the keys act like they would when editing using the corresponding editor. But the user is free to mix and match to create an environment that is even better (for this task, where many editing operations that a full editor needs to provide make no sense), so a vi mode user can bind ^A to "go to beginning of line" in insert mode if they want, just like happens with emacs editing, rather than "insert a control-A" which would be normal in vi, while otherwise having the command line editor act like vi. That won't work if what .editrc is overridden by the el_set(EL_EDITOR) operation. The commands that can go in .editrc which don't affect the key bindings (like setting the history size) should be unaffected by the order these two steps are performed. kre
CVS commit: src/bin/sh
Module Name:src Committed By: nia Date: Thu Aug 18 14:10:05 UTC 2022 Modified Files: src/bin/sh: histedit.c Log Message: sh(1): Allow an explicit set -o vi or set -o emacs to override ~/.editrc To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 src/bin/sh/histedit.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.62 src/bin/sh/histedit.c:1.63 --- src/bin/sh/histedit.c:1.62 Wed Aug 17 22:27:17 2022 +++ src/bin/sh/histedit.c Thu Aug 18 14:10:05 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.c,v 1.62 2022/08/17 22:27:17 nia Exp $ */ +/* $NetBSD: histedit.c,v 1.63 2022/08/18 14:10:05 nia 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.62 2022/08/17 22:27:17 nia Exp $"); +__RCSID("$NetBSD: histedit.c,v 1.63 2022/08/18 14:10:05 nia Exp $"); #endif #endif /* not lint */ @@ -176,11 +176,11 @@ bad: } if (el) { INTOFF; + el_source(el, lookupvar("EDITRC")); if (Vflag) el_set(el, EL_EDITOR, "vi"); else if (Eflag) el_set(el, EL_EDITOR, "emacs"); - el_source(el, lookupvar("EDITRC")); el_set(el, EL_BIND, "^I", tabcomplete ? "rl-complete" : "ed-insert", NULL); INTON;
CVS commit: src/bin/sh
Module Name:src Committed By: nia Date: Thu Aug 18 14:10:05 UTC 2022 Modified Files: src/bin/sh: histedit.c Log Message: sh(1): Allow an explicit set -o vi or set -o emacs to override ~/.editrc To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 src/bin/sh/histedit.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: nia Date: Wed Aug 17 22:27:17 UTC 2022 Modified Files: src/bin/sh: histedit.c Log Message: sh(1): Assign the tab completion key binding last so a user having "bind -v" or "bind -e" in ~/.editrc doesn't cause tab completion to no longer function. To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 src/bin/sh/histedit.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: nia Date: Wed Aug 17 22:27:17 UTC 2022 Modified Files: src/bin/sh: histedit.c Log Message: sh(1): Assign the tab completion key binding last so a user having "bind -v" or "bind -e" in ~/.editrc doesn't cause tab completion to no longer function. To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 src/bin/sh/histedit.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.61 src/bin/sh/histedit.c:1.62 --- src/bin/sh/histedit.c:1.61 Tue Feb 8 20:39:59 2022 +++ src/bin/sh/histedit.c Wed Aug 17 22:27:17 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.c,v 1.61 2022/02/08 20:39:59 rillig Exp $ */ +/* $NetBSD: histedit.c,v 1.62 2022/08/17 22:27:17 nia 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.61 2022/02/08 20:39:59 rillig Exp $"); +__RCSID("$NetBSD: histedit.c,v 1.62 2022/08/17 22:27:17 nia Exp $"); #endif #endif /* not lint */ @@ -180,9 +180,9 @@ bad: el_set(el, EL_EDITOR, "vi"); else if (Eflag) el_set(el, EL_EDITOR, "emacs"); + el_source(el, lookupvar("EDITRC")); el_set(el, EL_BIND, "^I", tabcomplete ? "rl-complete" : "ed-insert", NULL); - el_source(el, lookupvar("EDITRC")); INTON; } } else {
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Mon Apr 18 06:02:27 UTC 2022 Modified Files: src/bin/sh: jobs.c Log Message: Introduce a new macro JNUM to replace the idiom jp-jobtab+1 (the job number, given jp a pointer to a jobs table entry) used open coded previously in many places (mostly in DEBUG mode trace messages, so not included in most shells, but there are a few others). Make the type of JNUM() be int rather than the ptrdiff_t the open coded version became ... which when used in some printf() type function arg list was cast to some other arbitrary (but not consistent) int type for which there is a standard %Xd type format conversion. Now we can (and do) just use %d for this. If the number of jobs ever exceeds the range of an int, we would have far more serious problems than the broken output this would cause. While here improve a comment or two, and use JOBRUNNING instead of 0 where the intent is the former (JOBRUNNING is #defined as 0). NFCI. To generate a diff of this commit: cvs rdiff -u -r1.115 -r1.116 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.115 src/bin/sh/jobs.c:1.116 --- src/bin/sh/jobs.c:1.115 Sun Dec 19 21:15:27 2021 +++ src/bin/sh/jobs.c Mon Apr 18 06:02:27 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: jobs.c,v 1.115 2021/12/19 21:15:27 andvar Exp $ */ +/* $NetBSD: jobs.c,v 1.116 2022/04/18 06:02:27 kre 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.115 2021/12/19 21:15:27 andvar Exp $"); +__RCSID("$NetBSD: jobs.c,v 1.116 2022/04/18 06:02:27 kre Exp $"); #endif #endif /* not lint */ @@ -116,6 +116,8 @@ STATIC void cmdlist(union node *, int); STATIC void cmdputs(const char *); inline static void cmdputi(int); +#define JNUM(j) ((int)((j) != NULL ? ((j) - jobtab) + 1 : 0)) + #ifdef SYSV STATIC int onsigchild(void); #endif @@ -355,7 +357,7 @@ bgcmd(int argc, char **argv) if (jp->jobctl == 0) error("job not created under job control"); set_curjob(jp, 1); - out1fmt("[%ld] %s", (long)(jp - jobtab + 1), jp->ps[0].cmd); + out1fmt("[%d] %s", JNUM(jp), jp->ps[0].cmd); for (i = 1; i < jp->nprocs; i++) out1fmt(" | %s", jp->ps[i].cmd ); out1c('\n'); @@ -403,9 +405,9 @@ restartjob(struct job *jp) for (ps = jp->ps, i = jp->nprocs ; --i >= 0 ; ps++) { if (WIFSTOPPED(ps->status)) { VTRACE(DBG_JOBS, ( - "restartjob: [%zu] pid %d status change" + "restartjob: [%d] pid %d status change" " from %#x (stopped) to -1 (running)\n", - (size_t)(jp-jobtab+1), ps->pid, ps->status)); + JNUM(jp), ps->pid, ps->status)); ps->status = -1; jp->state = JOBRUNNING; } @@ -470,7 +472,7 @@ showjob(struct output *out, struct job * if (mode & SHOW_SIGNALLED && !(mode & SHOW_ISSIG)) { if (jp->state == JOBDONE && !(mode & SHOW_NO_FREE)) { VTRACE(DBG_JOBS, ("showjob: freeing job %d\n", - jp - jobtab + 1)); + JNUM(jp))); freejob(jp); } return; @@ -478,8 +480,8 @@ showjob(struct output *out, struct job * for (ps = jp->ps; --procno >= 0; ps++) { /* for each process */ if (ps == jp->ps) - fmtstr(s, 16, "[%ld] %c ", -(long)(jp - jobtab + 1), + fmtstr(s, 16, "[%d] %c ", +JNUM(jp), #if JOBS jp - jobtab == curjob ? '+' : @@ -948,7 +950,7 @@ jobidcmd(int argc, char **argv) jp = getjob(*argptr, 0); if (job) { - out1fmt("%%%zu\n", (size_t)(jp - jobtab + 1)); + out1fmt("%%%d\n", JNUM(jp)); return 0; } if (pg) { @@ -1157,7 +1159,7 @@ makejob(union node *node, int nprocs) } INTON; VTRACE(DBG_JOBS, ("makejob(%p, %d)%s returns %%%d\n", (void *)node, - nprocs, (jp->flags)?" PF":"", jp - jobtab + 1)); + nprocs, (jp->flags & JPIPEFAIL) ? " PF" : "", JNUM(jp))); return jp; } @@ -1184,7 +1186,7 @@ forkshell(struct job *jp, union node *n, int serrno; CTRACE(DBG_JOBS, ("forkshell(%%%d, %p, %d) called\n", - jp - jobtab, n, mode)); + JNUM(jp), n, mode)); switch ((pid = fork())) { case -1: @@ -1326,7 +1328,7 @@ waitforjob(struct job *jp) int st; INTOFF; - VTRACE(DBG_JOBS, ("waitforjob(%%%d) called\n", jp - jobtab + 1)); + VTRACE(DBG_JOBS, ("waitforjob(%%%d) called\n", JNUM(jp))); while (jp->state == JOBRUNNING) { dowait(WBLOCK, jp, NULL); } @@ -1352,7 +1354,7 @@ waitforjob(struct job *jp) st = WTERMSIG(status) + 128; VTRACE(DBG_JOBS, ("waitforjob: job %d, nproc %d, status %d, st %x\n", - jp - jobtab + 1, jp->nprocs, status, st)); + JNUM(jp), jp->nprocs, status, st)); #if JOBS if (jp->jobctl) { /* @@ -1402,7 +1404,7 @@ dowait(int flags, struct job *job, struc int err; VTRACE(DBG_JOBS|DBG_PROCS, ("dowait(%x) called for job %d%s\n", - flags, (job ? job-jobtab+1 : 0), changed ? " [report change]":"")); + flags, JNUM(job), changed ?
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Mon Apr 18 06:02:27 UTC 2022 Modified Files: src/bin/sh: jobs.c Log Message: Introduce a new macro JNUM to replace the idiom jp-jobtab+1 (the job number, given jp a pointer to a jobs table entry) used open coded previously in many places (mostly in DEBUG mode trace messages, so not included in most shells, but there are a few others). Make the type of JNUM() be int rather than the ptrdiff_t the open coded version became ... which when used in some printf() type function arg list was cast to some other arbitrary (but not consistent) int type for which there is a standard %Xd type format conversion. Now we can (and do) just use %d for this. If the number of jobs ever exceeds the range of an int, we would have far more serious problems than the broken output this would cause. While here improve a comment or two, and use JOBRUNNING instead of 0 where the intent is the former (JOBRUNNING is #defined as 0). NFCI. To generate a diff of this commit: cvs rdiff -u -r1.115 -r1.116 src/bin/sh/jobs.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sat Apr 16 14:26:26 UTC 2022 Modified Files: src/bin/sh: miscbltin.c Log Message: Redo the way the builtin cmd 'ulimit' getopt() (nextopt() really, but it is essentially the same) arg string is generated, to lessen the chances that the table of limits, and the arg string that allows limits to be reported or set will get out of sync. They weren't (as long as we didn't grow an RLIMIT_SWAP) this is just tidier. While here, reorder the limits table fields, and shrink a couple that were needlessly wasteful, to save some space -- for most architectures this should save 8 bytes per table entry (there are currently 13). (Some minor code bloat offsets this slightly because of int type promotions now required). NFCI. To generate a diff of this commit: cvs rdiff -u -r1.49 -r1.50 src/bin/sh/miscbltin.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/miscbltin.c diff -u src/bin/sh/miscbltin.c:1.49 src/bin/sh/miscbltin.c:1.50 --- src/bin/sh/miscbltin.c:1.49 Sat Apr 16 14:23:36 2022 +++ src/bin/sh/miscbltin.c Sat Apr 16 14:26:26 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: miscbltin.c,v 1.49 2022/04/16 14:23:36 kre Exp $ */ +/* $NetBSD: miscbltin.c,v 1.50 2022/04/16 14:26:26 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)miscbltin.c 8.4 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: miscbltin.c,v 1.49 2022/04/16 14:23:36 kre Exp $"); +__RCSID("$NetBSD: miscbltin.c,v 1.50 2022/04/16 14:26:26 kre Exp $"); #endif #endif /* not lint */ @@ -316,53 +316,95 @@ umaskcmd(int argc, char **argv) struct limits { const char *name; const char *unit; - int cmd; - int factor; /* multiply by to get rlim_{cur,max} values */ char option; + int8_t cmd; /* all RLIMIT_xxx are <= 127 */ + unsigned short factor; /* multiply by to get rlim_{cur,max} values */ }; +#define OPTSTRING_BASE "HSa" + static const struct limits limits[] = { #ifdef RLIMIT_CPU - { "time", "seconds", RLIMIT_CPU, 1, 't' }, + { "time", "seconds", 't', RLIMIT_CPU, 1 }, +#define OPTSTRING_t OPTSTRING_BASE "t" +#else +#define OPTSTRING_t OPTSTRING_BASE #endif #ifdef RLIMIT_FSIZE - { "file", "blocks", RLIMIT_FSIZE, 512, 'f' }, + { "file", "blocks", 'f', RLIMIT_FSIZE, 512 }, +#define OPTSTRING_f OPTSTRING_t "f" +#else +#define OPTSTRING_f OPTSTRING_t #endif #ifdef RLIMIT_DATA - { "data", "kbytes", RLIMIT_DATA, 1024, 'd' }, + { "data", "kbytes", 'd', RLIMIT_DATA, 1024 }, +#define OPTSTRING_d OPTSTRING_f "d" +#else +#define OPTSTRING_d OPTSTRING_f #endif #ifdef RLIMIT_STACK - { "stack", "kbytes", RLIMIT_STACK, 1024, 's' }, + { "stack", "kbytes", 's', RLIMIT_STACK, 1024 }, +#define OPTSTRING_s OPTSTRING_d "s" +#else +#define OPTSTRING_s OPTSTRING_d #endif #ifdef RLIMIT_CORE - { "coredump", "blocks", RLIMIT_CORE, 512, 'c' }, + { "coredump", "blocks", 'c', RLIMIT_CORE, 512 }, +#define OPTSTRING_c OPTSTRING_s "c" +#else +#define OPTSTRING_c OPTSTRING_s #endif #ifdef RLIMIT_RSS - { "memory", "kbytes", RLIMIT_RSS, 1024, 'm' }, + { "memory", "kbytes", 'm', RLIMIT_RSS, 1024 }, +#define OPTSTRING_m OPTSTRING_c "m" +#else +#define OPTSTRING_m OPTSTRING_c #endif #ifdef RLIMIT_MEMLOCK - { "locked memory","kbytes", RLIMIT_MEMLOCK, 1024, 'l' }, + { "locked memory","kbytes", 'l', RLIMIT_MEMLOCK, 1024 }, +#define OPTSTRING_l OPTSTRING_m "l" +#else +#define OPTSTRING_l OPTSTRING_m #endif #ifdef RLIMIT_NTHR - { "thread", "threads", RLIMIT_NTHR, 1, 'r' }, + { "thread", "threads", 'r', RLIMIT_NTHR, 1 }, +#define OPTSTRING_r OPTSTRING_l "r" +#else +#define OPTSTRING_r OPTSTRING_l #endif #ifdef RLIMIT_NPROC - { "process", "processes", RLIMIT_NPROC, 1, 'p' }, + { "process", "processes", 'p', RLIMIT_NPROC, 1 }, +#define OPTSTRING_p OPTSTRING_r "p" +#else +#define OPTSTRING_p OPTSTRING_r #endif #ifdef RLIMIT_NOFILE - { "nofiles", "descriptors", RLIMIT_NOFILE, 1, 'n' }, + { "nofiles", "descriptors", 'n', RLIMIT_NOFILE, 1 }, +#define OPTSTRING_n OPTSTRING_p "n" +#else +#define OPTSTRING_n OPTSTRING_p #endif #ifdef RLIMIT_VMEM - { "vmemory", "kbytes", RLIMIT_VMEM, 1024, 'v' }, + { "vmemory", "kbytes", 'v', RLIMIT_VMEM, 1024 }, +#define OPTSTRING_v OPTSTRING_n "v" +#else +#define OPTSTRING_v OPTSTRING_n #endif #ifdef RLIMIT_SWAP - { "swap", "kbytes", RLIMIT_SWAP, 1024, 'w' }, + { "swap", "kbytes", 'w', RLIMIT_SWAP, 1024 }, +#define OPTSTRING_w OPTSTRING_v "w" +#else +#define OPTSTRING_w OPTSTRING_v #endif #ifdef RLIMIT_SBSIZE - { "sbsize", "bytes", RLIMIT_SBSIZE, 1, 'b' }, + { "sbsize", "bytes", 'b', RLIMIT_SBSIZE, 1 }, +#define OPTSTRING_b OPTSTRING_w "b" +#else +#define OPTSTRING_b OPTSTRING_w #endif - { NULL, NULL, 0, 0, '\0' } + { NULL, NULL, '\0', 0, 0 } }; +#define OPTSTRING OPTSTRING_b int ulimitcmd(int argc, char **argv) @@ -377,7 +419,7 @@ ulimitcmd(int argc, char **argv) struct
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sat Apr 16 14:26:26 UTC 2022 Modified Files: src/bin/sh: miscbltin.c Log Message: Redo the way the builtin cmd 'ulimit' getopt() (nextopt() really, but it is essentially the same) arg string is generated, to lessen the chances that the table of limits, and the arg string that allows limits to be reported or set will get out of sync. They weren't (as long as we didn't grow an RLIMIT_SWAP) this is just tidier. While here, reorder the limits table fields, and shrink a couple that were needlessly wasteful, to save some space -- for most architectures this should save 8 bytes per table entry (there are currently 13). (Some minor code bloat offsets this slightly because of int type promotions now required). NFCI. To generate a diff of this commit: cvs rdiff -u -r1.49 -r1.50 src/bin/sh/miscbltin.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sat Apr 16 14:23:36 UTC 2022 Modified Files: src/bin/sh: miscbltin.c Log Message: While doing the previous change, I noticed that when used in a particularly perverse way, the error message for a bad octal constant as the new umask value could incorrectly claim that the -S option (which would need to be present to cause this issue) was the detected bad value. Fix that to report the actual incorrect arg. And while fiddling, also check for args to umask that are too big to be sane mask values (the biggest permitted is 0) and use mode_t as the mask variable type, rather than int. To generate a diff of this commit: cvs rdiff -u -r1.48 -r1.49 src/bin/sh/miscbltin.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/miscbltin.c diff -u src/bin/sh/miscbltin.c:1.48 src/bin/sh/miscbltin.c:1.49 --- src/bin/sh/miscbltin.c:1.48 Sat Apr 16 14:20:45 2022 +++ src/bin/sh/miscbltin.c Sat Apr 16 14:23:36 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: miscbltin.c,v 1.48 2022/04/16 14:20:45 kre Exp $ */ +/* $NetBSD: miscbltin.c,v 1.49 2022/04/16 14:23:36 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)miscbltin.c 8.4 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: miscbltin.c,v 1.48 2022/04/16 14:20:45 kre Exp $"); +__RCSID("$NetBSD: miscbltin.c,v 1.49 2022/04/16 14:23:36 kre Exp $"); #endif #endif /* not lint */ @@ -215,7 +215,7 @@ int umaskcmd(int argc, char **argv) { char *ap; - int mask; + mode_t mask; int i; int symbolic_mode = 0; @@ -265,13 +265,19 @@ umaskcmd(int argc, char **argv) } } else { if (isdigit((unsigned char)*ap)) { + int range = 0; + mask = 0; do { if (*ap >= '8' || *ap < '0') error("Not a valid octal number: '%s'", - argv[1]); + *argptr); mask = (mask << 3) + (*ap - '0'); +if (mask & ~0) + range = 1; } while (*++ap != '\0'); + if (range) + error("Mask constant '%s' out of range", *argptr); umask(mask); } else { void *set;
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sat Apr 16 14:23:36 UTC 2022 Modified Files: src/bin/sh: miscbltin.c Log Message: While doing the previous change, I noticed that when used in a particularly perverse way, the error message for a bad octal constant as the new umask value could incorrectly claim that the -S option (which would need to be present to cause this issue) was the detected bad value. Fix that to report the actual incorrect arg. And while fiddling, also check for args to umask that are too big to be sane mask values (the biggest permitted is 0) and use mode_t as the mask variable type, rather than int. To generate a diff of this commit: cvs rdiff -u -r1.48 -r1.49 src/bin/sh/miscbltin.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sat Apr 16 14:20:45 UTC 2022 Modified Files: src/bin/sh: miscbltin.c mystring.c options.c parser.c Log Message: Avoid generating error messages implying that user errors are illegal. To generate a diff of this commit: cvs rdiff -u -r1.47 -r1.48 src/bin/sh/miscbltin.c cvs rdiff -u -r1.18 -r1.19 src/bin/sh/mystring.c cvs rdiff -u -r1.56 -r1.57 src/bin/sh/options.c cvs rdiff -u -r1.177 -r1.178 src/bin/sh/parser.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Sat Apr 16 14:20:45 UTC 2022 Modified Files: src/bin/sh: miscbltin.c mystring.c options.c parser.c Log Message: Avoid generating error messages implying that user errors are illegal. To generate a diff of this commit: cvs rdiff -u -r1.47 -r1.48 src/bin/sh/miscbltin.c cvs rdiff -u -r1.18 -r1.19 src/bin/sh/mystring.c cvs rdiff -u -r1.56 -r1.57 src/bin/sh/options.c cvs rdiff -u -r1.177 -r1.178 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/miscbltin.c diff -u src/bin/sh/miscbltin.c:1.47 src/bin/sh/miscbltin.c:1.48 --- src/bin/sh/miscbltin.c:1.47 Sun Dec 12 11:18:46 2021 +++ src/bin/sh/miscbltin.c Sat Apr 16 14:20:45 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: miscbltin.c,v 1.47 2021/12/12 11:18:46 andvar Exp $ */ +/* $NetBSD: miscbltin.c,v 1.48 2022/04/16 14:20:45 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)miscbltin.c 8.4 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: miscbltin.c,v 1.47 2021/12/12 11:18:46 andvar Exp $"); +__RCSID("$NetBSD: miscbltin.c,v 1.48 2022/04/16 14:20:45 kre Exp $"); #endif #endif /* not lint */ @@ -268,7 +268,8 @@ umaskcmd(int argc, char **argv) mask = 0; do { if (*ap >= '8' || *ap < '0') - error("Illegal number: %s", argv[1]); + error("Not a valid octal number: '%s'", + argv[1]); mask = (mask << 3) + (*ap - '0'); } while (*++ap != '\0'); umask(mask); Index: src/bin/sh/mystring.c diff -u src/bin/sh/mystring.c:1.18 src/bin/sh/mystring.c:1.19 --- src/bin/sh/mystring.c:1.18 Fri Jul 13 22:43:44 2018 +++ src/bin/sh/mystring.c Sat Apr 16 14:20:45 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: mystring.c,v 1.18 2018/07/13 22:43:44 kre Exp $ */ +/* $NetBSD: mystring.c,v 1.19 2022/04/16 14:20:45 kre 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.18 2018/07/13 22:43:44 kre Exp $"); +__RCSID("$NetBSD: mystring.c,v 1.19 2022/04/16 14:20:45 kre Exp $"); #endif #endif /* not lint */ @@ -117,7 +117,7 @@ number(const char *s) if (!is_digit(*s) || ((n = strtoimax(s, , 10)), (ep == NULL || ep == s || *ep != '\0'))) - error("Illegal number: '%s'", s); + error("Invalid 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.56 src/bin/sh/options.c:1.57 --- src/bin/sh/options.c:1.56 Tue Oct 26 00:05:38 2021 +++ src/bin/sh/options.c Sat Apr 16 14:20:45 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: options.c,v 1.56 2021/10/26 00:05:38 kre Exp $ */ +/* $NetBSD: options.c,v 1.57 2022/04/16 14:20:45 kre 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.56 2021/10/26 00:05:38 kre Exp $"); +__RCSID("$NetBSD: options.c,v 1.57 2022/04/16 14:20:45 kre Exp $"); #endif #endif /* not lint */ @@ -325,7 +325,7 @@ minus_o(char *name, int val) #endif return; } - error("Illegal option %co %s", "+-"[val], name); + error("Unknown option %co %s", "+-"[val], name); } } @@ -344,7 +344,7 @@ setoption(int flag, int val) #endif return; } - error("Illegal option %c%c", "+-"[val], flag); + error("Unknown option %c%c", "+-"[val], flag); /* NOTREACHED */ } @@ -540,7 +540,7 @@ atend: s[1] = '\0'; err |= setvarsafe("OPTARG", s, 0); } else { -outfmt(, "Illegal option -%c\n", c); +outfmt(, "Unknown option -%c\n", c); (void) unsetvar("OPTARG", 0); } c = '?'; @@ -631,7 +631,7 @@ nextopt(const char *optstring) c = *p++; for (q = optstring ; *q != c ; ) { if (*q == '\0') - error("Illegal option -%c", c); + error("Unknown option -%c", c); if (*++q == ':') q++; } Index: src/bin/sh/parser.c diff -u src/bin/sh/parser.c:1.177 src/bin/sh/parser.c:1.178 --- src/bin/sh/parser.c:1.177 Wed Dec 8 20:21:09 2021 +++ src/bin/sh/parser.c Sat Apr 16 14:20:45 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: parser.c,v 1.177 2021/12/08 20:21:09 andvar Exp $ */ +/* $NetBSD: parser.c,v 1.178 2022/04/16 14:20:45 kre 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.177 2021/12/08 20:21:09 andvar Exp $"); +__RCSID("$NetBSD: parser.c,v 1.178 2022/04/16 14:20:45 kre Exp $"); #endif #endif /* not lint */ @@ -795,7 +795,8 @@ parsefname(void) * So, leave it like this until the rest of the parser is fixed. */ if (!noexpand(wordtext)) - synerror("Illegal eof marker for << redirection"); + synerror("Unimplemented form of eof marker" + " for << redirection"); rmescapes(wordtext); here->eofmark = wordtext;
CVS commit: src/bin/sh
Module Name:src Committed By: rillig Date: Tue Feb 8 20:39:59 UTC 2022 Modified Files: src/bin/sh: histedit.c Log Message: sh: fix typo in comment To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 src/bin/sh/histedit.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.60 src/bin/sh/histedit.c:1.61 --- src/bin/sh/histedit.c:1.60 Wed Feb 2 01:21:34 2022 +++ src/bin/sh/histedit.c Tue Feb 8 20:39:59 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.c,v 1.60 2022/02/02 01:21:34 kre Exp $ */ +/* $NetBSD: histedit.c,v 1.61 2022/02/08 20:39:59 rillig 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.60 2022/02/02 01:21:34 kre Exp $"); +__RCSID("$NetBSD: histedit.c,v 1.61 2022/02/08 20:39:59 rillig Exp $"); #endif #endif /* not lint */ @@ -133,7 +133,7 @@ histedit(void) * This odd piece of code doesn't affect the shell * at all, the environment modified here is the * stuff accessed via "environ" (the incoming - * envoironment to the shell) which is only ever + * environment to the shell) which is only ever * touched at sh startup time (long before we get * here) and ignored thereafter. *
CVS commit: src/bin/sh
Module Name:src Committed By: rillig Date: Tue Feb 8 20:39:59 UTC 2022 Modified Files: src/bin/sh: histedit.c Log Message: sh: fix typo in comment To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 src/bin/sh/histedit.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Wed Feb 2 01:21:34 UTC 2022 Modified Files: src/bin/sh: histedit.c Log Message: After (a few days short of) 21 years, revert 1.25, which did nothing except make the -e option to "fc" fail to work (the commit message was about some other changes entirely, so I an only assume this was committed by mistake). It says a lot about the use of the fc command that no-one noticed that this did not work properly for all this time. Internally in sh, it is possible for built in commands to use either getopt(3) (from libc) or the much simpler internal shell nextopt() routine for option (flag) parsing.However it makes no sense to use getopt() and then access a global variable set only by nextopt() instead of the one getopt() sets (which is what the code had used previously, forever). Use the correct variable again. XXX pullup -9 -8 (-7 -6 -5 ...) To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 src/bin/sh/histedit.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.59 src/bin/sh/histedit.c:1.60 --- src/bin/sh/histedit.c:1.59 Mon Jan 31 18:15:45 2022 +++ src/bin/sh/histedit.c Wed Feb 2 01:21:34 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.c,v 1.59 2022/01/31 18:15:45 kre Exp $ */ +/* $NetBSD: histedit.c,v 1.60 2022/02/02 01:21:34 kre 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.59 2022/01/31 18:15:45 kre Exp $"); +__RCSID("$NetBSD: histedit.c,v 1.60 2022/02/02 01:21:34 kre Exp $"); #endif #endif /* not lint */ @@ -318,7 +318,7 @@ histcmd(volatile int argc, char ** volat (ch = getopt(argc, argv, ":e:lnrs")) != -1) switch ((char)ch) { case 'e': - editor = optionarg; + editor = optarg; break; case 'l': lflg = 1;
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Wed Feb 2 01:21:34 UTC 2022 Modified Files: src/bin/sh: histedit.c Log Message: After (a few days short of) 21 years, revert 1.25, which did nothing except make the -e option to "fc" fail to work (the commit message was about some other changes entirely, so I an only assume this was committed by mistake). It says a lot about the use of the fc command that no-one noticed that this did not work properly for all this time. Internally in sh, it is possible for built in commands to use either getopt(3) (from libc) or the much simpler internal shell nextopt() routine for option (flag) parsing.However it makes no sense to use getopt() and then access a global variable set only by nextopt() instead of the one getopt() sets (which is what the code had used previously, forever). Use the correct variable again. XXX pullup -9 -8 (-7 -6 -5 ...) To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 src/bin/sh/histedit.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/bin/sh
Module Name:src Committed By: kre Date: Mon Jan 31 18:15:45 UTC 2022 Modified Files: src/bin/sh: histedit.c Log Message: When we initialize libedit (editline) always call ourselves "sh" no matter what $0 is (or is not) set to. This means that editrc(5) lines that start "sh:" are used (in addition to those with no prefix, which will usually be most of them), regardless of the name or manner in which we were invoked. OK christos@ To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 src/bin/sh/histedit.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.58 src/bin/sh/histedit.c:1.59 --- src/bin/sh/histedit.c:1.58 Mon Jan 31 16:54:28 2022 +++ src/bin/sh/histedit.c Mon Jan 31 18:15:45 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.c,v 1.58 2022/01/31 16:54:28 kre Exp $ */ +/* $NetBSD: histedit.c,v 1.59 2022/01/31 18:15:45 kre 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.58 2022/01/31 16:54:28 kre Exp $"); +__RCSID("$NetBSD: histedit.c,v 1.59 2022/01/31 18:15:45 kre Exp $"); #endif #endif /* not lint */ @@ -115,7 +115,7 @@ histedit(void) /* * turn editing on */ - char *term, *shname; + char *term; INTOFF; if (el_in == NULL) @@ -151,10 +151,7 @@ histedit(void) setenv("TERM", term, 1); else unsetenv("TERM"); - shname = arg0; - if (shname[0] == '-') -shname++; - el = el_init(shname, el_in, el_out, el_err); + el = el_init("sh", el_in, el_out, el_err); if (el != NULL) { if (hist) el_set(el, EL_HIST, history, hist);