Merge pull request #4891 from khaneliman/bugfix/stab-003-test-001-hyprland-ipc

fix(hyprland-ipc): harden fd lifecycle and listener loop
This commit is contained in:
Alexis Rouillard
2026-03-04 22:41:30 +01:00
committed by GitHub
10 changed files with 219 additions and 115 deletions
+4 -4
View File
@@ -13,6 +13,7 @@
#include <string>
#include <thread>
#include "util/scoped_fd.hpp"
#include "giomm/datainputstream.h"
#include "giomm/dataoutputstream.h"
#include "giomm/unixinputstream.h"
@@ -30,7 +31,7 @@ int IPC::connectToSocket() {
}
struct sockaddr_un addr;
int socketfd = socket(AF_UNIX, SOCK_STREAM, 0);
util::ScopedFd socketfd(socket(AF_UNIX, SOCK_STREAM, 0));
if (socketfd == -1) {
throw std::runtime_error("socketfd failed");
@@ -45,11 +46,10 @@ int IPC::connectToSocket() {
int l = sizeof(struct sockaddr_un);
if (connect(socketfd, (struct sockaddr*)&addr, l) == -1) {
close(socketfd);
throw std::runtime_error("unable to connect");
}
return socketfd;
return socketfd.release();
}
void IPC::startIPC() {
@@ -235,7 +235,7 @@ void IPC::unregisterForIPC(EventHandler* ev_handler) {
}
Json::Value IPC::send(const Json::Value& request) {
int socketfd = connectToSocket();
util::ScopedFd socketfd(connectToSocket());
auto unix_istream = Gio::UnixInputStream::create(socketfd, true);
auto unix_ostream = Gio::UnixOutputStream::create(socketfd, false);