mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-15 04:32:24 +00:00
Fix v=$(<file) for closed FD 0,1,2 (rhbz#1066589)
var=$(< file) now reads the file even if the standard inout, standard output and/or standard error file descriptors are closed. Original patch: https://src.fedoraproject.org/rpms/ksh/blob/642af4d6/f/ksh-20120801-filecomsubst.patch src/cmd/ksh93/sh/io.c: sh_redirect(): - When processing the '<' redirector as part of $(< ...), i.e. if flag==3, make sure the FD of the file to read is > 2 by calling sh_iomovefd(). Unlike the RedHat patch, this checks for flag==3 to avoid unnecessary sh_iomovefd() calls for normal redirections, as there was no bug with those. src/cmd/ksh93/tests/io.sh: - Add test.
This commit is contained in:
parent
5683155cb5
commit
fe6d0903dc
3 changed files with 6 additions and 0 deletions
3
NEWS
3
NEWS
|
@ -9,6 +9,9 @@ Any uppercase BUG_* names are modernish shell bug IDs.
|
|||
to lose the output of the commands they ran. This bug occurred when ksh was
|
||||
compiled with the SHOPT_SPAWN compile-time option.
|
||||
|
||||
- Bugfix: var=$(< file) now reads the file even if the standard inout, standard
|
||||
output and/or standard error file descriptors are closed.
|
||||
|
||||
2020-09-20:
|
||||
|
||||
- Bugfix: when whence -v/-a found an "undefined" (i.e. autoloadable) function
|
||||
|
|
|
@ -1266,6 +1266,8 @@ int sh_redirect(Shell_t *shp,struct ionod *iop, int flag)
|
|||
if(flag==SH_SHOWME)
|
||||
goto traceit;
|
||||
fd=sh_chkopen(fname);
|
||||
if(flag==3) /* make sure that $(<file) works... */
|
||||
fd=sh_iomovefd(fd); /* ...with stdin/stdout/stderr closed */
|
||||
}
|
||||
else if(sh_isoption(SH_RESTRICTED))
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted,fname);
|
||||
|
|
|
@ -462,6 +462,7 @@ got=$(<$tmp/22.out)
|
|||
|
||||
tmp=$tmp $SHELL 2> /dev/null -c 'exec 3<&1 ; exec 1<&- ; exec > $tmp/outfile;print foobar' || err_exit 'exec 1<&- causes failure'
|
||||
[[ $(<$tmp/outfile) == foobar ]] || err_exit 'outfile does not contain foobar'
|
||||
[[ $(<$tmp/outfile) == foobar ]] <&- >&- 2>&- || err_exit '$(<file) does not work with stdin, stdout and/or stderr closed'
|
||||
|
||||
print hello there world > $tmp/foobar
|
||||
sed -e 's/there //' $tmp/foobar >; $tmp/foobar
|
||||
|
|
Loading…
Reference in a new issue