xwayland: Cleanup server startup and FDs (#9769)

This commit is contained in:
Lee Bousfield 2025-03-28 11:12:25 -05:00 committed by GitHub
parent 10035a85cc
commit a46576afc3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 21 deletions

View File

@ -299,7 +299,7 @@ void CXWaylandServer::runXWayland(CFileDescriptor& notifyFD) {
} }
auto cmd = auto cmd =
std::format("Xwayland {} -rootless -core -listenfd {} -listenfd {} -displayfd {} -wm {}", displayName, xFDs[0].get(), xFDs[1].get(), notifyFD.take(), xwmFDs[1].get()); std::format("Xwayland {} -rootless -core -listenfd {} -listenfd {} -displayfd {} -wm {}", displayName, xFDs[0].get(), xFDs[1].get(), notifyFD.get(), xwmFDs[1].get());
auto waylandSocket = std::format("{}", waylandFDs[1].get()); auto waylandSocket = std::format("{}", waylandFDs[1].get());
setenv("WAYLAND_SOCKET", waylandSocket.c_str(), true); setenv("WAYLAND_SOCKET", waylandSocket.c_str(), true);
@ -352,7 +352,7 @@ bool CXWaylandServer::start() {
return false; return false;
} }
waylandFDs[0].take(); // does this leak? waylandFDs[0].take(); // wl_client owns this fd now
int notify[2] = {-1, -1}; int notify[2] = {-1, -1};
if (pipe(notify) < 0) { if (pipe(notify) < 0) {
@ -372,19 +372,13 @@ bool CXWaylandServer::start() {
pipeSource = wl_event_loop_add_fd(g_pCompositor->m_sWLEventLoop, notifyFds[0].get(), WL_EVENT_READABLE, ::xwaylandReady, nullptr); pipeSource = wl_event_loop_add_fd(g_pCompositor->m_sWLEventLoop, notifyFds[0].get(), WL_EVENT_READABLE, ::xwaylandReady, nullptr);
pipeFd = std::move(notifyFds[0]); pipeFd = std::move(notifyFds[0]);
serverPID = fork(); auto serverPID = fork();
if (serverPID < 0) { if (serverPID < 0) {
Debug::log(ERR, "fork failed"); Debug::log(ERR, "fork failed");
die(); die();
return false; return false;
} else if (serverPID == 0) { } else if (serverPID == 0) {
pid_t pid = fork(); runXWayland(notifyFds[1]);
if (pid < 0) {
Debug::log(ERR, "second fork failed");
_exit(1);
} else if (pid == 0)
runXWayland(notifyFds[1]);
_exit(0); _exit(0);
} }
@ -403,14 +397,6 @@ int CXWaylandServer::ready(int fd, uint32_t mask) {
return 1; return 1;
} }
while (waitpid(serverPID, nullptr, 0) < 0) {
if (errno == EINTR)
continue;
Debug::log(ERR, "Xwayland: waitpid for fork failed");
g_pXWayland->pServer.reset();
return 1;
}
// if we don't have readable here, it failed // if we don't have readable here, it failed
if (!(mask & WL_EVENT_READABLE)) { if (!(mask & WL_EVENT_READABLE)) {
Debug::log(ERR, "Xwayland: startup failed, not setting up xwm"); Debug::log(ERR, "Xwayland: startup failed, not setting up xwm");
@ -420,8 +406,8 @@ int CXWaylandServer::ready(int fd, uint32_t mask) {
Debug::log(LOG, "XWayland is ready"); Debug::log(LOG, "XWayland is ready");
close(fd);
wl_event_source_remove(pipeSource); wl_event_source_remove(pipeSource);
pipeFd.reset();
pipeSource = nullptr; pipeSource = nullptr;
// start the wm // start the wm

View File

@ -34,8 +34,6 @@ class CXWaylandServer {
bool tryOpenSockets(); bool tryOpenSockets();
void runXWayland(Hyprutils::OS::CFileDescriptor& notifyFD); void runXWayland(Hyprutils::OS::CFileDescriptor& notifyFD);
pid_t serverPID = 0;
std::string displayName; std::string displayName;
int display = -1; int display = -1;
std::array<Hyprutils::OS::CFileDescriptor, 2> xFDs; std::array<Hyprutils::OS::CFileDescriptor, 2> xFDs;