From e3b84c9595262655a0fef274f2a85cff493df669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20BOULMIER?= Date: Wed, 13 Mar 2019 02:55:02 -0400 Subject: [PATCH] fix(controller): ignore SIGUSR1 until polybar is fully reloaded. (#1678) To avoid polybar from being killed by SIGUSR1 during reloading, SIGUSR1 is ignored until the signal is registered in the new polybar process. As stated in signal(7) man page, the ignored signals are still ignored after a call to a function of the execvX family. During an execve(2), the dispositions of handled signals are reset to the default; the dispositions of ignored signals are left unchanged. Fixes #428 --- src/components/controller.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/controller.cpp b/src/components/controller.cpp index e7b47e80..a8ecdd10 100644 --- a/src/components/controller.cpp +++ b/src/components/controller.cpp @@ -26,6 +26,10 @@ sig_atomic_t g_reload{0}; sig_atomic_t g_terminate{0}; void interrupt_handler(int signum) { + if (g_reload || g_terminate) { + return; + } + g_terminate = 1; g_reload = (signum == SIGUSR1); if (write(g_eventpipe[PIPE_WRITE], &g_terminate, 1) == -1) { @@ -122,6 +126,12 @@ controller::~controller() { signal(SIGINT, SIG_DFL); signal(SIGQUIT, SIG_DFL); signal(SIGTERM, SIG_DFL); + signal(SIGALRM, SIG_DFL); + + if (g_reload) { + // Cause SIGUSR1 to be ignored until registered in the new polybar process + signal(SIGUSR1, SIG_IGN); + } m_log.trace("controller: Detach signal receiver"); m_sig.detach(this);