[Bug 224270] Get exit status of process that's piped to another: set -o pipefail is missing for /bin/sh

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Sun Feb 24 21:06:20 UTC 2019


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=224270

--- Comment #12 from commit-hook at freebsd.org ---
A commit references this bug:

Author: jilles
Date: Sun Feb 24 21:05:16 UTC 2019
New revision: 344502
URL: https://svnweb.freebsd.org/changeset/base/344502

Log:
  sh: Add set -o pipefail

  The pipefail option allows checking the exit status of all commands in a
  pipeline more easily, at a limited cost of complexity in sh itself. It works
  similarly to the option in bash, ksh93 and mksh.

  Like ksh93 and unlike bash and mksh, the state of the option is saved when a
  pipeline is started. Therefore, even in the case of commands like
    A | B &
  a later change of the option does not change the exit status, the same way
    (A | B) &
  works.

  Since SIGPIPE is not handled specially, more work in the script is required
  for a proper exit status for pipelines containing commands such as head that
  may terminate successfully without reading all input. This can be something
  like

  (
          cmd1
          r=$?
          if [ "$r" -gt 128 ] && [ "$(kill -l "$r")" = PIPE ]; then
                  exit 0
          else
                  exit "$r"
          fi
  ) | head

  PR:           224270
  Relnotes:     yes

Changes:
  head/bin/sh/jobs.c
  head/bin/sh/options.h
  head/bin/sh/sh.1
  head/bin/sh/tests/execution/Makefile
  head/bin/sh/tests/execution/pipefail1.0
  head/bin/sh/tests/execution/pipefail2.42
  head/bin/sh/tests/execution/pipefail3.42
  head/bin/sh/tests/execution/pipefail4.42
  head/bin/sh/tests/execution/pipefail5.42
  head/bin/sh/tests/execution/pipefail6.42
  head/bin/sh/tests/execution/pipefail7.0

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list