Sway IPC client: robustness improvements & code cleanups#5068
Open
c4rlo wants to merge 4 commits into
Open
Conversation
Ensure to only read actual "sway --get-socketpath" output, not subsequent garbage in buffer.
Handle EINTR/EAGAIN, partial sends, etc.
c4rlo
commented
May 24, 2026
| int open(const std::string&) const; | ||
| static std::string getSocketPath(); | ||
| static int open(const std::string&); | ||
|
|
Contributor
Author
There was a problem hiding this comment.
Made these static since they're not accessing any instance methods/fields.
| throw std::runtime_error("Failed to get socket path"); | ||
| } | ||
| while (fgets(buf, sizeof(buf), in) != nullptr) { | ||
| str_buf.append(buf, sizeof(buf)); |
Contributor
Author
There was a problem hiding this comment.
This was appending the entire buffer, even beyond the NUL byte, potentially writing garbage into str_buf. In practice it probably didn't matter because the socket path was then treated like a C-string, thereby ignoring anything beyond the embedded NUL.
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.
Update Sway IPC client to make I/O logic and socket path discovery more robust.
send()calls are handled correctly.recv()calls consistently.reinterpret_cast<uint32_t*>IPC header access withmemcpy.popen()/pclose()failures when resolving the Sway socket path, and ignore emptySWAYSOCKenv var.autofor readability, etc.