From patchwork Tue Apr 10 12:23:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ron Yorston X-Patchwork-Id: 10332933 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 25C2160365 for ; Tue, 10 Apr 2018 12:38:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16773285EA for ; Tue, 10 Apr 2018 12:38:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B2D528A45; Tue, 10 Apr 2018 12:38:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74055285EA for ; Tue, 10 Apr 2018 12:38:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753118AbeDJMiG (ORCPT ); Tue, 10 Apr 2018 08:38:06 -0400 Received: from haggis.mythic-beasts.com ([46.235.224.141]:42245 "EHLO haggis.mythic-beasts.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752846AbeDJMiG (ORCPT ); Tue, 10 Apr 2018 08:38:06 -0400 X-Greylist: delayed 884 seconds by postgrey-1.27 at vger.kernel.org; Tue, 10 Apr 2018 08:38:06 EDT Received: from [2a00:1098:0:86:1000:33:8512:30ae] (port=55770 helo=frippery.frippery.org) by haggis.mythic-beasts.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1f5sIw-0003g2-3F for dash@vger.kernel.org; Tue, 10 Apr 2018 13:23:18 +0100 Received: by frippery.frippery.org (Postfix, from userid 1000) id DB8B8214A6; Tue, 10 Apr 2018 13:23:16 +0100 (BST) Date: Tue, 10 Apr 2018 13:23:16 +0100 From: Ron Yorston To: dash@vger.kernel.org Subject: [PATCH] expand: remove unnecessary code in backquote expansion Message-ID: <5accacb4.rqjKBcCIxcDMEPQC%rmy@frippery.org> User-Agent: Heirloom mailx 12.4 7/29/08 MIME-Version: 1.0 Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 *) &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; - 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); }