Skip to content

Commit

Permalink
xwl: clean up fd logic
Browse files Browse the repository at this point in the history
check if the fd is actually opened before closing, and close the
pipesource FD on exit.
  • Loading branch information
gulafaran committed Jul 31, 2024
1 parent 103e0b6 commit 644538b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/xwayland/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,16 @@ void CXWaylandServer::die() {
if (pipeSource)
wl_event_source_remove(pipeSource);

if (waylandFDs[0])
if (pipeFd >= 0)
close(pipeFd);

if (waylandFDs[0] >= 0)
close(waylandFDs[0]);
if (waylandFDs[1])
if (waylandFDs[1] >= 0)
close(waylandFDs[1]);
if (xwmFDs[0])
if (xwmFDs[0] >= 0)
close(xwmFDs[0]);
if (xwmFDs[1])
if (xwmFDs[1] >= 0)
close(xwmFDs[1]);

// possible crash. Better to leak a bit.
Expand Down Expand Up @@ -364,6 +367,7 @@ bool CXWaylandServer::start() {
}

pipeSource = wl_event_loop_add_fd(g_pCompositor->m_sWLEventLoop, notify[0], WL_EVENT_READABLE, ::xwaylandReady, nullptr);
pipeFd = notify[0];

serverPID = fork();
if (serverPID < 0) {
Expand Down
1 change: 1 addition & 0 deletions src/xwayland/Server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class CXWaylandServer {
std::array<wl_event_source*, 2> xFDReadEvents = {nullptr, nullptr};
wl_event_source* idleSource = nullptr;
wl_event_source* pipeSource = nullptr;
int pipeFd = -1;
std::array<int, 2> xwmFDs = {-1, -1};
std::array<int, 2> waylandFDs = {-1, -1};

Expand Down

0 comments on commit 644538b

Please sign in to comment.