From patchwork Sun May 17 13:36:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 11554165 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CE30113B4 for ; Sun, 17 May 2020 13:36:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B04372065F for ; Sun, 17 May 2020 13:36:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727893AbgEQNgw (ORCPT ); Sun, 17 May 2020 09:36:52 -0400 Received: from helcar.hmeau.com ([216.24.177.18]:44960 "EHLO fornost.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727898AbgEQNgw (ORCPT ); Sun, 17 May 2020 09:36:52 -0400 Received: from gwarestrin.arnor.me.apana.org.au ([192.168.0.7]) by fornost.hmeau.com with smtp (Exim 4.89 #2 (Debian)) id 1jaJSr-0006E0-Ul; Sun, 17 May 2020 23:36:27 +1000 Received: by gwarestrin.arnor.me.apana.org.au (sSMTP sendmail emulation); Sun, 17 May 2020 23:36:25 +1000 Date: Sun, 17 May 2020 23:36:25 +1000 From: Herbert Xu To: Harald van Dijk Cc: Ron Yorston , contact@emersion.fr, dash@vger.kernel.org Subject: [PATCH] parser: Save and restore heredoclist in expandstr Message-ID: <20200517133625.GA15227@gondor.apana.org.au> References: <20200121063959.tel7ty76fkz33xpn@gondor.apana.org.au> <5e56df24.H24u7mxAPbLPL6fI%rmy@frippery.org> <20200228004023.GA9163@gondor.apana.org.au> <20200428061758.GA1771@gondor.apana.org.au> <15d522d8-e0f5-be2a-f2a2-8b17290fce31@gigawatt.nl> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <15d522d8-e0f5-be2a-f2a2-8b17290fce31@gigawatt.nl> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org On Sun, May 17, 2020 at 01:19:28PM +0100, Harald van Dijk wrote: > > This still does not restore the state completely. It does not clean up any > pending heredocs. I see: > > $ PS1='$(< src/dash: 1: Syntax error: Unterminated quoted string > $(< > > > That is, after entering the ':' command, the shell is still trying to read > the heredoc from the prompt. This patch saves and restores the heredoclist in expandstr. It also removes a bunch of unnecessary volatiles as those variables are only referenced in case of a longjmp other than one started by a signal like SIGINT. Reported-by: Harald van Dijk Signed-off-by: Herbert Xu diff --git a/src/parser.c b/src/parser.c index 3131045..54c2861 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1565,10 +1565,11 @@ setprompt(int which) const char * expandstr(const char *ps) { - struct parsefile *volatile file_stop; + struct parsefile *file_stop; struct jmploc *volatile savehandler; - const char *volatile result; - volatile int saveprompt; + struct heredoc *saveheredoclist; + const char *result; + int saveprompt; struct jmploc jmploc; union node n; int err; @@ -1578,6 +1579,8 @@ expandstr(const char *ps) /* XXX Fix (char *) cast. */ setinputstring((char *)ps); + saveheredoclist = heredoclist; + heredoclist = NULL; saveprompt = doprompt; doprompt = 0; result = ps; @@ -1603,6 +1606,7 @@ out: doprompt = saveprompt; unwindfiles(file_stop); + heredoclist = saveheredoclist; return result; }