tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Possible "new" redirect style for /bin/sh (needs a name)



On Sun, Apr 11, 2021 at 09:53:34AM -0700, Greg A. Woods wrote:
> At Sun, 11 Apr 2021 09:05:57 +0200, tlaronde%polynum.com@localhost wrote:
> Subject: Re: Possible "new" redirect style for /bin/sh (needs a name)
> >
> > On Sat, Apr 10, 2021 at 05:04:11PM -0700, Greg A. Woods wrote:
> > >
> > > 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 thought of this "mapping" too (using big numbers for "named fds" but
> > mapping them to real small ones).
> 
> not "mapping" -- "moving".
> 
> and not moving them to small ones, but using the automatically allocated
> next-higher number from open() and moving it up to the top of the
> available range
> 
> dup2() (and dup3()) lets the caller specify the new FD -- which would be
> N-1 in my example where N begins at sysconf(_SC_OPEN_MAX)-1 and moves
> down.
> 
> /bin/sh already has a function called movefd() to do this (which
> basically does the error handling around dup2() or dup3()), and so
> "dynamic" redirection could use it like:
> 
> 	N = sysconf(_SC_OPEN_MAX) - 1;
> 
>     ....
> 
> 	fd = open();
> 	fd_var = movefd(fd, N-1);
> 	fd = -1;
> 	N--;
> 

Ah, OK: I misread it. I mixed it with what Robert has explained: that 
there is a huge penalty when using high number fds. So short-circuited
this with a way to use high numbers apparently but in fact, internally,
using small ones (i.e. the reverse).

Sorry,
-- 
        Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
                     http://www.kergis.com/
                    http://kertex.kergis.com/
                       http://www.sbfa.fr/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C


Home | Main Index | Thread Index | Old Index