mirror of https://github.com/djcb/mu.git
cmd-server: improve signal handling
use a static signal handling function, which is easier to check than a lambda.
This commit is contained in:
parent
ebc9b88f80
commit
12658a3dc6
|
@ -38,22 +38,28 @@ using namespace Mu;
|
||||||
static std::atomic<bool> MuTerminate{false};
|
static std::atomic<bool> MuTerminate{false};
|
||||||
static bool tty;
|
static bool tty;
|
||||||
|
|
||||||
|
static void
|
||||||
|
sig_handler(int sig)
|
||||||
|
{
|
||||||
|
MuTerminate = true;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
install_sig_handler(void)
|
install_sig_handler(void)
|
||||||
{
|
{
|
||||||
struct sigaction action;
|
static struct sigaction action;
|
||||||
int i, sigs[] = {SIGINT, SIGHUP, SIGTERM, SIGPIPE};
|
int i, sigs[] = {SIGINT, SIGHUP, SIGTERM, SIGPIPE};
|
||||||
|
|
||||||
MuTerminate = false;
|
MuTerminate = false;
|
||||||
|
|
||||||
action.sa_handler = [](int sig) { MuTerminate = true; };
|
action.sa_handler = sig_handler;
|
||||||
sigemptyset(&action.sa_mask);
|
sigemptyset(&action.sa_mask);
|
||||||
action.sa_flags = SA_RESETHAND;
|
action.sa_flags = SA_RESETHAND;
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(sigs); ++i)
|
for (i = 0; i != G_N_ELEMENTS(sigs); ++i)
|
||||||
if (sigaction(sigs[i], &action, NULL) != 0)
|
if (sigaction(sigs[i], &action, NULL) != 0)
|
||||||
g_critical("set sigaction for %d failed: %s", sigs[i], g_strerror(errno));
|
g_critical("set sigaction for %d failed: %s",
|
||||||
;
|
sigs[i], g_strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue