From patchwork Wed Apr 4 09:54:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 10322329 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 5406260318 for ; Wed, 4 Apr 2018 09:54:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E826206AF for ; Wed, 4 Apr 2018 09:54:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32B6628DBE; Wed, 4 Apr 2018 09:54:11 +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=-6.9 required=2.0 tests=BAYES_00,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 3676B206AF for ; Wed, 4 Apr 2018 09:54:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750762AbeDDJyJ (ORCPT ); Wed, 4 Apr 2018 05:54:09 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:33570 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750736AbeDDJyJ (ORCPT ); Wed, 4 Apr 2018 05:54:09 -0400 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtp (Exim 4.84_2 #2 (Debian)) id 1f3f7D-0000NH-05; Wed, 04 Apr 2018 17:54:03 +0800 Received: from herbert by gondobar with local (Exim 4.84_2) (envelope-from ) id 1f3f7B-0002sr-3X; Wed, 04 Apr 2018 17:54:01 +0800 Date: Wed, 4 Apr 2018 17:54:01 +0800 From: Herbert Xu To: Dirk Fieldhouse Cc: dash@vger.kernel.org Subject: eval: Variable assignments on functions are no longer persistent Message-ID: <20180404095401.GA11060@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <435f62d6-76a1-a935-9a75-075d633e0989@gmx.net> X-Newsgroups: apana.lists.os.linux.dash Organization: Core User-Agent: Mutt/1.5.23 (2014-03-12) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Dirk Fieldhouse wrote: > > In POSIX.1-2017 ("simultaneously IEEE Std 1003.1™-2017 and The Open > Group Technical Standard Base Specifications, Issue 7") > , > we read under '2.9.1 Simple Commands' > > "Variable assignments shall be performed as follows: > ... > - If the command name is a standard utility implemented as a function > (see XBD Utility), the effect of variable assignments shall be as if the > utility was not implemented as a function. > ... > - If the command name is a function that is not a standard utility > implemented as a function, variable assignments shall affect the current > execution environment during the execution of the function. It is > unspecified: > > * Whether or not the variable assignments persist after the > completion of the function > > * Whether or not the variables gain the export attribute during > the execution of the function > > * Whether or not export attributes gained as a result of the > variable assignments persist after the completion of the function (if > variable assignments persist after the completion of the function)" POSIX used to require the current dash behaviour. However, you're right that this is no longer the case. This patch will remove the persistence of the variable assignment. I have considered the exporting the variables during the function execution but have decided against it because: 1) It makes the code bigger. 2) dash has never done this in the past. 3) You cannot use this portably anyway. Reported-by: Dirk Fieldhouse Signed-off-by: Herbert Xu diff --git a/src/eval.c b/src/eval.c index 7498f9d..623166d 100644 --- a/src/eval.c +++ b/src/eval.c @@ -883,7 +883,6 @@ raise: goto readstatus; case CMDFUNCTION: - poplocalvars(1); if (evalfun(cmdentry.u.func, argc, argv, flags)) goto raise; readstatus: @@ -967,9 +966,7 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags) shellparam.p = argv + 1; shellparam.optind = 1; shellparam.optoff = -1; - pushlocalvars(); evaltree(func->n.ndefun.body, flags & EV_TESTED); - poplocalvars(0); funcdone: INTOFF; loopnest = saveloopnest;