mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
Merge #10057: [init] Deduplicated sigaction() boilerplate
81a3857
Deduplicated sigaction() boilerplate (Thomas Snider)
Tree-SHA512: 705b73f285a3d76504ba01476e072fdce67731b65f309bb04e4bbd765556c37e127cb769b475de2d68b33f50d7737fb136aefa0fa7c725a11ad16a47b9d0365f
This commit is contained in:
parent
6bb55d5474
commit
c2258978bf
33
src/init.cpp
33
src/init.cpp
@ -374,18 +374,31 @@ void Shutdown()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signal handlers are very limited in what they are allowed to do, so:
|
* Signal handlers are very limited in what they are allowed to do.
|
||||||
|
* The execution context the handler is invoked in is not guaranteed,
|
||||||
|
* so we restrict handler operations to just touching variables:
|
||||||
*/
|
*/
|
||||||
void HandleSIGTERM(int)
|
static void HandleSIGTERM(int)
|
||||||
{
|
{
|
||||||
fRequestShutdown = true;
|
fRequestShutdown = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleSIGHUP(int)
|
static void HandleSIGHUP(int)
|
||||||
{
|
{
|
||||||
fReopenDebugLog = true;
|
fReopenDebugLog = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
static void registerSignalHandler(int signal, void(*handler)(int))
|
||||||
|
{
|
||||||
|
struct sigaction sa;
|
||||||
|
sa.sa_handler = handler;
|
||||||
|
sigemptyset(&sa.sa_mask);
|
||||||
|
sa.sa_flags = 0;
|
||||||
|
sigaction(signal, &sa, NULL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool static Bind(CConnman& connman, const CService &addr, unsigned int flags) {
|
bool static Bind(CConnman& connman, const CService &addr, unsigned int flags) {
|
||||||
if (!(flags & BF_EXPLICIT) && IsLimited(addr))
|
if (!(flags & BF_EXPLICIT) && IsLimited(addr))
|
||||||
return false;
|
return false;
|
||||||
@ -1064,19 +1077,11 @@ bool AppInitBasicSetup()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clean shutdown on SIGTERM
|
// Clean shutdown on SIGTERM
|
||||||
struct sigaction sa;
|
registerSignalHandler(SIGTERM, HandleSIGTERM);
|
||||||
sa.sa_handler = HandleSIGTERM;
|
registerSignalHandler(SIGINT, HandleSIGTERM);
|
||||||
sigemptyset(&sa.sa_mask);
|
|
||||||
sa.sa_flags = 0;
|
|
||||||
sigaction(SIGTERM, &sa, NULL);
|
|
||||||
sigaction(SIGINT, &sa, NULL);
|
|
||||||
|
|
||||||
// Reopen debug.log on SIGHUP
|
// Reopen debug.log on SIGHUP
|
||||||
struct sigaction sa_hup;
|
registerSignalHandler(SIGHUP, HandleSIGHUP);
|
||||||
sa_hup.sa_handler = HandleSIGHUP;
|
|
||||||
sigemptyset(&sa_hup.sa_mask);
|
|
||||||
sa_hup.sa_flags = 0;
|
|
||||||
sigaction(SIGHUP, &sa_hup, NULL);
|
|
||||||
|
|
||||||
// Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
|
// Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
Loading…
Reference in New Issue
Block a user