close safe wrapper may be broken

From: <>
Date: Tue, 17 Sep 2019 17:37:50 +0000

Posix says about close(2): "If close() is interrupted by a signal that is to be caught, it shall return -1 with errno set to [EINTR] and the state of fildes is unspecified." What means that the file descriptor can be already closed and return EINTR, making the call try to close it again, while this shouldn't be a real problem in single-threaded programs (although would return a fake EBADF), it creates a real problem in multi-threaded programs as you could close other file descriptors that were open in the mean time. Maybe you could verify with fstat if is safe to close again (by comparing the ino and dev values or by receveing EBADF)
Received on Tue Sep 17 2019 - 17:37:50 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC