Skip to content

Sway IPC client: robustness improvements & code cleanups#5068

Open
c4rlo wants to merge 4 commits into
Alexays:masterfrom
c4rlo:sway-ipc-fixes
Open

Sway IPC client: robustness improvements & code cleanups#5068
c4rlo wants to merge 4 commits into
Alexays:masterfrom
c4rlo:sway-ipc-fixes

Conversation

@c4rlo
Copy link
Copy Markdown
Contributor

@c4rlo c4rlo commented May 24, 2026

Update Sway IPC client to make I/O logic and socket path discovery more robust.

  • Send IPC headers and payloads with retry loops so partial send() calls are handled correctly.
  • Handle interrupted/nonblocking recv() calls consistently.
  • Replace unaligned reinterpret_cast<uint32_t*> IPC header access with memcpy.
  • Check popen()/pclose() failures when resolving the Sway socket path, and ignore empty SWAYSOCK env var.
  • Misc code cleanups, e.g. use designated initializers for clarity, tweak how/where we use auto for readability, etc.

c4rlo added 4 commits May 24, 2026 06:41
Ensure to only read actual "sway --get-socketpath" output, not
subsequent garbage in buffer.
Handle EINTR/EAGAIN, partial sends, etc.
int open(const std::string&) const;
static std::string getSocketPath();
static int open(const std::string&);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant