4 ms·
There is a genuine complication that this post seems to have missed. If a system call is interrupted and returns to user space (due to a signal, most likely),
by amluto 7y ago
There is a genuine complication that this post seems to have missed. If a system call is interrupted and returns to user space (due to a signal, most likely), then it is in one of three states: nothing happened, the call finished, or it is part-way done. If nothing happened, then PC can point back to the syscall or EINTR can be returned. (EINTR is a promise that no progress was made.) If it’s all done, it can return success. But, if it’s only part way done, then either it needs to restart transparently or the user code needs to be prepared to handle this.
With recv(), for example, the return value can indicate that some but not all bytes were read. When read()one from a file, most programs aren’t prepared for partial success.
Linux has some ERESTARTSYS mechanisms to handle some of these cases. The code and the semantics are a bit gross.
- gumby 7y agoCame here to post this. The important thing Dick glossed over was that when your process was PCLSRed you were guaranteed what state your program would be in. A guarantee made by ITS before a line of Unix was ever written.
- deleted 7y ago[deleted]
- mwcremer 7y ago> most programs aren’t prepared for partial success But read() and write() return the number of bytes actually read or written. So actually they are, or should be...
- amluto 7y agoOn a normal file, unless it’s NFS with a special mount option, read() and write() never return partial results, which means that many programs can’t handle it. Even modern async/await/promise/future systems frequently have no reliable way to express partial success.
- daurnimator 7y ago> EINTR is a promise that no progress was made. If only.... on many operating systems, you shouldn't retry close on EINTR, e.g. From [linux man page](http://man7.org/linux/man-pages/man2/close.2.html http://man7.org/linux/man-pages/man2/close.2.html): > In particular close() should not be retried after an EINTR since this may cause a reused descriptor from another thread to be closed. Worse, it's different per operating system! - HP-UX you must try again - Linux, Solaris and AIX you don't want to try again - OSX is ill-defined and hence unsafe, you should use `close$nocancel` instead of `close` and _not_ try again. Related links: - http://austingroupbugs.net/view.php?id=529 http://austingroupbugs.net/view.php?id=529 - http://alobbs.com/post/54503240599/close-and-eintr http://alobbs.com/post/54503240599/close-and-eintr - http://www.daemonology.net/blog/2011-12-17-POSIX-close-is-broken.html http://www.daemonology.net/blog/2011-12-17-POSIX-close-is-br... - https://code.google.com/p/chromium/issues/detail?id=269623 https://code.google.com/p/chromium/issues/detail?id=269623 - https://github.com/wahern/cqueues/issues/56 https://github.com/wahern/cqueues/issues/56 - https://github.com/ziglang/zig/issues/2425 https://github.com/ziglang/zig/issues/2425