User: Password:
|
|
Subscribe / Log in / New account

When the programmer is forced to handle return codes

When the programmer is forced to handle return codes

Posted Dec 5, 2009 22:47 UTC (Sat) by cras (guest, #7000)
In reply to: When the programmer is forced to handle return codes by nix
Parent article: On the importance of return codes

So I guess you know what happens in Linux when close() fails with EINTR (with NFS)? It won't close
the fd and it should be retried?

I've gotten rid of alarm()s in (most of) my code and there are no child processes, so I'd think close()s
are pretty safe to do without looping.. And with NFS I first fsync/fdatasync first anyway, so close
probably shouldn't fail anyway. Unless it can fail with EINTR even when it doesn't have to write
anything?.. That would seem almost like a bug.


(Log in to post comments)

When the programmer is forced to handle return codes

Posted Dec 6, 2009 0:05 UTC (Sun) by nix (subscriber, #2304) [Link]

So I guess you know what happens in Linux when close() fails with EINTR (with NFS)? It won't close the fd and it should be retried?
The EINTR happens if a signal arrives while pending writes are being flushed. At this point, the FD is not yet closed. (But if it were, you could retry it anyway, and you'd get EBADF and would know that it had been closed last time around.)

Since you have to loop for write()/read() anyway, looping for close() as well is hardly a killer. (And, yes, I would rather that -EINTR would die die die as fast as possible, but unfortunately it is not dead so we have to deal with it.)

When the programmer is forced to handle return codes

Posted Dec 6, 2009 0:29 UTC (Sun) by cras (guest, #7000) [Link]

That also makes me wonder about my fsync/fdatasync calls. I suppose they can also fail with EINTR.
Anyway, as I mentioned above, all signals causing those to my program nowdays should be
external so I don't think I will be doing anything about this problem. (Handling is the same for
EINTR as for EDQUOT/ESPACE.) Interesting to realize it could be a problem, of course.

When the programmer is forced to handle return codes

Posted Dec 6, 2009 11:17 UTC (Sun) by nix (subscriber, #2304) [Link]

POSIX documents that fsync() can return EINTR but does not document it for
fdatasync(). This seems likely to be an oversight to me.


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds