Skip to content

Commit

Permalink
core: restart on a critical signal or SIGHUP
Browse files Browse the repository at this point in the history
ref #76
  • Loading branch information
vaxerski committed Mar 5, 2024
1 parent d45ffd5 commit 2fa0da4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/core/hyprlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ static void handleUnlockSignal(int sig) {
}
}

static void handleCriticalSignal(int sig) {
g_pHyprlock->attemptRestoreOnDeath();
abort();
}

void CHyprlock::run() {
m_sWaylandState.registry = wl_display_get_registry(m_sWaylandState.display);

Expand Down Expand Up @@ -332,6 +337,8 @@ void CHyprlock::run() {
lockSession();

signal(SIGUSR1, handleUnlockSignal);
signal(SIGSEGV, handleCriticalSignal);
signal(SIGABRT, handleCriticalSignal);

pollfd pollfds[] = {
{
Expand All @@ -346,13 +353,15 @@ void CHyprlock::run() {

if (ret < 0) {
Debug::log(CRIT, "[core] Polling fds failed with {}", errno);
attemptRestoreOnDeath();
m_bTerminate = true;
exit(1);
}

for (size_t i = 0; i < 1; ++i) {
if (pollfds[i].revents & POLLHUP) {
Debug::log(CRIT, "[core] Disconnected from pollfd id {}", i);
attemptRestoreOnDeath();
m_bTerminate = true;
exit(1);
}
Expand Down Expand Up @@ -872,4 +881,10 @@ std::string CHyprlock::spawnSync(const std::string& cmd) {

zwlr_screencopy_manager_v1* CHyprlock::getScreencopy() {
return m_sWaylandState.screencopy;
}

void CHyprlock::attemptRestoreOnDeath() {
// dirty hack
spawnSync("hyprctl keyword misc:allow_session_lock_restore true");
spawnAsync("sleep 2 && hyprlock & disown");
}
2 changes: 2 additions & 0 deletions src/core/hyprlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class CHyprlock {
void lockSession();
void unlockSession();

void attemptRestoreOnDeath();

void spawnAsync(const std::string& cmd);
std::string spawnSync(const std::string& cmd);

Expand Down

0 comments on commit 2fa0da4

Please sign in to comment.