mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix I/O redirection in -c script (Solaris patch 280-23332860)
This change is pulled from here: https://github.com/oracle/solaris-userland/blob/master/components/ksh93/patches/280-23332860.patch Info and reproducers: https://github.com/att/ast/issues/36 In a -c script (like ksh -c 'commands'), the last command misredirects standard output if an EXIT or ERR trap is set. This appears to be a side effect of the optimisation that runs the last command without forking. This applies a patch by George Lijo that flags these specific cases and disables the optimisation. src/cmd/ksh93/include/defs.h, src/cmd/ksh93/bltins/trap.c, src/cmd/ksh93/sh/init.c, src/cmd/ksh93/sh/main.c, src/cmd/ksh93/sh/xec.c: - Apply patch as above. src/cmd/ksh93/tests/io.sh: - Add the reproducers from the bug report as regression tests.
This commit is contained in:
parent
7c47ab56fe
commit
17ebfbf6a3
6 changed files with 78 additions and 1 deletions
|
@ -649,5 +649,53 @@ err=$(
|
|||
((!(e = $?))) || err_exit 'crash on null-command redirection with DEBUG trap' \
|
||||
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
|
||||
|
||||
# ======
|
||||
# stdout was misdirected if an EXIT/ERR trap handler was defined in a -c script
|
||||
# https://github.com/att/ast/issues/36
|
||||
exp=$'exit to stdout\ntrap to stdout'
|
||||
exp2=$'exit to file\ntrap to file'
|
||||
got=$(export tmp; "$SHELL" -ec \
|
||||
' function log
|
||||
{
|
||||
echo "$* to stdout"
|
||||
echo "$* to file" >> $tmp/ast36_a.test.log
|
||||
}
|
||||
function test_exit
|
||||
{
|
||||
log trap
|
||||
}
|
||||
trap test_exit EXIT
|
||||
log exit
|
||||
')
|
||||
[[ $got == "$exp" ]] || err_exit 'stdout misdirected to file with EXIT/ERR trap defined (1)' \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
[[ $(< $tmp/ast36_a.test.log) == "$exp2" ]] || err_exit 'stdout not correctly redirected to file with EXIT/ERR trap defined (1)' \
|
||||
"(expected $(printf %q "$exp2"), wrote $(printf %q "$(< $tmp/ast36_a.test.log)"))"
|
||||
|
||||
exp=$'trap to stdout\nexit to stdout'
|
||||
exp2=$'trap to file\nexit to file'
|
||||
got=$(export tmp; "$SHELL" -ec \
|
||||
' function log
|
||||
{
|
||||
echo "$* to stdout"
|
||||
echo "$* to file" >> $tmp/ast36_b.test.log
|
||||
}
|
||||
function test_exit
|
||||
{
|
||||
trap test_exittrap EXIT
|
||||
log trap
|
||||
}
|
||||
function test_exittrap
|
||||
{
|
||||
log exit
|
||||
}
|
||||
test_exit
|
||||
')
|
||||
[[ $got == "$exp" ]] || err_exit 'stdout misdirected to file with EXIT/ERR trap defined (2)' \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
[[ $(< $tmp/ast36_b.test.log) == "$exp2" ]] || err_exit 'stdout not correctly redirected to file with EXIT/ERR trap defined (2)' \
|
||||
"(expected $(printf %q "$exp2"), wrote $(printf %q "$(< $tmp/ast36_b.test.log)"))"
|
||||
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue