diff options
| author | Wladimir J. van der Laan <[email protected]> | 2017-03-27 10:36:32 +0200 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2017-03-27 10:36:57 +0200 |
| commit | 5114f8113627791b871c88998bd5a3d36961c241 (patch) | |
| tree | 69700b0396389a594509dbde17b5581c270f73ce /src | |
| parent | Merge #10056: [zmq] Call va_end() on va_start()ed args. (diff) | |
| parent | Deduplicated sigaction() boilerplate (diff) | |
| download | discoin-5114f8113627791b871c88998bd5a3d36961c241.tar.xz discoin-5114f8113627791b871c88998bd5a3d36961c241.zip | |
Merge #10057: [init] Deduplicated sigaction() boilerplate
81a3857 Deduplicated sigaction() boilerplate (Thomas Snider)
Tree-SHA512: 705b73f285a3d76504ba01476e072fdce67731b65f309bb04e4bbd765556c37e127cb769b475de2d68b33f50d7737fb136aefa0fa7c725a11ad16a47b9d0365f
Diffstat (limited to 'src')
| -rw-r--r-- | src/init.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/init.cpp b/src/init.cpp index 3c51fe380..a78224d5d 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -265,18 +265,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; } -void HandleSIGHUP(int) +static void HandleSIGHUP(int) { 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) { if (!(flags & BF_EXPLICIT) && IsLimited(addr)) return false; @@ -848,19 +861,11 @@ bool AppInitBasicSetup() } // Clean shutdown on SIGTERM - struct sigaction sa; - sa.sa_handler = HandleSIGTERM; - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - sigaction(SIGTERM, &sa, NULL); - sigaction(SIGINT, &sa, NULL); + registerSignalHandler(SIGTERM, HandleSIGTERM); + registerSignalHandler(SIGINT, HandleSIGTERM); // Reopen debug.log on SIGHUP - struct sigaction sa_hup; - sa_hup.sa_handler = HandleSIGHUP; - sigemptyset(&sa_hup.sa_mask); - sa_hup.sa_flags = 0; - sigaction(SIGHUP, &sa_hup, NULL); + registerSignalHandler(SIGHUP, HandleSIGHUP); // Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly signal(SIGPIPE, SIG_IGN); |