1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

sh_exec(): do not simulate close-on-exec for (very few) built-ins

The question-everything department is productive today.

When executing a built-in, ksh checks execflg, which is set if the
command is run in a location where an exec optimisation would take
place if the command were an external command (i.e. if it's the
last command in the script). In that case, and if there are no
traps, and we're not running a function (which we wouldn't anyway
if execflg is set), and the built-in does not have the BLT_ENV
attribute, ksh simulates close-on-exec by manually closing the file
descriptors with the IOCLEX attribute before running the built-in.

This is yet another thing that makes no sense:
- The command is a built-in. There is no exec, so close-on-exec
  should not happen.
- Why only for the last command in the script? For external
  commands, close-on-exec happens regardless of the command's
  location, because external commands fork, then exec. So if this
  was meant to introduce behavioural consistency between externals
  and built-ins: FAIL
- Why only for built-ins without the BLT_ENV attribute? There are
  only a few of them (see data/builtins.c).

Researching ksh93-history shows that this code was introduced in
2005-03-19 ksh93q+. The changes in ksh93/RELEASE in that commit
have a couple of entries that could be superficially related, but
nothing directly relevant. It also introduced several regression
tests that are still present, and none of them fail after we delete
this. So, this looks like yet more undocumented nonsense.
This commit is contained in:
Martijn Dekker 2022-06-10 13:29:29 +01:00
parent f51e54828e
commit ed5d561a72

View file

@ -1319,15 +1319,6 @@ int sh_exec(register const Shnode_t *t, int flags)
bp->flags = (OPTIMIZE!=0);
if(sh.subshell && nv_isattr(np,BLT_NOSFIO))
sh_subtmpfile();
if(execflg && !sh.subshell &&
!sh.st.trapcom[0] && !sh.st.trap[SH_ERRTRAP] && sh.fn_depth==0 && !nv_isattr(np,BLT_ENV))
{
/* do close-on-exec */
int fd;
for(fd=0; fd < sh.lim.open_max; fd++)
if((sh.fdstatus[fd]&IOCLEX)&&fd!=sh.infd)
sh_close(fd);
}
if(argn)
sh.exitval = (*sh.bltinfun)(argn,com,(void*)bp);
if(error_info.flags&ERROR_INTERACTIVE)