mirror of
https://github.com/hyprwm/xdg-desktop-portal-hyprland.git
synced 2024-12-22 17:59:47 +01:00
core: kill process if threads are in a deadlock
This commit is contained in:
parent
ec31e99056
commit
667007fa4e
2 changed files with 11 additions and 2 deletions
|
@ -11,6 +11,7 @@
|
|||
#include <sys/poll.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <thread>
|
||||
|
||||
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue