If a close(2) system call fails with EIO, will the file descriptor still be deleted?
If yes, is it not possible to handle a spurious IO error by retrying later? If no, how should one prevent a file descriptor leak?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That’s a tricky question. However, the POSIX standard does cover it in the description of
close():So, the state of the file descriptor is unspecified by the standard.
For most practical purposes, it is closed; there is precious little you can do with the file descriptor even if it is officially open. You could try an innocuous operation (like
fcntl()andF_GETFL) and see whether you get EBADF back, indicating the descriptor is formally closed. But if it is open and the cause of the EIO error is permanent, then you’re likely to get EIO every time you try to do anything with it (possibly including thefcntl()call). You might or might not ever get the same descriptor returned by another open-like operation. It is not clear that evendup2()could be successful specifying the ‘dead’ file descriptor as the target if the dead file descriptor is open but uncloseable.