1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-04 23:35:36 -08:00
openbsd-src/regress
kn f8c806b8e6 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
2022-10-10 14:57:48 +00:00
..
bin Trigger ERR trap on permanent I/O redirection failure 2022-10-10 14:57:48 +00:00
etc Bring this regress into nicer shape. Add all recent architectures. 2021-09-27 18:27:14 +00:00
gnu Add subdir gnu/lib to regress. 2022-03-23 22:34:51 +00:00
include
lib Dynamically link libssl for QUIC regress. 2022-10-02 16:40:56 +00:00
libexec add ld.so RTLD_NOLOAD regress tests, ok jca@ guenther@ 2022-08-20 14:13:48 +00:00
misc remove swblk_t type from sys/types.h 2022-08-06 13:31:13 +00:00
sbin Increase the auto partitioner's maximum /usr size to 30G. 2022-06-25 19:19:39 +00:00
sys two tests are now expected to fail since the introduction of mimmutable 2022-10-10 05:26:11 +00:00
usr.bin The sysORTable doesn't have 10 entries anymore. 2022-09-02 07:07:45 +00:00
usr.sbin Continue tests is the mountpoint already exists 2022-10-10 11:06:14 +00:00
Makefile Remove all references to "make depend" from regress. 2017-07-07 23:55:21 +00:00