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


Groups > gnu.bash.bug > #16716

Re: process substitution error handling

Path csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From "Jason A. Donenfeld" <Jason@zx2c4.com>
Newsgroups gnu.bash.bug
Subject Re: process substitution error handling
Date Thu, 6 Aug 2020 16:36:38 +0200
Lines 66
Approved bug-bash@gnu.org
Message-ID <mailman.1017.1596724617.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>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
X-Trace usenet.stanford.edu 1596724617 2668 209.51.188.17 (6 Aug 2020 14:36:57 GMT)
X-Complaints-To action@cs.stanford.edu
Cc bug-bash@gnu.org, "Demi M. Obenour" <demiobenour@gmail.com>
To Chester Ramey <chet.ramey@case.edu>
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=mime-version :references:in-reply-to:from:date:message-id:subject:to:cc :content-type; s=mail; bh=P/xJxbByGaj8EGQJVClUxkJkLsQ=; b=a+pHRo s+leQb2HwgRdZ5vplPiPQcitRjOOYeQSJwzyQnynRT0D1KfRGSarPbyLFzuZiogw V1+edUZZ/4M7o6Foa2yXNomU7DVErbOotzT6a55Ht/UW6RDlgh94nIjiuaX1z2Za x9nj4RJL8BOWlwUPkye/WpEc9qa6C9yGAIIDK7/HEPYS8GC09LVhSYKZygNqJUsh oFivd+NfHa5x2QOJGlgkJsIQIhE2Ci9oHGM7vos28I5LLo2imLP9WaF8XH4K/IOz jkZmU9aIjE6IvyAsh94GoR+1PHUFZBx58MEw6jqns1rEBody6RdsGfRsBlWueYWw ksQ7Z4tTb5w46bQg==
X-Gm-Message-State AOAM530+IlCxJwvdhWKh0L+EdgupIgk2HJY2uXxUTLrDLuTZfqqYfMCw tzBkA7Vg/Yfex2raszpD12k1m3de5wCj+HGNnt0=
X-Google-Smtp-Source ABdhPJzVdaDDmw3CtG3SW/vaYNln2TA7DVGkUAstymQSQ+sb0tPTmQU2qAvK6A2RyCdvDmBPToukEYLjpLCAZSphFNE=
X-Received by 2002:a6b:b211:: with SMTP id b17mr10580447iof.29.1596724611248; Thu, 06 Aug 2020 07:36:51 -0700 (PDT)
In-Reply-To <ac79e09f-b4e3-5368-87c1-b6e7147809e2@case.edu>
X-Gmail-Original-Message-ID <CAHmME9qNjO+LMxB8py2MDpS2Oprv1mRndgfTXQfXNWyHuwzmjg@mail.gmail.com>
Received-SPF pass client-ip=192.95.5.64; envelope-from=Jason@zx2c4.com; helo=mail.zx2c4.com
X-detected-operating-system by eggs.gnu.org: First seen = 2020/08/06 10:36:52
X-ACL-Warn Detected OS = Linux 3.11 and newer
X-Spam_score_int -20
X-Spam_score -2.1
X-Spam_bar --
X-Spam_report (-2.1 / 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, 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 <CAHmME9qNjO+LMxB8py2MDpS2Oprv1mRndgfTXQfXNWyHuwzmjg@mail.gmail.com>
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>
Xref csiph.com gnu.bash.bug:16716

Show key headers only | View raw


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.

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.

Jason

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


Thread

Re: process substitution error handling "Jason A. Donenfeld" <Jason@zx2c4.com> - 2020-08-06 16:36 +0200

csiph-web