diff options
author | Klemens Nanni <kn@cvs.openbsd.org> | 2022-10-10 14:57:49 +0000 |
---|---|---|
committer | Klemens Nanni <kn@cvs.openbsd.org> | 2022-10-10 14:57:49 +0000 |
commit | db3a254828f442987d861024611a21558590f1c2 (patch) | |
tree | 40b9ce2817efb771fe8b90cb6caaa67683906320 /sys/dev/fdt | |
parent | 1279f37fb50fab454492d6a2ec8aec43e6d0c953 (diff) |
Trigger ERR trap on permanent I/O redirection failure
The following three cases behave identical in bash(1), but our ksh
(ksh93 also) fails to run the trap in the last case:
(non-zero exit code is trigger, no redirection)
$ ksh -c 'trap "echo ERR" ERR ; false'
ERR
(failed redirection is trigger, 'echo' was not executed)
$ ksh -c 'trap "echo ERR" ERR ; echo >/'
ksh: cannot create /: Is a directory
ERR
(failed redirection, no execution, trap was NOT triggered)
$ ksh -c 'trap "echo ERR" ERR ; exec >/'
ksh: cannot create /: Is a directory
bash(1) prints "ERR" in all three cases, as expected.
ksh93 behaves like our ksh(1).
In ksh `exec' is a builtin (CSHELL), but also special (SPEC_BI):
$ type alias
alias is a shell builtin
$ type exec
exec is a special shell builtin
Without command and redirection alone, `exec' permanently redirects I/O for
the shell itself, not executing anything; it is the only (special) builtin
with such a special use-case, implemented as c_sh.c:c_exec().
This corner-case is overlooked in exec.c:execute() which handles iosetup()
failure for all commands, incl. builtins.
Exclude c_exec() from the rest of special builtins to ensure it runs the
ERR trap as expected:
$ ./obj/ksh -c 'trap "echo ERR" ERR ; exec >/'
ksh: cannot create /: Is a directory
ERR
Also add three new regress cases covering this; rest keep passing.
OK millert
Diffstat (limited to 'sys/dev/fdt')
0 files changed, 0 insertions, 0 deletions