Email list hosting service & mailing list manager

close() can be interrupted with undefined behavior Lassi Kortela (21 Jul 2019 11:44 UTC)
Re: close() can be interrupted with undefined behavior Duy Nguyen (21 Jul 2019 11:59 UTC)
Re: close() can be interrupted with undefined behavior Lassi Kortela (21 Jul 2019 12:11 UTC)
Re: close() can be interrupted with undefined behavior Duy Nguyen (23 Jul 2019 10:17 UTC)
Re: close() can be interrupted with undefined behavior hga@xxxxxx (21 Jul 2019 12:43 UTC)

close() can be interrupted with undefined behavior Lassi Kortela 21 Jul 2019 11:44 UTC

"POSIX close(2) is broken", Colin Percival and Taylor Campbell, 2011.
<http://www.daemonology.net/blog/2011-12-17-POSIX-close-is-broken.html>

Apparently POSIX close() can cause EINTR and leave the file descriptor
in an unknown state :D I mean:

int
threadunsafe_close(int fd)
{
     if (close(fd) == 0)
         return (0);
     if (errno != EINTR)
         return (-1);
     while (close(fd)) {
         if (errno == EBADF)
             return (0);
         if (errno != EINTR)
             return (-1);
     }
     return (0);
}

And the thread- and signal-safe version is worse.

Let that sink in.