Question
EINTR on write(): avoiding duplicate data when retrying
Rey Nea
0 reputation · 28 Apr 2022, 05:02 UTC
128.5K views0
EINTR on write()
The write() system call may return EINTR when a signal interrupts the operation before any data is transferred. POSIX requires the caller to retry, but the standard does not clarify whether data written before the interruption is discarded. This ambiguity can lead to duplicate writes on regular files.
Goal
Determine a reliable strategy for retrying write() that guarantees no data duplication across POSIX systems.
Constraints & Uncertainty
- Partial writes may occur before the signal is delivered.
- O_APPEND can mitigate duplication but alters ordering semantics.
- File locking mechanisms are not uniformly portable and may introduce deadlocks.
Specific Questions
- Under POSIX, is a write() that returns
EINTRguaranteed to have written zero bytes? - On Linux, does the kernel commit partial writes before delivering the signal that causes
EINTR? - What standard library wrappers or patterns exist to retry write() safely without duplicating data?