fix(hyprland-ipc): harden fd lifecycle and listener loop

Hyprland IPC had fd lifecycle risks on failure/shutdown paths and used a
spin-sleep listener model.

I initialized fd state defensively, tightened connect/close/shutdown handling,
moved to blocking read with newline framing, and added RAII-style fd cleanup in
socket1 reply paths.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman
2026-02-09 13:48:28 -06:00
parent fd086d0f33
commit d0363313b8
2 changed files with 101 additions and 46 deletions

View File

@@ -1,5 +1,6 @@
#pragma once
#include <atomic>
#include <filesystem>
#include <list>
#include <mutex>
@@ -43,10 +44,11 @@ class IPC {
std::thread ipcThread_;
std::mutex callbackMutex_;
std::mutex socketMutex_;
util::JsonParser parser_;
std::list<std::pair<std::string, EventHandler*>> callbacks_;
int socketfd_; // the hyprland socket file descriptor
pid_t socketOwnerPid_;
bool running_ = true; // the ipcThread will stop running when this is false
int socketfd_ = -1; // the hyprland socket file descriptor
pid_t socketOwnerPid_ = -1;
std::atomic<bool> running_ = true; // the ipcThread will stop running when this is false
};
}; // namespace waybar::modules::hyprland