diff --git a/src/core/PortalManager.cpp b/src/core/PortalManager.cpp index 912f859..30e0943 100644 --- a/src/core/PortalManager.cpp +++ b/src/core/PortalManager.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -242,6 +243,8 @@ void CPortalManager::onGlobalRemoved(void* data, struct wl_registry* registry, u } void CPortalManager::init() { + m_iPID = getpid(); + try { m_pConnection = sdbus::createDefaultBusConnection("org.freedesktop.impl.portal.desktop.hyprland"); } catch (std::exception& e) { @@ -517,6 +520,11 @@ void CPortalManager::addTimer(const CTimer& timer) { void CPortalManager::terminate() { m_bTerminate = true; + // if we don't exit in 5s, we'll kill by force. Nuclear option. PIDs are not reused in linux until a wrap-around, + // and I doubt anyone will make 4.2M PIDs within 5s. + if (fork() == 0) + execl("/bin/sh", "/bin/sh", "-c", std::format("sleep 5 && kill -9 {}", m_iPID).c_str()); + { m_sEventLoopInternals.shouldProcess = true; m_sEventLoopInternals.loopSignal.notify_all(); diff --git a/src/core/PortalManager.hpp b/src/core/PortalManager.hpp index 98359a4..1813786 100644 --- a/src/core/PortalManager.hpp +++ b/src/core/PortalManager.hpp @@ -75,9 +75,10 @@ class CPortalManager { void terminate(); private: - void startEventLoop(); + void startEventLoop(); - bool m_bTerminate = false; + bool m_bTerminate = false; + pid_t m_iPID = 0; struct { std::condition_variable loopSignal;