[PATCH v2] ash: remove unnecessary code in backquote expansion

Ron Yorston rmy at pobox.com
Fri Apr 20 07:50:28 UTC 2018


Some traces remain of ash's ancient support for omitting the fork when
expanding a builtin command in backquotes.

Remove:

- the buf and nleft elements of the backcmd structure;
- a misleading comment regarding handling of builtins.

A similar patch to dash was rejected because "we may need this at
some point in the future".  In the meantime I don't see any need to
carry this dead code in BusyBox:  it can aways be restored if
necessary.

function                                             old     new   delta
argstr                                              1332    1325      -7

v2:
- update commit message
- change incorrect function name in TRACE

Signed-off-by: Ron Yorston <rmy at pobox.com>
---
 shell/ash.c | 39 ++++++++++-----------------------------
 1 file changed, 10 insertions(+), 29 deletions(-)

diff --git a/shell/ash.c b/shell/ash.c
index 051cc671f..9c5c1535a 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -6369,15 +6369,12 @@ exptilde(char *startp, char *p, int flags)
 }
 
 /*
- * Execute a command inside back quotes.  If it's a builtin command, we
- * want to save its output in a block obtained from malloc.  Otherwise
- * we fork off a subprocess and get the output of the command via a pipe.
- * Should be called with interrupts off.
+ * Execute a command inside back quotes.  We fork off a subprocess and
+ * get the output of the command via a pipe.  Should be called with
+ * interrupts off.
  */
 struct backcmd {                /* result of evalbackcmd */
 	int fd;                 /* file descriptor to read from */
-	int nleft;              /* number of chars in buffer */
-	char *buf;              /* buffer */
 	struct job *jp;         /* job structure for command */
 };
 
@@ -6407,8 +6404,6 @@ evalbackcmd(union node *n, struct backcmd *result)
 	struct job *jp;
 
 	result->fd = -1;
-	result->buf = NULL;
-	result->nleft = 0;
 	result->jp = NULL;
 	if (n == NULL) {
 		goto out;
@@ -6445,8 +6440,7 @@ evalbackcmd(union node *n, struct backcmd *result)
 	result->jp = jp;
 
  out:
-	TRACE(("evalbackcmd done: fd=%d buf=0x%x nleft=%d jp=0x%x\n",
-		result->fd, result->buf, result->nleft, result->jp));
+	TRACE(("evalbackcmd done: fd=%d jp=0x%x\n", result->fd, result->jp));
 }
 
 /*
@@ -6458,7 +6452,6 @@ expbackq(union node *cmd, int flag)
 	struct backcmd in;
 	int i;
 	char buf[128];
-	char *p;
 	char *dest;
 	int startloc;
 	int syntax = flag & EXP_QUOTED ? DQSYNTAX : BASESYNTAX;
@@ -6470,24 +6463,12 @@ expbackq(union node *cmd, int flag)
 	evalbackcmd(cmd, &in);
 	popstackmark(&smark);
 
-	p = in.buf;
-	i = in.nleft;
-	if (i == 0)
-		goto read;
-	for (;;) {
-		memtodest(p, i, syntax, flag & QUOTES_ESC);
- read:
-		if (in.fd < 0)
-			break;
-		i = nonblock_immune_read(in.fd, buf, sizeof(buf));
-		TRACE(("expbackq: read returns %d\n", i));
-		if (i <= 0)
-			break;
-		p = buf;
-	}
-
-	free(in.buf);
 	if (in.fd >= 0) {
+		while ((i=nonblock_immune_read(in.fd, buf, sizeof(buf))) > 0) {
+			TRACE(("expbackq: read returns %d\n", i));
+			memtodest(buf, i, syntax, flag & QUOTES_ESC);
+		}
+
 		close(in.fd);
 		back_exitstatus = waitforjob(in.jp);
 	}
@@ -6501,7 +6482,7 @@ expbackq(union node *cmd, int flag)
 
 	if (!(flag & EXP_QUOTED))
 		recordregion(startloc, dest - (char *)stackblock(), 0);
-	TRACE(("evalbackq: size:%d:'%.*s'\n",
+	TRACE(("expbackq: size:%d:'%.*s'\n",
 		(int)((dest - (char *)stackblock()) - startloc),
 		(int)((dest - (char *)stackblock()) - startloc),
 		stackblock() + startloc));
-- 
2.14.3



More information about the busybox mailing list