O_CLOEXEC Shiro Kawai (26 Jul 2020 08:12 UTC)
Re: O_CLOEXEC John Cowan (26 Jul 2020 12:51 UTC)
Re: O_CLOEXEC Shiro Kawai (26 Jul 2020 18:30 UTC)
Re: O_CLOEXEC Lassi Kortela (26 Jul 2020 18:57 UTC)
Re: O_CLOEXEC Lassi Kortela (26 Jul 2020 19:16 UTC)

Re: O_CLOEXEC Lassi Kortela 26 Jul 2020 19:16 UTC

> Manually calling close() in a loop is slow and it's not clear how many
> fd's to try.

An emulation would go something like this:

static int
closefrom(int n)
{
     int max;

     max = sysconf(_SC_OPEN_MAX);
     while ((n >= 0) && (n <= max)) {
         for (;;) {
             if (close(n) == 0) {
                 break;
             }
             if (errno == EBADF) {
                 break;
             }
             if (errno != EINTR) {
                 return -1;
             }
         }
         n++;
     }
     return 0;
}