1From: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx> 2Date: Thu, 19 Apr 2018 18:16:12 +0800 3 4> ash originally had support for omitting the fork when expanding a 5> builtin in backquotes. dash has gradually been removing this support, 6> most recently in commit 66b614e29038e31745c4a5d296f64f8d64f5c377 7> ("[EVAL] Remove unused EV_BACKCMD flag"). 8> 9> Some traces still remain, however. Remove: 10> 11> - the buf and nleft elements of the backcmd structure; 12> - a misleading comment regarding handling of builtins. 13> 14> Signed-off-by: Ron Yorston <rmy@xxxxxxxxxxxx> 15 16Unfortunately we may need this at some point in the future due 17to changes in POSIX. So let's keep it around for now until we 18get things such as `jobs -p` to work. 19 20************************************* 21 22From: Ron Yorston <rmy@xxxxxxxxxxxx> 23Date: Thu, 19 Apr 2018 17:18:47 +0100 24 25>Unfortunately we may need this at some point in the future due 26>to changes in POSIX. So let's keep it around for now until we 27>get things such as `jobs -p` to work. 28 29As you wish. 30 31Something even more trivial I noticed later: the TRACE at the end of 32expbackq incorrectly refers to the function as evalbackq. 33 34************************************* 35 36Date: Tue, 10 Apr 2018 13:23:35 +0100 37From: Ron Yorston <rmy@pobox.com> 38To: busybox@busybox.net 39Subject: [PATCH] ash: remove unnecessary code in backquote expansion 40 41Some traces remain of ash's ancient support for omitting the fork when 42expanding a builtin command in backquotes. 43 44Remove: 45 46- the buf and nleft elements of the backcmd structure; 47- a misleading comment regarding handling of builtins. 48 49I've submitted a similar patch to dash. 50 51Signed-off-by: Ron Yorston <rmy@pobox.com> 52--- 53 shell/ash.c | 37 +++++++++---------------------------- 54 1 file changed, 9 insertions(+), 28 deletions(-) 55 56diff --git a/shell/ash.c b/shell/ash.c 57index 45c747dbc..6f1458722 100644 58--- a/shell/ash.c 59+++ b/shell/ash.c 60@@ -6356,15 +6356,12 @@ exptilde(char *startp, char *p, int flags) 61 } 62 63 /* 64- * Execute a command inside back quotes. If it's a builtin command, we 65- * want to save its output in a block obtained from malloc. Otherwise 66- * we fork off a subprocess and get the output of the command via a pipe. 67- * Should be called with interrupts off. 68+ * Execute a command inside back quotes. We fork off a subprocess and 69+ * get the output of the command via a pipe. Should be called with 70+ * interrupts off. 71 */ 72 struct backcmd { /* result of evalbackcmd */ 73 int fd; /* file descriptor to read from */ 74- int nleft; /* number of chars in buffer */ 75- char *buf; /* buffer */ 76 struct job *jp; /* job structure for command */ 77 }; 78 79@@ -6394,8 +6391,6 @@ evalbackcmd(union node *n, struct backcmd *result) 80 struct job *jp; 81 82 result->fd = -1; 83- result->buf = NULL; 84- result->nleft = 0; 85 result->jp = NULL; 86 if (n == NULL) { 87 goto out; 88@@ -6432,8 +6427,7 @@ evalbackcmd(union node *n, struct backcmd *result) 89 result->jp = jp; 90 91 out: 92- TRACE(("evalbackcmd done: fd=%d buf=0x%x nleft=%d jp=0x%x\n", 93- result->fd, result->buf, result->nleft, result->jp)); 94+ TRACE(("evalbackcmd done: fd=%d jp=0x%x\n", result->fd, result->jp)); 95 } 96 97 /* 98@@ -6445,7 +6439,6 @@ expbackq(union node *cmd, int flag) 99 struct backcmd in; 100 int i; 101 char buf[128]; 102- char *p; 103 char *dest; 104 int startloc; 105 int syntax = flag & EXP_QUOTED ? DQSYNTAX : BASESYNTAX; 106@@ -6457,24 +6450,12 @@ expbackq(union node *cmd, int flag) 107 evalbackcmd(cmd, &in); 108 popstackmark(&smark); 109 110- p = in.buf; 111- i = in.nleft; 112- if (i == 0) 113- goto read; 114- for (;;) { 115- memtodest(p, i, syntax, flag & QUOTES_ESC); 116- read: 117- if (in.fd < 0) 118- break; 119- i = nonblock_immune_read(in.fd, buf, sizeof(buf)); 120- TRACE(("expbackq: read returns %d\n", i)); 121- if (i <= 0) 122- break; 123- p = buf; 124- } 125- 126- free(in.buf); 127 if (in.fd >= 0) { 128+ while ((i = nonblock_immune_read(in.fd, buf, sizeof(buf))) > 0) { 129+ TRACE(("expbackq: read returns %d\n", i)); 130+ memtodest(buf, i, syntax, flag & QUOTES_ESC); 131+ } 132+ 133 close(in.fd); 134 back_exitstatus = waitforjob(in.jp); 135 } 136