mirror of
https://github.com/hyprwm/Hyprland
synced 2025-12-20 02:30:03 +01:00
internal/start: More careful signal handling (#12573)
- Take out signal set up into a subroutine; - Use `sigaction` instead of `signal` for consistent behavior across UNIX platforms; - Enable a warning when a signal handler set up fails; - Don't do anything to SIGKILL, since it cannot be handled.
This commit is contained in:
parent
8ca40479a7
commit
ca99e8228c
1 changed files with 14 additions and 4 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include <csignal>
|
||||
#include <cstring>
|
||||
#include <print>
|
||||
|
||||
#include "helpers/Logger.hpp"
|
||||
|
|
@ -28,14 +29,23 @@ static void onSignal(int sig) {
|
|||
exit(0);
|
||||
}
|
||||
|
||||
static void terminateChildOnSignal(int signal) {
|
||||
struct sigaction sa;
|
||||
sa.sa_handler = onSignal;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_RESTART;
|
||||
int ret = sigaction(signal, &sa, nullptr);
|
||||
if (ret != 0)
|
||||
g_logger->log(Hyprutils::CLI::LOG_WARN, "Failed to set up handler for signal {}: {}", signal, strerror(errno));
|
||||
}
|
||||
|
||||
int main(int argc, const char** argv, const char** envp) {
|
||||
g_logger = makeUnique<Hyprutils::CLI::CLoggerConnection>(*g_loggerMain);
|
||||
g_logger->setName("start-hyprland");
|
||||
g_logger->setLogLevel(Hyprutils::CLI::LOG_DEBUG);
|
||||
|
||||
signal(SIGTERM, ::onSignal);
|
||||
signal(SIGINT, ::onSignal);
|
||||
signal(SIGKILL, ::onSignal);
|
||||
terminateChildOnSignal(SIGTERM);
|
||||
terminateChildOnSignal(SIGINT);
|
||||
|
||||
int startArgv = -1;
|
||||
|
||||
|
|
@ -84,4 +94,4 @@ int main(int argc, const char** argv, const char** envp) {
|
|||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue