Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh PR bin/53550
details: https://anonhg.NetBSD.org/src/rev/d3634ed26d46
branches: trunk
changeset: 1026398:d3634ed26d46
user: kre <kre%NetBSD.org@localhost>
date: Mon Nov 22 05:17:43 2021 +0000
description:
PR bin/53550
Here we go again... One more time to redo how here docs are
processed (it has been a few years since the last time!)
This is actually a relatively minor change, mostly to timimg
(to just when things happen). Now here docs are expanded at the
same time the "filename" word in a redirect is expanded, rather than
later when the heredoc was being sent to its process. This actually
makes things more consistent - but does break one of the ATF tests
which was testing that we were (effectively) internally inconsistent
in this area.
Not all shells agree on the context in which redirection expansions
should happen, some make any side effects visible to the parent shell
(the majority do) others do the redirection expansions in a subshell
so any side effcts are lost. We used to have a foot in each camp,
with the majority for everything but here docs, and the minority for
here docs. Now we're all the way with LBJ ... (or something like that).
diffstat:
bin/sh/eval.c | 10 ++++++++--
bin/sh/expand.c | 14 +++++++-------
bin/sh/expand.h | 4 ++--
bin/sh/nodetypes | 3 ++-
bin/sh/redir.c | 21 +++++++++------------
5 files changed, 28 insertions(+), 24 deletions(-)
diffs (155 lines):
diff -r 3b7d2d712fc8 -r d3634ed26d46 bin/sh/eval.c
--- a/bin/sh/eval.c Mon Nov 22 05:07:15 2021 +0000
+++ b/bin/sh/eval.c Mon Nov 22 05:17:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: eval.c,v 1.185 2021/11/16 11:27:50 kre Exp $ */
+/* $NetBSD: eval.c,v 1.186 2021/11/22 05:17:43 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.185 2021/11/16 11:27:50 kre Exp $");
+__RCSID("$NetBSD: eval.c,v 1.186 2021/11/22 05:17:43 kre Exp $");
#endif
#endif /* not lint */
@@ -618,6 +618,12 @@
fixredir(redir, fn.list->text, 1);
}
break;
+ case NHERE:
+ redir->nhere.text = redir->nhere.doc->narg.text;
+ break;
+ case NXHERE:
+ redir->nhere.text = expandhere(redir->nhere.doc);
+ break;
}
}
}
diff -r 3b7d2d712fc8 -r d3634ed26d46 bin/sh/expand.c
--- a/bin/sh/expand.c Mon Nov 22 05:07:15 2021 +0000
+++ b/bin/sh/expand.c Mon Nov 22 05:17:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: expand.c,v 1.140 2021/11/10 15:26:34 kre Exp $ */
+/* $NetBSD: expand.c,v 1.141 2021/11/22 05:17:43 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.140 2021/11/10 15:26:34 kre Exp $");
+__RCSID("$NetBSD: expand.c,v 1.141 2021/11/22 05:17:43 kre Exp $");
#endif
#endif /* not lint */
@@ -143,16 +143,16 @@
* Expand shell variables and backquotes inside a here document.
*/
-void
-expandhere(union node *arg, int fd)
+char *
+expandhere(union node *arg)
{
int len;
- VTRACE(DBG_EXPAND|DBG_REDIR, ("expandhere() fd=%d\n", fd));
- herefd = fd;
+ VTRACE(DBG_EXPAND|DBG_REDIR, ("expandhere(%p)\n", arg));
expandarg(arg, NULL, 0);
len = rmescapes(stackblock());
- xwrite(fd, stackblock(), len);
+ VTRACE(DBG_EXPAND|DBG_REDIR, ("expandhere() -> %d\n", len));
+ return stalloc(len + 1); /* include the \0 */
}
diff -r 3b7d2d712fc8 -r d3634ed26d46 bin/sh/expand.h
--- a/bin/sh/expand.h Mon Nov 22 05:07:15 2021 +0000
+++ b/bin/sh/expand.h Mon Nov 22 05:17:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: expand.h,v 1.25 2020/02/13 05:19:05 kre Exp $ */
+/* $NetBSD: expand.h,v 1.26 2021/11/22 05:17:43 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -65,7 +65,7 @@
union node;
-void expandhere(union node *, int);
+char *expandhere(union node *);
void expandarg(union node *, struct arglist *, int);
int rmescapes(char *);
int casematch(union node *, char *);
diff -r 3b7d2d712fc8 -r d3634ed26d46 bin/sh/nodetypes
--- a/bin/sh/nodetypes Mon Nov 22 05:07:15 2021 +0000
+++ b/bin/sh/nodetypes Mon Nov 22 05:17:43 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: nodetypes,v 1.19 2021/11/16 11:25:44 kre Exp $
+# $NetBSD: nodetypes,v 1.20 2021/11/22 05:17:43 kre Exp $
# Copyright (c) 1991, 1993
# The Regents of the University of California. All rights reserved.
#
@@ -143,6 +143,7 @@
next nodeptr # next redirection in list
fd int # file descriptor being redirected
doc nodeptr # input to command (NARG node)
+ text temp char *text # expanded heredoc content
NNOT nnot # ! command (actually pipeline)
NDNOT nnot # ! ! pipeline (optimisation)
diff -r 3b7d2d712fc8 -r d3634ed26d46 bin/sh/redir.c
--- a/bin/sh/redir.c Mon Nov 22 05:07:15 2021 +0000
+++ b/bin/sh/redir.c Mon Nov 22 05:17:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: redir.c,v 1.71 2021/11/16 11:27:50 kre Exp $ */
+/* $NetBSD: redir.c,v 1.72 2021/11/22 05:17:43 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)redir.c 8.2 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: redir.c,v 1.71 2021/11/16 11:27:50 kre Exp $");
+__RCSID("$NetBSD: redir.c,v 1.72 2021/11/22 05:17:43 kre Exp $");
#endif
#endif /* not lint */
@@ -459,12 +459,12 @@
if (pipe(pip) < 0)
error("Pipe call failed");
- if (redir->type == NHERE) {
- len = strlen(redir->nhere.doc->narg.text);
- if (len <= PIPESIZE) {
- xwrite(pip[1], redir->nhere.doc->narg.text, len);
- goto out;
- }
+ len = strlen(redir->nhere.text);
+ VTRACE(DBG_REDIR, ("openhere(%p) [%d] \"%.*s\"%s\n", redir, len,
+ (len < 40 ? len : 40), redir->nhere.text, (len < 40 ? "" : "...")));
+ if (len <= PIPESIZE) { /* XXX eventually copy FreeBSD method */
+ xwrite(pip[1], redir->nhere.text, len);
+ goto out;
}
VTRACE(DBG_REDIR, (" forking [%d,%d]\n", pip[0], pip[1]));
if (forkshell(NULL, NULL, FORK_NOJOB) == 0) {
@@ -476,10 +476,7 @@
signal(SIGTSTP, SIG_IGN);
#endif
signal(SIGPIPE, SIG_DFL);
- if (redir->type == NHERE)
- xwrite(pip[1], redir->nhere.doc->narg.text, len);
- else
- expandhere(redir->nhere.doc, pip[1]);
+ xwrite(pip[1], redir->nhere.text, len);
VTRACE(DBG_PROCS|DBG_REDIR, ("wrote here doc. exiting(0)\n"));
_exit(0);
}
Home |
Main Index |
Thread Index |
Old Index