#990270 zsh: incorrect handling of EBADF for builtins

Package:
zsh
Source:
zsh
Description:
shell with lots of features
Submitter:
Vincent Lefevre
Date:
2021-06-24 10:27:03 UTC
Severity:
normal
Tags:
#990270#5
Date:
2021-06-24 10:22:06 UTC
From:
To:
zsh does not always handle output error correctly, e.g. with
closed stdout (yielding EBADF). For instance:

zira% (exec >&-; echo; echo $? >&2)
zsh: write error: bad file descriptor
0
zira% (exec >&-; echo >&-; echo $? >&2)
0
zira% (exec >&-; print; echo $? >&2)
zsh: write error: bad file descriptor
0
zira% (exec >&-; print >&-; echo $? >&2)
0
zira% (exec >&-; pwd; echo $? >&2)
zsh: write error: bad file descriptor
0
zira% (exec >&-; pwd >&-; echo $? >&2)
0
zira% (exec >&-; history; echo $? >&2)
zsh: write error: bad file descriptor
0
zira% (exec >&-; history >&-; echo $? >&2)
0

There are 2 issues:

1. The exit status is always 0 instead of non-zero.

2. The error message is missing when stdout is closed in the same
command.

According to

https://www.zsh.org/mla/workers/2021/msg01267.html

EBADF is treated specially, at least for echo. See

https://www.zsh.org/mla/workers/2021/msg01335.html

about the history.