[libc-commits] [libc] [libc] Implement posix_close in unistd (PR #240024)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Mon Nov 9 05:05:16 PST 2026


https://github.com/labath requested changes to this pull request.

I have two questions:
- Why do we have two definitions of POSIX_CLOSE_RESTART
- I think the implementation is not correct as permits `posix_close(fd, POSIX_CLOSE_RESTART)` to fail with EINTR, which is precisely what POSIX_CLOSE_RESTART was meant to prevent.

  >  If POSIX_CLOSE_RESTART is zero, the close() function shall not return an [EINTR] error. 

  I think we have two options:
  - map kernel's EINTR to EINPROGRESS, which POSIX describes as "The function was interrupted by a signal and fildes was closed but the close operation is continuing asynchronously.", and which exactly describes what linux does under the hood.
  - map kernel EINTR to zero (success), with the rationale that there's not much that an application can do with the EINPROGRESS anyway.

  Musl used to do the first option, and then [switched](https://git.musl-libc.org/cgit/musl/commit/src/unistd/close.c?id=6bea5dc69892cd9ff0c222474e7dd468c29dfa75) to the second one because it broke too many applications. However, this was for close, which is called from bazzilion places. I think we have more leeway for posix_close, which I think was created exactly to resolve this, and this behavior (EINPROGRESS) is pretty much the only reason for not calling the simpler function. So, I'd say we should go with EINPROGRESS until we have evidence that we cannot.

https://github.com/llvm/llvm-project/pull/240024


More information about the libc-commits mailing list