At Sun, 11 Apr 2021 01:37:44 +0700, Robert Elz <kre%munnari.OZ.AU@localhost> wrote: Subject: Re: Possible "new" redirect style for /bin/sh (needs a name) > > Because of the way the system calls work: everything allocating fds (in the > kernel) allocates upwards. So, still, the shell could keep a "high FD watermark" for the range of the FDs allocated by "{var}>file" and open them the normal way then move them with dup2() to the next lower (i.e. unused) FD below this high FD watermark, and reduce it in turn. If I'm not mistaken the initial value for the high FD watermark could be set to sysconf(_SC_OPEN_MAX)-1. I.e. the range would be the dynamic range N..sysconf(_SC_OPEN_MAX)-1, where N is the most recent FD opened by this feature and the next opened this way would be N=N-1. The documentation can simply say that any attempt to explicitly redirect to or from a file descriptor numbered at or higher than the current high FD watermark would result in "Undefined Behaviour". Perhaps the current high FD watermark could even be exposed to the user with a new shell variable such as ${CUR_MAX_FD}, but also/instead the shell could emit a warning if a script/user tries to do a redirection like NNN>file where NNN is greater than N-1. Possibly this should even be an error that (un-trapped) would terminate the script (or return an interactive shell to the REPL). > And second, we need a name for the generic facility, so we have some way to > refer to it (and also use as a sub-section heading for the man page, > and a test case name for (yet to be written) ATF tests of this) The only thing that immediately jumped into my mind was "dynamic redirection". Maybe Steve Bourne could suggest a name? (seriously) -- Greg A. Woods <gwoods%acm.org@localhost> Kelowna, BC +1 250 762-7675 RoboHack <woods%robohack.ca@localhost> Planix, Inc. <woods%planix.com@localhost> Avoncote Farms <woods%avoncote.ca@localhost>
Attachment:
pgpWAKES_v0wI.pgp
Description: OpenPGP Digital Signature