mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-13 19:52:20 +00:00
Fix 'redirect {var}>file' in subshell (re: 7b82c338
)
Permanent redirections of that form broke in subshells when used
with the 'redirect' command, because I had overlooked one instance
where the new 'redirect' builtin needs to match the behaviour of
the 'exec' builtin.
src/cmd/ksh93/tests/io.sh: sh_exec():
- Do not restore file descriptors in (virtual) subshells for
'redirect' just as this isn't done for 'exec'.
src/cmd/ksh93/tests/io.sh:
- Add regression test for this bug.
- Complete the test for f9427909
which I committed prematurely.
Fixes: https://github.com/ksh93/ksh/issues/167
This commit is contained in:
parent
f9427909dc
commit
7b59fb805c
2 changed files with 9 additions and 4 deletions
|
@ -1401,8 +1401,8 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
sh_unscope(shp);
|
sh_unscope(shp);
|
||||||
bp->ptr = (void*)save_ptr;
|
bp->ptr = (void*)save_ptr;
|
||||||
bp->data = (void*)save_data;
|
bp->data = (void*)save_data;
|
||||||
/* don't restore for subshell exec */
|
/* don't restore for 'exec' or 'redirect' in subshell */
|
||||||
if((shp->topfd>topfd) && !(shp->subshell && np==SYSEXEC))
|
if((shp->topfd>topfd) && !(shp->subshell && (np==SYSEXEC || np==SYSREDIR)))
|
||||||
sh_iorestore(shp,topfd,jmpval);
|
sh_iorestore(shp,topfd,jmpval);
|
||||||
|
|
||||||
shp->redir0 = 0;
|
shp->redir0 = 0;
|
||||||
|
|
|
@ -698,8 +698,13 @@ got=$(export tmp; "$SHELL" -ec \
|
||||||
|
|
||||||
# ======
|
# ======
|
||||||
# Redirections of the form {varname}>file stopped working if brace expansion was turned off
|
# Redirections of the form {varname}>file stopped working if brace expansion was turned off
|
||||||
redirect {v}>$tmp/v.out; echo ok >&$v
|
set +B
|
||||||
[[ $(<$tmp/v.out) == ok ]] || err_exit '{varname}>file not working with brace expansion turned off'
|
{ redirect {v}>$tmp/v.out && echo ok >&$v; } 2>/dev/null
|
||||||
|
set -B
|
||||||
|
[[ -r $tmp/v.out && $(<$tmp/v.out) == ok ]] || err_exit '{varname}>file not working with brace expansion turned off'
|
||||||
|
# ...and they didn't work in subshells: https://github.com/ksh93/ksh/issues/167
|
||||||
|
(redirect {v}>$tmp/v.out; echo ok2 >&$v) 2>/dev/null
|
||||||
|
[[ -r $tmp/v.out && $(<$tmp/v.out) == ok2 ]] || err_exit 'redirect {varname}>file not working in a subshell'
|
||||||
|
|
||||||
# ======
|
# ======
|
||||||
exit $((Errors<125?Errors:125))
|
exit $((Errors<125?Errors:125))
|
||||||
|
|
Loading…
Reference in a new issue