Re: [PATCH] expand: remove unnecessary code in backquote expansion

2018-04-19 Thread Ron Yorston
Herbert Xu  wrote:
>Unfortunately we may need this at some point in the future due
>to changes in POSIX.  So let's keep it around for now until we
>get things such as `jobs -p` to work.

As you wish.

Something even more trivial I noticed later:  the TRACE at the end of
expbackq incorrectly refers to the function as evalbackq.

Ron
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] expand: remove unnecessary code in backquote expansion

2018-04-10 Thread Ron Yorston
ash originally had support for omitting the fork when expanding a
builtin in backquotes.  dash has gradually been removing this support,
most recently in commit 66b614e29038e31745c4a5d296f64f8d64f5c377
("[EVAL] Remove unused EV_BACKCMD flag").

Some traces still remain, however.  Remove:

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

Signed-off-by: Ron Yorston 
---
 src/eval.c   | 12 
 src/eval.h   |  2 --
 src/expand.c | 31 ++-
 3 files changed, 14 insertions(+), 31 deletions(-)

diff --git a/src/eval.c b/src/eval.c
index 7498f9d..32fc300 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -605,10 +605,9 @@ evalpipe(union node *n, 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.
  */
 
 void
@@ -618,8 +617,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;
@@ -644,8 +641,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));
 }
 
 static char **
diff --git a/src/eval.h b/src/eval.h
index 63e7d86..92227af 100644
--- a/src/eval.h
+++ b/src/eval.h
@@ -42,8 +42,6 @@ extern int savestatus;/* exit status of last 
command outside traps */
 
 struct backcmd {   /* result of evalbackcmd */
int fd; /* file descriptor to read from */
-   char *buf;  /* buffer */
-   int nleft;  /* number of chars in buffer */
struct job *jp; /* job structure for command */
 };
 
diff --git a/src/expand.c b/src/expand.c
index 30288db..04a3eeb 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -510,7 +510,6 @@ expbackq(union node *cmd, int flag)
struct backcmd in;
int i;
char buf[128];
-   char *p;
char *dest;
int startloc;
char const *syntax = flag & EXP_QUOTED ? DQSYNTAX : BASESYNTAX;
@@ -522,27 +521,17 @@ expbackq(union node *cmd, int flag)
evalbackcmd(cmd, (struct backcmd *) );
popstackmark();
 
-   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;
-   do {
-   i = read(in.fd, buf, sizeof buf);
-   } while (i < 0 && errno == EINTR);
-   TRACE(("expbackq: read returns %d\n", i));
-   if (i <= 0)
-   break;
-   p = buf;
-   }
-
-   if (in.buf)
-   ckfree(in.buf);
if (in.fd >= 0) {
+   for (;;) {
+   do {
+   i = read(in.fd, buf, sizeof buf);
+   } while (i < 0 && errno == EINTR);
+   TRACE(("expbackq: read returns %d\n", i));
+   if (i <= 0)
+   break;
+   memtodest(buf, i, syntax, flag & QUOTES_ESC);
+   }
+
close(in.fd);
back_exitstatus = waitforjob(in.jp);
}
-- 
2.14.3

--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html