1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Stop the time keyword overriding errexit (#351)

This bug was first reported in <https://www.illumos.org/issues/7694>.
The time keyword currently overrides the errexit shell option,
allowing failing scripts to continue after an error:

  $ cat 1.sh
  #!/bin/sh
  time false   # This should cause the script to exit
  echo FAILURE
  true
  $ ksh -o errexit 1.sh

  real    0m0.00s
  user    0m0.00s
  sys     0m0.00s
  FAILURE

src/cmd/ksh93/sh/xec.c:
- When the time keyword runs a command, pass the errexit state flag
  to the sh_exec call. This state flag is required for ksh to exit
  when a command fails while the errexit option is on.

src/cmd/ksh93/tests/basic.sh:
- Add a regression test based on the reproducer.
This commit is contained in:
Johnothan King 2021-11-29 00:16:23 -08:00 committed by Martijn Dekker
parent f508660ddf
commit a0eeb14787
4 changed files with 21 additions and 2 deletions

View file

@ -601,6 +601,20 @@ eu=$(
)
[[ ${us:1:1} == ${eu:1:1} ]] && err_exit "The time keyword ignores the locale's radix point (both are ${eu:1:1})"
# The time keyword should obey the errexit option
# https://www.illumos.org/issues/7694
time_errexit="$tmp/time_errexit.sh"
cat > "$time_errexit" << 'EOF'
time false
echo FAILURE
true
EOF
got=$($SHELL -e "$time_errexit" 2>&1)
(( $? == 0 )) && err_exit "The time keyword ignores the errexit option" \
"(got $(printf %q "$got"))"
[[ -z $got ]] || err_exit "The time keyword produces output when a timed command fails and the errexit option is on" \
"(got $(printf %q "$got"))"
# ======
# Expansion of multibyte characters after expansion of single-character names $1..$9, $?, $!, $-, etc.
case ${LC_ALL:-${LC_CTYPE:-${LANG:-}}} in