Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #16720
| Path | csiph.com!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 11:53:00 -0400 |
| Organization | ITS, Case Western Reserve University |
| Lines | 110 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.1031.1596729190.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> <CAHmME9qHEtsri_jYdqppSXwYFLH3Os06xS7wsM00z2dNgHgwyg@mail.gmail.com> <ae4fce5c-32df-fab5-f521-7b405d444b42@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 1596729190 5558 209.51.188.17 (6 Aug 2020 15:53:10 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=1596729185; bh=730eHDpgW8yDu8t0eKGjxwYww+PIbCpR2zNDz2KgmII=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=0PqmedCMn2GZwBbZl+DwWBpoUgkY9/GhIKaoBOTtdlYaC8rU8IlUZYYoHtPtq4P+YP aZnOK9ezsWQ1muPJ2nbYmmYMEcHhiv2Xl2EAKyrttXgwW/+gb6Ax509/ho88Q2zSKSt 4dj0pYmCoY7vigGZfbHmIxui6mwKsQjof9LkiegwXeHkwasRDz1HbMICIoDg/Mrd29M B40eIkagXIzGXFqvZ7al2wi624KhRRdsMcYYogvzVXTTmLhIrpu8+Kx90DyezCbjPeu GG3tv+duASdWaAdCNvJbtVw392wpJiva8uXARDP5FAnRvYkJQYHsQHJf2KqCN7mdap4 IssU5niw== |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1596729183; bh=sWTUSaVUPvshS/ms8V7lnEGGFdg4Zm2XSvf27gsJvsE=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=1owcAuke1m4T+Mxvdh18Qx5RKfel7zSD8pGcFzIL4pIiOlaOI18iUq+peMz2p+JOGc /V11tiffQy236UU9W1cQSfkwQRcePyiXprry278FEdZZVHpmV34A2Bd62MCpPvWyWSl GDyAUc1zIJD+2PzF6GoY+AwMR4qFwDwDUvXxm8dP46K9/mlEdAMMUEM2shKRgIkHfcn B04/EBN9r4aX9k5WpNFxzDykgDh2b6DefMRlXTdLzoODNHkFrOZph+TTUjuWzaMCt+x DwFiMMxBVg82S+KX97S/IWbn6Wc8VXESO/XG329SCuW7Jpb35OKxXIke+Wlc/SqbNgR grLxMyCg== |
| 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=sWTUSaVUPvshS/ms8V7lnEGGFdg4Zm2XSvf27gsJvsE=; b=Q/gjl54dq0xYiW0OtdgkUQ/LLqsIX9kSFaVSdBFSl9t5Mwx+8yLBOToNh53gZMMoDl 7gnWuRYEhfenctcmiCDFdYCSIgO0xRP9/+pSNOH5ZbDN7dj+kJ4jmWzQrPD5r3TnNSap 9+e4EBMdRFQ3XOXXl/06H6q1SDkrl8jbSuuM6LijHu0dCyJOmiYX8QsPVlAMab/uO57w E3Ml7q3kKBuGkwHkvXJbM69JW//Fa63q35lwy63hyJM3P1RwzwWFyOrdny3f3SLvRTEK 6GCt7Ym1u4dal7yc14tG8dxJXpJmy6skn+ZyfvAISvg9tdSkkfbpjusWd45hxAEkrWdu asoQ== |
| 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=sWTUSaVUPvshS/ms8V7lnEGGFdg4Zm2XSvf27gsJvsE=; b=RfEp8DptB5QDAJgPs424RzstUTBCmuswp5ZqpvebSxfKHGFwtdLtWZcisqmIbywafM JR2ofjWEET+Bf1DlDQ0JrWZo7HADsg1YckLUF9O18m3XxGY4ogVvoZ54a8yzAbylvkDV se3eyVGPwqEQPxPTbV2MPPbVpeR6A12meY1cBHwzQVLZptrMc5Vj+rPMDNfW0tpv2Mqz vO0m07bsztXlEJBNPoUFgmvZk9D4BOhDId+aueGaUEEB+DDkMT95XVWIYzwb+Hyz8MX1 18jU3zb5YlPCq409ivhDklG8GkDBREEo5kYSpMfEKtxWxOit8cWwDTjFPCg4zQKBRL/C V61w== |
| X-Gm-Message-State | AOAM532Gsiqz8pGQGidbPfN5KgAEvLpHiDfjQpY4oS22/Dvp7H2ZKAU0 v1MDGxDHfSjMvuIxmTlzYfUGWPx/5RPtziuUQUxS0YNK6r6Gy92rcCbAySZulivae/VlZWWtGno qmFmhq4qiI2E= |
| X-Received | by 2002:a37:61d4:: with SMTP id v203mr9741478qkb.390.1596729182705; Thu, 06 Aug 2020 08:53:02 -0700 (PDT) |
| X-Google-Smtp-Source | ABdhPJzMP8WGRXPD3rkDs6Sd4MowjakR5y4i824HWT0kMh/e+nqlOb0SQJbJstA0eEdSAe3AyEg2RA== |
| X-Received | by 2002:a37:61d4:: with SMTP id v203mr9741448qkb.390.1596729182362; Thu, 06 Aug 2020 08:53:02 -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 | <CAHmME9qHEtsri_jYdqppSXwYFLH3Os06xS7wsM00z2dNgHgwyg@mail.gmail.com> |
| Content-Language | en-US |
| X-Mirapoint-IP-Reputation | reputation=Good-1, source=Queried, refid=tid=0001.0A020301.5F2C1EEF.00E1, actions=tag |
| X-Mirapoint-IP-Reputation | reputation=good-1, source=Fixed, refid=n/a, actions=tag |
| X-Junkmail-Status | score=8/80, host=mpv3-2015.case.edu |
| X-Junkmail-PrAS-Raw | score=8/80, refid=2.7.2:2020.8.6.145718: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, __BITCOIN_ADDRESS_OBFU, __URI_IN_BODY, __URI_NOT_IMG, [TRUNCATED], so=2010-03-03 19:42:08, dmn=2016-08-03-0138 |
| Received-SPF | pass client-ip=129.22.103.194; envelope-from=chet.ramey@case.edu; helo=mpv3-2015.case.edu |
| X-detected-operating-system | by eggs.gnu.org: First seen = 2020/08/06 11:53:04 |
| 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 | <ae4fce5c-32df-fab5-f521-7b405d444b42@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> <9b358a76-4867-41b9-5a3a-c1892c76b8ee@case.edu> <CAHmME9qHEtsri_jYdqppSXwYFLH3Os06xS7wsM00z2dNgHgwyg@mail.gmail.com> |
| Xref | csiph.com gnu.bash.bug:16720 |
Show key headers only | View raw
On 8/6/20 11:31 AM, Jason A. Donenfeld wrote: > On Thu, Aug 6, 2020 at 4:49 PM Chet Ramey <chet.ramey@case.edu> wrote: >> >> 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. > > That doesn't always work: Because you have structured the loop so it's difficult to save the last asynchronous command you want outside of it? There's an easy fix for that: decide what your priority is and write code in a way to make that happen. > > set -e > while read -r line; do > echo "$line" & > done < <(echo 1; sleep 1; echo 2; sleep 1; exit 77) > sleep 1 > wait $! > echo done > Either way, tagging on `wait $!` everywhere, and hoping it works like > I want feels pretty flimsy. Are you sure you're opposed to set -o > procsuberr that would do the right thing for most common use cases? Yes, I don't think there's real consensus on what the right thing is, and "most common use cases" is already possible with existing features. There will be more support in bash-5.1 to make certain use cases easier, but at least they will be deterministic. I don't think introducing more non-determinism into the shell is helpful. -- ``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
Re: process substitution error handling Chet Ramey <chet.ramey@case.edu> - 2020-08-06 11:53 -0400
csiph-web