fix(EINTR): retry operations on interrupt#62
Open
kruton wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves robustness of low-level I/O by introducing an EINTR-retry macro and “full read/write” helpers, then applying them to key input/output paths (socket resolver pipe, stdout flush, stdin reads) and tightening a few filesystem-call error paths.
Changes:
- Add
RETRY_ON_EINTRplusread_full/write_full/writev_fullhelpers to reliably complete syscalls across interrupts and partial I/O. - Use the new helpers in nonblocking hostname resolution and in raw output paths (stdout flush,
/echo -r). - Add error handling for
getcwd/getwdusage to avoid propagating NULL/garbage paths.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/port.h | Adds RETRY_ON_EINTR macro used to harden syscall loops. |
| src/util.c | Implements read_full, write_full, and writev_full helpers. |
| src/util.h | Exposes the new full I/O helpers to the rest of the codebase. |
| src/tfio.c | Retries stdin read() on EINTR and logs errors. |
| src/socket.c | Uses full read/write helpers for resolver IPC and refactors resolver cleanup. |
| src/output.c | Retries write() in bufflush() to avoid EINTR-related truncation/spins. |
| src/command.c | Makes getcwd/getwd failures explicit and uses write_full for raw echo. |
| src/signals.c | Avoids using an uninitialized initial directory when getcwd/getwd fails. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+125
to
+135
| while (niov > 0) { | ||
| ssize_t result; | ||
| size_t written; | ||
|
|
||
| RETRY_ON_EINTR(result, writev(fd, iov, niov)); | ||
| if (result < 0) | ||
| return -1; | ||
| if (result == 0) { | ||
| errno = EIO; | ||
| return -1; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.