News for hackers. Stuff that matters.
Re:Comparative unsafety by cesarb on Friday April 09, 2021 @11:14AM (#26751553)
You cannot retry close(). Quoting from https://man7.org/linux/man-pages/man2/close.2.html#NOTES

       Retrying the close() after a failure return is the wrong thing to
       do, since this may cause a reused file descriptor from another
       thread to be closed.  This can occur because the Linux kernel
       always releases the file descriptor early in the close operation,
       freeing it for reuse; the steps that may return an error, such as
       flushing data to the filesystem or device, occur only later in
       the close operation.
That is, once you call close(), the file descriptor is always freed (even if close() returns an error), and can be reused for an open() or similar in another thread. Retrying the close() will fail with EBADF in the best case, and close something another thread has opened in the worst case.
Re:Comparative unsafety by OskarS on Friday April 09, 2021 @04:06PM (#26755411)
So what is the point of it having a return value at all then?