From patchwork Sat May 5 16:39:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 10382211 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 D09C06053F for ; Sat, 5 May 2018 16:39:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFBF129143 for ; Sat, 5 May 2018 16:39:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3EEF29148; Sat, 5 May 2018 16:39:03 +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 20A0D29143 for ; Sat, 5 May 2018 16:39:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751739AbeEEQjC (ORCPT ); Sat, 5 May 2018 12:39:02 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:35778 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751358AbeEEQjC (ORCPT ); Sat, 5 May 2018 12:39:02 -0400 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1fF0D6-0007xg-HT; Sun, 06 May 2018 00:39:00 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1fF0D6-00068C-94; Sun, 06 May 2018 00:39:00 +0800 Date: Sun, 6 May 2018 00:39:00 +0800 From: Herbert Xu To: DASH Mailing List Subject: mkinit: Split reset into exitreset and reset Message-ID: <20180505163900.rstiime4bafd3tmp@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Previously reset was called after exitshell. This was changed so that it was called before exitshell because certain state needed to be reset in order for the EXIT trap to work. However, this caused issues because certain other states (such as local variables) should not be reset. This patch fixes this by creating a new function exitreset that is called prior to exitshell and moving reset back to its original location. Signed-off-by: Herbert Xu diff --git a/src/eval.c b/src/eval.c index a27d657..94c56ec 100644 --- a/src/eval.c +++ b/src/eval.c @@ -112,7 +112,7 @@ STATIC const struct builtincmd bltin = { #ifdef mkinit INCLUDE "eval.h" -RESET { +EXITRESET { evalskip = 0; loopnest = 0; if (savestatus >= 0) { diff --git a/src/expand.c b/src/expand.c index 7ed259a..45e9b79 100644 --- a/src/expand.c +++ b/src/expand.c @@ -1780,7 +1780,7 @@ varunset(const char *end, const char *var, const char *umsg, int varflags) INCLUDE "expand.h" -RESET { +EXITRESET { ifsfree(); } diff --git a/src/init.h b/src/init.h index e026e86..49791a0 100644 --- a/src/init.h +++ b/src/init.h @@ -35,5 +35,5 @@ */ void init(void); +void exitreset(void); void reset(void); -void initshellproc(void); diff --git a/src/main.c b/src/main.c index fcd3e7d..b8f3c08 100644 --- a/src/main.c +++ b/src/main.c @@ -106,7 +106,7 @@ main(int argc, char **argv) int e; int s; - reset(); + exitreset(); e = exception; @@ -114,6 +114,8 @@ main(int argc, char **argv) if (e == EXEXIT || s == 0 || iflag == 0 || shlvl) exitshell(); + reset(); + if (e == EXINT #if ATTY && (! attyset() || equal(termval(), "emacs")) diff --git a/src/mkinit.c b/src/mkinit.c index 9714bee..5bca9ee 100644 --- a/src/mkinit.c +++ b/src/mkinit.c @@ -106,6 +106,13 @@ char init[] = "\ * Initialization code.\n\ */\n"; +char exitreset[] = "\ +/*\n\ + * This routine is called when an error or an interrupt occurs in an\n\ + * interactive shell and control is returned to the main command loop\n\ + * but prior to exitshell. \n\ + */\n"; + char reset[] = "\ /*\n\ * This routine is called when an error or an interrupt occurs in an\n\ @@ -115,6 +122,7 @@ char reset[] = "\ struct event event[] = { {"INIT", "init", init}, + {"EXITRESET", "exitreset", exitreset}, {"RESET", "reset", reset}, {NULL, NULL} }; diff --git a/src/redir.c b/src/redir.c index 71b0f77..e67cc0a 100644 --- a/src/redir.c +++ b/src/redir.c @@ -374,7 +374,7 @@ popredir(int drop) INCLUDE "redir.h" -RESET { +EXITRESET { /* * Discard all saved file descriptors. */