[PATCH] io: Refactor close_range and closefrom

Adhemerval Zanella adhemerval.zanella@linaro.org
Mon Nov 8 17:04:23 GMT 2021



On 08/11/2021 12:13, Sergey Bugaev wrote:
> On Mon, Nov 8, 2021 at 5:55 PM Adhemerval Zanella
> <adhemerval.zanella@linaro.org> wrote:
>>> Is this (either closes everything or nothing) an appropriate thing to
>>> promise in the common header? Similarly, if the default implementation
>>> accepts no flags, should the common description mention "the
>>> CLOSE_RANGE prefix"?
>>
>> Well, that's the semantic of the both the syscall and the Linux fallback.
>> If Hurd does not provide such semantic I think you should work this out.
> 
> My Hurd patch does provide that semantic. I'm concerned about this
> being promised in the generic header; some other port/kernel could
> potentially decide to instead stop & propagate an error from closing a
> descriptor. Perhaps the claim could be qualified (for instance, "In
> all current ports, ...")? Not that this matters.

I think it worth to align with other two current implementation (Linux
and FreeBSD) where errors are indeed ignored.  I changed to:

/* Close all file descriptors in the range FD up to MAX_FD.  The flag FLAGS
   are defined by the CLOSE_RANGE prefix.  This function behaves like close
   on the range and gaps where the file descriptor is invalid or errors
   encountered while closing file descriptors are ignored.   Returns 0 on
   successor or -1 for failure (and sets errno accordingly).  */


> 
> Another suggestion:
> 
>> +  for (int i = 0; i < maxfd; i++)
>> +    if (i >= lowfd)
>> +      __close_nocancel_nostatus (i);
> 
> This should be
> 
> int i;
> for (i = first; i <= last && i < maxfd; i++)
>   __close_nocancel_nostatus (i);
> 
> shouldn't it?
> 
> How does that even compile? 'lowfd' is the name of closefrom's
> argument. close_range's arguments are 'first' and 'last' (and
> 'flags').

It does not, mostly because it is not really used anywhere. I have
fixed it, thanks.


More information about the Libc-alpha mailing list