EINTR Not Restarting Some Blocking Calls Even With SA_RESTART
0 reputation · 29 Sept 2024, 08:22 UTC
Background
In Linux, blocking I/O system calls can be interrupted by signals. The kernel returns -EINTR unless the signal handler is installed with the SA_RESTART flag, which instructs the kernel to automatically restart certain system calls.
Observed Symptom
When a process sets a timeout via alarm() and relies on SA_RESTART, some calls such as read(), write(), and accept() resume automatically, but others like connect() and getaddrinfo() return immediately with -EINTR, even though SA_RESTART is set.
Constraints and Uncertainty
Developers must explicitly set SA_RESTART per signal, and the kernel does not expose a global switch to enable automatic restart for all blocking calls. This leads to inconsistent cancellation behavior across programs that expect a uniform timeout handling mechanism.
Unresolved Questions
1. Would extending SA_RESTART semantics to all blocking system calls simplify timeout handling without breaking existing applications?
2. Is there a kernel‑level configuration or flag that could enable a global “always restart” mode for blocking calls?
3. What compatibility issues might arise on older kernels if such a global restart mechanism were introduced?