mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
-o posix: allow invoked programs to inherit FDs > 2
If there are file descriptors > 2 opened with 'exec' or 'redirect', ksh93 has always closed them when invoking another pogram. This is contrary to POSIX which states: Utilities other than the special built-ins […] shall be invoked in a separate environment that consists of the following. The initial value of these objects shall be the same as that for the parent shell, except as noted below. * Open files inherited on invocation of the shell, open files controlled by the exec special built-in plus any modifications, and additions specified by any redirections to the utility * […] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_12 src/cmd/ksh93/sh/io.c: sh_redirect(): - When flag==2, do not close FDs > 2 if POSIX mode is active. src/cmd/ksh93/tests/io.sh: - Regress-test inheriting FD 7 with and without POSIX mode. src/cmd/ksh93/sh.1: - Update.
This commit is contained in:
parent
b301d41731
commit
fd977388a2
4 changed files with 13 additions and 2 deletions
1
NEWS
1
NEWS
|
@ -16,6 +16,7 @@ Any uppercase BUG_* names are modernish shell bug IDs.
|
||||||
* disables the &> redirection shorthand
|
* disables the &> redirection shorthand
|
||||||
* causes the 'let' arithmetic command to recognise octal numbers by
|
* causes the 'let' arithmetic command to recognise octal numbers by
|
||||||
leading zeros regardless of the setting of the 'letoctal' option
|
leading zeros regardless of the setting of the 'letoctal' option
|
||||||
|
* causes file descriptors > 2 to be left open when invoking another program
|
||||||
|
|
||||||
2020-08-19:
|
2020-08-19:
|
||||||
|
|
||||||
|
|
|
@ -6817,7 +6817,8 @@ command.
|
||||||
Any file descriptor numbers greater than
|
Any file descriptor numbers greater than
|
||||||
.B 2
|
.B 2
|
||||||
that are opened with this mechanism are closed when invoking another program,
|
that are opened with this mechanism are closed when invoking another program,
|
||||||
unless explicitly redirected to themselves as part of that invocation.
|
unless they are explicitly redirected to themselves as part of that invocation
|
||||||
|
(e.g. \fb4>&4\fR) or the \fBposix\fR shell option is active.
|
||||||
.TP
|
.TP
|
||||||
\(dg \f3return\fP \*(OK \f2n\^\fP \*(CK
|
\(dg \f3return\fP \*(OK \f2n\^\fP \*(CK
|
||||||
Causes a shell
|
Causes a shell
|
||||||
|
@ -7038,6 +7039,7 @@ to fail or zero if no command has failed.
|
||||||
.B posix
|
.B posix
|
||||||
Enable POSIX standard compatibility mode. This option
|
Enable POSIX standard compatibility mode. This option
|
||||||
is on by default if ksh is invoked as \fBsh\fR. It
|
is on by default if ksh is invoked as \fBsh\fR. It
|
||||||
|
causes file descriptors > 2 to be left open when invoking another program,
|
||||||
enables octal numbers in \fBlet\fR shell arithmetic (see \fBletoctal\fR), and
|
enables octal numbers in \fBlet\fR shell arithmetic (see \fBletoctal\fR), and
|
||||||
disables the \fB&>\fR redirection shorthand.
|
disables the \fB&>\fR redirection shorthand.
|
||||||
.TP 8
|
.TP 8
|
||||||
|
|
|
@ -1094,7 +1094,7 @@ int sh_redirect(Shell_t *shp,struct ionod *iop, int flag)
|
||||||
Namval_t *np=0;
|
Namval_t *np=0;
|
||||||
int isstring = shp->subshell?(sfset(sfstdout,0,0)&SF_STRING):0;
|
int isstring = shp->subshell?(sfset(sfstdout,0,0)&SF_STRING):0;
|
||||||
|
|
||||||
if(flag==2)
|
if(flag==2 && !sh_isoption(SH_POSIX))
|
||||||
clexec = 1;
|
clexec = 1;
|
||||||
if(iop)
|
if(iop)
|
||||||
traceon = sh_trace(shp,NIL(char**),0);
|
traceon = sh_trace(shp,NIL(char**),0);
|
||||||
|
|
|
@ -616,5 +616,13 @@ then set -o posix
|
||||||
[[ $(< aha2.txt) == ok2 ]] || err_exit '&> does not redirect stderr'
|
[[ $(< aha2.txt) == ok2 ]] || err_exit '&> does not redirect stderr'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# In POSIX mode, file descriptors > 2 should remain open when invoking another proram
|
||||||
|
if [[ -o ?posix ]]
|
||||||
|
then (set -o posix; exec 7>ok.txt; "$SHELL" -c 'print ok >&7' 2>/dev/null)
|
||||||
|
[[ $(<ok.txt) == ok ]] || err_exit 'File descriptors > 2 not inherited in POSIX mode'
|
||||||
|
fi
|
||||||
|
(exec 7>bad.txt; "$SHELL" -c 'print bad >&7' 2>/dev/null)
|
||||||
|
[[ $(<bad.txt) == '' ]] || err_exit 'File descriptors > 2 inherited without POSIX mode' "(got $actual)"
|
||||||
|
|
||||||
# ======
|
# ======
|
||||||
exit $((Errors<125?Errors:125))
|
exit $((Errors<125?Errors:125))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue