mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix BUG_PUTIOERR: Check for and report I/O error in output builtins
This allows scripts to check for a nonzero exit status on the 'print', 'printf' and 'echo' builtins and prevent possible infinite loops if SIGPIPE is ignored. sfsync() was already returning a negative value on I/O error, so all we need to do is add a check. The stream buffer will need to be filled before an I/O error can be detected, but this is the same on other shells. See manual page: src/lib/libast/man/sfio.3 Ref.: https://github.com/att/ast/issues/1093 https://github.com/att/ast/pull/1363 src/cmd/ksh93/bltins/print.c: b_print(): - Make sure an error result from sfsync() is reflected in the output builtin's exit status (exitval). - Write an I/O error message (e_io) if the exit status is nonzero. src/cmd/ksh93/data/msg.c, src/cmd/ksh93/include/io.h: - Add the e_io[] error message. src/cmd/ksh93/tests/builtins.sh: - Add I/O error regression test, checking for the correct error message and exit status. All three output builtins use the same b_print() function so we only need to test one. src/cmd/ksh93/tests/basic.sh, src/cmd/ksh93/tests/coprocess.sh: - Redirect stderr on a few 'print' commands to /dev/null; these now issue an expected I/O error. This does not cause failures. NEWS, TODO: - Update. (cherry picked from commit 9011fa933552e483dab460f7dd1593d64e059d94)
This commit is contained in:
parent
846ad93272
commit
93e15a3035
8 changed files with 45 additions and 13 deletions
|
|
@ -431,7 +431,7 @@ done | while read sec; do ( $sleep $sec; $sleep $sec) done
|
|||
s=SECONDS
|
||||
set -o pipefail
|
||||
for ((i=0; i < 30; i++))
|
||||
do print hello
|
||||
do print hello 2>/dev/null
|
||||
sleep .1
|
||||
done | $sleep 1
|
||||
(( (SECONDS-s) < 2 )) || err_exit 'early termination not causing broken pipe'
|
||||
|
|
@ -470,7 +470,7 @@ bintrue=$(whence -p true)
|
|||
set -o pipefail
|
||||
float start=$SECONDS end
|
||||
for ((i=0; i < 2; i++))
|
||||
do print foo
|
||||
do print foo 2>/dev/null
|
||||
sleep 1.5
|
||||
done | { read; $bintrue; end=$SECONDS ;}
|
||||
(( (SECONDS-start) < 1 )) && err_exit "pipefail not waiting for pipe to finish"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue