[PATCH 2/3] io: Add closefrom [BZ #10353]

Florian Weimer fweimer@redhat.com
Tue Dec 22 13:17:56 GMT 2020


* Adhemerval Zanella:

>> Right, but I think it's needed for correctness.  closefrom (3) should
>> work even if all descriptors are open.
>
> Alright, I think we can do something like:
>
>   int dirfd = __open_nocancel (FD_TO_FILENAME_PREFIX, O_RDONLY | O_DIRECTORY, 0);
>   if (dirfd == -1 && errno == EMFILE)
>     {
>       int maxfd = __getdtablesize ();
>       for (int i = lowfd; i < maxfd; i++)
> 	if (__close_nocancel (i) == 0)
> 	  break;
>       dirfd = __open_nocancel (FD_TO_FILENAME_PREFIX, O_RDONLY | O_DIRECTORY, 0);
>       if (dirfd == -1)
>         goto err;
>     }
>

I suggest errno != ENOENT (not mounted /proc), but otherwise looks good.

Thanks,
Florian
-- 
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill



More information about the Libc-alpha mailing list