1
0
Fork 0
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:
Martijn Dekker 2020-09-01 08:11:27 +01:00
parent b301d41731
commit fd977388a2
4 changed files with 13 additions and 2 deletions

View file

@ -1094,7 +1094,7 @@ int sh_redirect(Shell_t *shp,struct ionod *iop, int flag)
Namval_t *np=0;
int isstring = shp->subshell?(sfset(sfstdout,0,0)&SF_STRING):0;
if(flag==2)
if(flag==2 && !sh_isoption(SH_POSIX))
clexec = 1;
if(iop)
traceon = sh_trace(shp,NIL(char**),0);