Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16717

Re: process substitution error handling

Path csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: process substitution error handling
Date Thu, 6 Aug 2020 10:48:58 -0400
Organization ITS, Case Western Reserve University
Lines 82
Approved bug-bash@gnu.org
Message-ID <mailman.1023.1596725355.2739.bug-bash@gnu.org> (permalink)
References <20200420051508.GA2359844@zx2c4.com> <7496b183-2db3-6c03-6074-928adcd08f45@case.edu> <CAHmME9pzOY_0EJ69y9wt6r-Jh3frZpV8XdFC6zG5EOkZ99h-1A@mail.gmail.com> <ac79e09f-b4e3-5368-87c1-b6e7147809e2@case.edu> <CAHmME9qNjO+LMxB8py2MDpS2Oprv1mRndgfTXQfXNWyHuwzmjg@mail.gmail.com> <9b358a76-4867-41b9-5a3a-c1892c76b8ee@case.edu>
Reply-To chet.ramey@case.edu
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace usenet.stanford.edu 1596725356 3313 209.51.188.17 (6 Aug 2020 14:49:16 GMT)
X-Complaints-To action@cs.stanford.edu
Cc chet.ramey@case.edu, bug-bash@gnu.org, "Demi M. Obenour" <demiobenour@gmail.com>
To "Jason A. Donenfeld" <Jason@zx2c4.com>
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1596725343; bh=iPtwNUB+8tXjMfzQ8+ZxMzWdut9IZkGrbXGdxKyyBs0=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=8ds3USLjJVKac6BQClMnOCxZI2A6CGsCM9bcIAo/vigo4cQbVaqK6NxPvToXsdFlMp B3yvUP/UiE2j557kglKThMLux5adMIryxJG0YqZ0Dxo97NSaWvXlSO5ehjXaqw6dYey le0jo10RXfZUtOQLXo3KBG1qlRJZjwHW0ecpvcAlr9O/faGGqK/mbGP7Ez+9sL4ZKDM pNCOZuPvXYJrtGcKTleYYxpsrWbr+1TKQsjtVqXsSceVLfIJOxmZ6+ziktettpaDI6V FfxkKfFSf/oRGmHA1VasenGGnH/qadhvM2uz4HlSacdXwZNOO/XNfGo23m12GpIWT62 vkUqTqCQ==
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1596725342; bh=xkwnN7hJ1FEMB5nefOh7DIKgLtOoQLjkJcTQ0Z1yXw0=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=RMqOikAwJpKxlvKS3lJMou3WbjNRnBxJO5SRKhbmuUWgH/AosdDWlDrtjVseQXcab1 u3TMQ05pdfEcU8/pu3tCTV9AJouTt9rClXRezT99ASDs81p7It+rXt9EDv5jivaEubF OC71AkPy3zRreav9Zz4Z+N8lp0awuyKNjUEtfm4tZuLAtE4IYb9joYZ/uU5qIe4fG88 5RsgSD5nJfmtpJ+ANptSjTqgnGyhaZ+dcvtkxhtSVSqCV92RsLJt11QPBWfwzTCnpUA m4I/R/TS3mLUZafNENIZjIA9oqJbOnC8rJc3C/X+4qLnHeSz6PdDZWe5DIfpTm86N7a uEPELfoA==
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=g-case; h=reply-to:cc:subject:to:references:from:autocrypt:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=xkwnN7hJ1FEMB5nefOh7DIKgLtOoQLjkJcTQ0Z1yXw0=; b=K6wPdAmYB5tB7t5StY9Lyx+VsFg7b3kgsznP22N+u9WENEEqt3NiNTAYZ4f1RtlLhM +31pSrJLPP4eXP//F3IDkyf5MInW6R69Ub6eAA8nxogjiJvYbqCzSw0K/Vjb/MWXvobe SQFUpmxoq4njqWudgWpULRWVla04NWrqcfE72R/etpmQgSh4GTKs1HzNGG97xFBCOGHu sVsWfF8650TNaloeYzCUFtvI4XQC69Z1uIv9i/SOfpKUjTc8hqyzBS7fQQ1lxOkbmrNZ 9TjiARxTHJohknN4wi1aZvaQ3p0dT6/tf14MvSL9vvsxoYz+Z65fD61esiepL5SQfImJ m4tQ==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:cc:subject:to:references:from:autocrypt :organization:message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=xkwnN7hJ1FEMB5nefOh7DIKgLtOoQLjkJcTQ0Z1yXw0=; b=bForFu0N1I9LBmFV8qhAy3j16DRp2uSwRfSGmbDv1CStKT97aK/xXyG1bPitO91Jv/ akVyDapHOeoL/csh488y/y6nrQYXy2buDOei81k5ja8Bi7KJHuI3fF8l7AvFRwj820EB Hs14+KUAnaAPI5XxSYxLupzuYeGSJEl+ZnL+ChZS8auT1I6itc0zKmeufCG3uSNW3h6y Juf1NKwVd8kMVVeXuXGnIkwFigtN45i8D2/9Cr03OrhRvVnor5FNsm4ybfU823gXuSmw nXPpLG7zlFm0AXVYJZKqb1Lvna/URo7W+cLlBjWBdDCVtZxxX6paLTGXKca05hI7CaYG bGAg==
X-Gm-Message-State AOAM530kRvZksk7CH6GCTq9XxRnZIHc6P92V13/E6yZhtZS2brbdjapD 79l8rHMRLqAInEEk1rKXMZUUg2+kqt2ZzkxP4Pj0I6f1IOJwBt0GgPXTdG8YQE1hym74U1D+10o DvnEqqozHTXM=
X-Received by 2002:aed:2356:: with SMTP id i22mr8889474qtc.92.1596725341627; Thu, 06 Aug 2020 07:49:01 -0700 (PDT)
X-Google-Smtp-Source ABdhPJzr0ukH9YCHghlhzhqPqU5jw0fQJOMPysreGAo1oYcWLf+qxnqX3OyJ0LW0BoMz/w6o4/pysw==
X-Received by 2002:aed:2356:: with SMTP id i22mr8889410qtc.92.1596725340747; Thu, 06 Aug 2020 07:49:00 -0700 (PDT)
Autocrypt addr=chet.ramey@case.edu; prefer-encrypt=mutual; keydata= mQGiBEEOsGwRBACFa0A1oa71HSZLWxAx0svXzhOZNQZOzqHmSuGOG92jIpQpr8DpvgRh40Yp AwdcXb8QG1J5yGAKeevNE1zCFaA725vGSdHUyypHouV0xoWwukYO6qlyyX+2BZU+okBUqoWQ koWxiYaCSfzB2Ln7pmdys1fJhcgBKf3VjWCjd2XJTwCgoFJOwyBFJdugjfwjSoRSwDOIMf0D /iQKqlWhIO1LGpMrGX0il0/x4zj0NAcSwAk7LaPZbN4UPjn5pqGEHBlf1+xDDQCkAoZ/VqES GZragl4VqJfxBr29Ag0UDvNbUbXoxQsARdero1M8GiAIRc50hj7HXFoERwenbNDJL86GPLAQ OTGOCa4W2o29nFfFjQrsrrYHzVtyA/9oyKvTeEMJ7NA3VJdWcmn7gOu0FxEmSNhSoV1T4vP2 1Wf7f5niCCRKQLNyUy0wEApQi4tSysdz+AbgAc0b/bHYVzIf2uO2lIEZQNNt+3g2bmXgloWm W5fsm/di50Gm1l1Na63d3RZ00SeFQos6WEwLUHEB0yp6KXluXLLIZitEJLQwQ2hldCBSYW1l eSAoQ2FzZSBzdGFuZGFyZCkgPGNoZXQucmFtZXlAY2FzZS5lZHU+iF8EExECAB8FAkPi19EC GwMHCwkIBwMCAQMVAgMDFgIBAh4BAheAAAoJELtYafBk6nSrelkAn31Gsuib7GcCZHbv5L5t VKYR9LklAJ4hzUHKA49Z0QXR+qCb80osIcmPSbkBDQRBDrBvEAQAkK6TAOKBEM+EC4j6V/7o /riVZqcgU5cid2qG9TXdwNtD9a3kvA/ObZBO93sX59wc6Bnwo4VJxsOmMlpGrAjJsxNwg3QH akEtf8LXRbVpj5xStdmBdQZUhIQyalo/2/TZq5OijtddUQcL5cs70hTv/FpT3wUvr2Xr8rjF 41IFEz8AAwcD/A0CZEGlzIrT5WCBnl6xBog/8vKiUCbarByat3d1mL6DbizvKNXQRTC9E/vE dENAWCQCjr75Bu55xT8n3SXGtWdDC5xmZ/P3OBYORP8yl8H8I1FIosWOFirbIeYdZPq8SPD1 HL+EXo9zSiHVrrZRJ19ooCKKbSdXHFCY+aJG+0KZiEkEGBECAAkFAkEOsG8CGwwACgkQu1hp 8GTqdKvjcACfZlkVCDwaz/NTO9cy3t69oWpVPNwAnRwe0qk/WL/gfhH346xh5B3HFbFN
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.11.0
In-Reply-To <CAHmME9qNjO+LMxB8py2MDpS2Oprv1mRndgfTXQfXNWyHuwzmjg@mail.gmail.com>
Content-Language en-US
X-Mirapoint-IP-Reputation reputation=Good-1, source=Queried, refid=tid=0001.0A020303.5F2C10C9.0003, actions=tag
X-Mirapoint-IP-Reputation reputation=good-1, source=Fixed, refid=n/a, actions=tag
X-Junkmail-Status score=8/80, host=mpv2-2015.case.edu
X-Junkmail-PrAS-Raw score=8/80, refid=2.7.2:2020.8.6.135717:17:8.317, ip=, rules=__YOUTUBE_RCVD, DKIM_SIGNATURE, __X_GOOGLE_DKIM_SIGNATURE, __HAS_REPLYTO, __HAS_CC_HDR, __MULTIPLE_RCPTS_CC_X2, __CC_NAME, __CC_NAME_DIFF_FROM_ACC, __SUBJ_REPLY, __PHISH_SPEAR_SUBJ_ALERT, __BOUNCE_CHALLENGE_SUBJ, __BOUNCE_NDR_SUBJ_EXEMPT, __SUBJ_ALPHA_END, __TO_MALFORMED_2, __TO_NAME, __TO_NAME_DIFF_FROM_ACC, __HAS_REFERENCES, __REFERENCES, __HAS_FROM, FROM_EDU_TLD, __HAS_MSGID, __SANE_MSGID, DATE_TZ_NA, __USER_AGENT, __MOZILLA_USER_AGENT, __MIME_VERSION, __IN_REP_TO, __CT, __CT_TEXT_PLAIN, __CTE, __REPLYTO_SAMEAS_FROM_ADDY, __REPLYTO_SAMEAS_FROM_ACC, __FROM_DOMAIN_IN_ANY_CC2, __REPLYTO_SAMEAS_FROM_DOMAIN, __DKIM_ALIGNS_1, __DKIM_ALIGNS_2, __ANY_URI, __URI_MAILTO, __URI_WITH_PATH, __URI_ENDS_IN_SLASH, __URI_NO_WWW, __CP_URI_IN_BODY, __FRAUD_MONEY_CURRENCY_DOLLAR, __SUBJ_ALPHA_NEGATE, __COURIER_PHRASE, __URI_IN_BODY, __URI_NOT_IMG, __MAIL_CHAIN, [TRUNCATED], so=2010-03-03 19:42:08, dmn=2016-08-03-0138
Received-SPF pass client-ip=129.22.103.227; envelope-from=chet.ramey@case.edu; helo=mpv1-2015.case.edu
X-detected-operating-system by eggs.gnu.org: First seen = 2020/08/06 10:49:02
X-ACL-Warn Detected OS = Linux 2.4.x-2.6.x [generic]
X-Spam_score_int -43
X-Spam_score -4.4
X-Spam_bar ----
X-Spam_report (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no
X-Spam_action no action
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <9b358a76-4867-41b9-5a3a-c1892c76b8ee@case.edu>
X-Mailman-Original-References <20200420051508.GA2359844@zx2c4.com> <7496b183-2db3-6c03-6074-928adcd08f45@case.edu> <CAHmME9pzOY_0EJ69y9wt6r-Jh3frZpV8XdFC6zG5EOkZ99h-1A@mail.gmail.com> <ac79e09f-b4e3-5368-87c1-b6e7147809e2@case.edu> <CAHmME9qNjO+LMxB8py2MDpS2Oprv1mRndgfTXQfXNWyHuwzmjg@mail.gmail.com>
Xref csiph.com gnu.bash.bug:16717

Show key headers only | View raw


On 8/6/20 10:36 AM, Jason A. Donenfeld wrote:
> Hi Chet,
> 
> On Thu, Aug 6, 2020 at 4:30 PM Chet Ramey <chet.ramey@case.edu> wrote:
>>
>> On 8/6/20 6:05 AM, Jason A. Donenfeld wrote:
>>> Hi,
>>>
>>> It may be a surprise to some that this code here winds up printing
>>> "done", always:
>>>
>>> $ cat a.bash
>>> set -e -o pipefail
>>> while read -r line; do
>>>        echo "$line"
>>> done < <(echo 1; sleep 1; echo 2; sleep 1; false; exit 1)
>>> sleep 1
>>> echo done
>>>
>>> $ bash a.bash
>>> 1
>>> 2
>>> done
>>>
>>> The reason for this is that process substitution right now does not
>>> propagate errors. It's sort of possible to almost make this better
>>> with `|| kill $$` or some variant, and trap handlers, but that's very
>>> clunky and fraught with its own problems.
>>>
>>> Therefore, I propose a `set -o substfail` option for the upcoming bash
>>> 5.1, which would cause process substitution to propagate its errors
>>> upwards, even if done asynchronously.
>>>
>>> Chet - thoughts?
>>
>> I don't like it, for two reasons:
>>
>> 1. Process substitution is a word expansion, and, with one exception, word
>>    expansions don't contribute to a command's exit status and
>>    consequently the behavior of errexit, and this proposal isn't compelling
>>    enough to change that even with a new option; and
>>
>> 2. Process substitution is asynchronous. I can't think of how spontaneously
>>    changing $? (and possibly exiting) at some random point in a script when
>>    the shell reaps a process substitution will make scripts more reliable.
> 
> Demi (CC'd) points out that there might be security dangers around
> patterns like:
> 
> while read -r one two three; do
>     add_critical_thing_for "$one" "$two" "$three"
> done < <(get_critical_things)
> 
> If get_critical_things returns a few lines but then exits with a
> failure, the script will forget to call add_critical_thing_for, and
> some kind of door will be held wide open. This is problematic and
> arguably makes bash unsuitable for many of the sysadmin things that
> people use bash for.

If this is a problem for a particular script, add the usual `wait $!'
idiom and react accordingly. If that's not feasible, you can always
use some construct other than process substitution (e.g., a file).
I don't see how this "makes bash unsuitable for many [...] sysadmin
things."

> 
> Perhaps another, clunkier, proposal would be to add `wait -s` so that
> the wait builtin also waits for process substitutions and returns
> their exit codes and changes $?. The downside would be that scripts
> now need to add a "wait" after all of above such loops, but on the
> upside, it's better than the current problematic situation.

You can already do this. Since process substitution sets $!, you can
keep track of all of the process substitutions of interest and wait
for as many of them as you like. `wait' will return their statuses
and set $? for you.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: process substitution error handling Chet Ramey <chet.ramey@case.edu> - 2020-08-06 10:48 -0400

csiph-web