CVS commit: [netbsd-10] src/bin/sh

2024-02-03 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Feb  3 14:31:38 UTC 2024

Modified Files:
src/bin/sh [netbsd-10]: jobs.c

Log Message:
Pull up following revision(s) (requested by kre in ticket #577):

bin/sh/jobs.c: revision 1.119

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!)


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.117.2.1 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.117 src/bin/sh/jobs.c:1.117.2.1
--- src/bin/sh/jobs.c:1.117	Sun Oct 30 01:46:16 2022
+++ src/bin/sh/jobs.c	Sat Feb  3 14:31:38 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: jobs.c,v 1.117 2022/10/30 01:46:16 kre Exp $	*/
+/*	$NetBSD: jobs.c,v 1.117.2.1 2024/02/03 14:31:38 martin Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)jobs.c	8.5 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: jobs.c,v 1.117 2022/10/30 01:46:16 kre Exp $");
+__RCSID("$NetBSD: jobs.c,v 1.117.2.1 2024/02/03 14:31:38 martin 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: [netbsd-10] src/bin/sh

2024-02-03 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Feb  3 14:31:38 UTC 2024

Modified Files:
src/bin/sh [netbsd-10]: jobs.c

Log Message:
Pull up following revision(s) (requested by kre in ticket #577):

bin/sh/jobs.c: revision 1.119

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!)


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.117.2.1 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: [netbsd-10] src/bin/sh

2024-01-14 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jan 14 13:15:05 UTC 2024

Modified Files:
src/bin/sh [netbsd-10]: eval.c expand.c

Log Message:
Pull up following revision(s) (requested by kre in ticket #535):

bin/sh/eval.c: revision 1.191
bin/sh/expand.c: revision 1.144

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.

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.


To generate a diff of this commit:
cvs rdiff -u -r1.188 -r1.188.2.1 src/bin/sh/eval.c
cvs rdiff -u -r1.141 -r1.141.2.1 src/bin/sh/expand.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/eval.c
diff -u src/bin/sh/eval.c:1.188 src/bin/sh/eval.c:1.188.2.1
--- src/bin/sh/eval.c:1.188	Wed Jan  5 15:25:44 2022
+++ src/bin/sh/eval.c	Sun Jan 14 13:15:05 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: eval.c,v 1.188 2022/01/05 15:25:44 kre Exp $	*/
+/*	$NetBSD: eval.c,v 1.188.2.1 2024/01/14 13:15:05 martin Exp $	*/
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)eval.c	8.9 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: eval.c,v 1.188 2022/01/05 15:25:44 kre Exp $");
+__RCSID("$NetBSD: eval.c,v 1.188.2.1 2024/01/14 13:15:05 martin 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;
 

Index: src/bin/sh/expand.c
diff -u src/bin/sh/expand.c:1.141 src/bin/sh/expand.c:1.141.2.1
--- src/bin/sh/expand.c:1.141	Mon Nov 22 05:17:43 2021
+++ src/bin/sh/expand.c	Sun Jan 14 13:15:05 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: expand.c,v 1.141 2021/11/22 05:17:43 kre Exp $	*/
+/*	$NetBSD: expand.c,v 1.141.2.1 2024/01/14 13:15:05 martin Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)expand.c	8.5 (Berkeley) 5/15/95";
 #else
-__RCSID("$NetBSD: expand.c,v 1.141 2021/11/22 05:17:43 kre Exp $");
+__RCSID("$NetBSD: expand.c,v 1.141.2.1 2024/01/14 13:15:05 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -1185,7 +1185,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 {\
@@ -1197,7 +1197,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: [netbsd-10] src/bin/sh

2024-01-14 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jan 14 13:15:05 UTC 2024

Modified Files:
src/bin/sh [netbsd-10]: eval.c expand.c

Log Message:
Pull up following revision(s) (requested by kre in ticket #535):

bin/sh/eval.c: revision 1.191
bin/sh/expand.c: revision 1.144

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.

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.


To generate a diff of this commit:
cvs rdiff -u -r1.188 -r1.188.2.1 src/bin/sh/eval.c
cvs rdiff -u -r1.141 -r1.141.2.1 src/bin/sh/expand.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: [netbsd-10] src/bin/sh

2023-11-03 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Nov  3 10:07:09 UTC 2023

Modified Files:
src/bin/sh [netbsd-10]: miscbltin.c

Log Message:
Pull up following revision(s) (requested by kre in ticket #454):

bin/sh/miscbltin.c: revision 1.54

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).


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.53.2.1 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.53.2.1
--- src/bin/sh/miscbltin.c:1.53	Sun Dec 11 08:23:10 2022
+++ src/bin/sh/miscbltin.c	Fri Nov  3 10:07:09 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: miscbltin.c,v 1.53 2022/12/11 08:23:10 kre Exp $	*/
+/*	$NetBSD: miscbltin.c,v 1.53.2.1 2023/11/03 10:07:09 martin 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.53.2.1 2023/11/03 10:07:09 martin 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: [netbsd-10] src/bin/sh

2023-11-03 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Nov  3 10:07:09 UTC 2023

Modified Files:
src/bin/sh [netbsd-10]: miscbltin.c

Log Message:
Pull up following revision(s) (requested by kre in ticket #454):

bin/sh/miscbltin.c: revision 1.54

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).


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.53.2.1 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: [netbsd-10] src/bin/sh

2022-12-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Dec 20 09:51:47 UTC 2022

Modified Files:
src/bin/sh [netbsd-10]: sh.1

Log Message:
Pull up following revision(s) (requested by uwe in ticket #11):

bin/sh/sh.1: revision 1.253

sh(1): Fix markup.  -compact must be last.


To generate a diff of this commit:
cvs rdiff -u -r1.252 -r1.252.2.1 src/bin/sh/sh.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: [netbsd-10] src/bin/sh

2022-12-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Dec 20 09:51:47 UTC 2022

Modified Files:
src/bin/sh [netbsd-10]: sh.1

Log Message:
Pull up following revision(s) (requested by uwe in ticket #11):

bin/sh/sh.1: revision 1.253

sh(1): Fix markup.  -compact must be last.


To generate a diff of this commit:
cvs rdiff -u -r1.252 -r1.252.2.1 src/bin/sh/sh.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/sh.1
diff -u src/bin/sh/sh.1:1.252 src/bin/sh/sh.1:1.252.2.1
--- src/bin/sh/sh.1:1.252	Sun Dec 11 08:23:10 2022
+++ src/bin/sh/sh.1	Tue Dec 20 09:51:47 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sh.1,v 1.252 2022/12/11 08:23:10 kre Exp $
+.\"	$NetBSD: sh.1,v 1.252.2.1 2022/12/20 09:51:47 martin 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 ,