@@ -265,18 +265,31 @@ void Shutdown()
265
265
}
266
266
267
267
/* *
268
- * Signal handlers are very limited in what they are allowed to do, so:
268
+ * Signal handlers are very limited in what they are allowed to do.
269
+ * The execution context the handler is invoked in is not guaranteed,
270
+ * so we restrict handler operations to just touching variables:
269
271
*/
270
- void HandleSIGTERM (int )
272
+ static void HandleSIGTERM (int )
271
273
{
272
274
fRequestShutdown = true ;
273
275
}
274
276
275
- void HandleSIGHUP (int )
277
+ static void HandleSIGHUP (int )
276
278
{
277
279
fReopenDebugLog = true ;
278
280
}
279
281
282
+ #ifndef WIN32
283
+ static void registerSignalHandler (int signal, void (*handler)(int ))
284
+ {
285
+ struct sigaction sa;
286
+ sa.sa_handler = handler;
287
+ sigemptyset (&sa.sa_mask );
288
+ sa.sa_flags = 0 ;
289
+ sigaction (signal, &sa, NULL );
290
+ }
291
+ #endif
292
+
280
293
bool static Bind (CConnman& connman, const CService &addr, unsigned int flags) {
281
294
if (!(flags & BF_EXPLICIT) && IsLimited (addr))
282
295
return false ;
@@ -848,19 +861,11 @@ bool AppInitBasicSetup()
848
861
}
849
862
850
863
// Clean shutdown on SIGTERM
851
- struct sigaction sa;
852
- sa.sa_handler = HandleSIGTERM;
853
- sigemptyset (&sa.sa_mask );
854
- sa.sa_flags = 0 ;
855
- sigaction (SIGTERM, &sa, NULL );
856
- sigaction (SIGINT, &sa, NULL );
864
+ registerSignalHandler (SIGTERM, HandleSIGTERM);
865
+ registerSignalHandler (SIGINT, HandleSIGTERM);
857
866
858
867
// Reopen debug.log on SIGHUP
859
- struct sigaction sa_hup;
860
- sa_hup.sa_handler = HandleSIGHUP;
861
- sigemptyset (&sa_hup.sa_mask );
862
- sa_hup.sa_flags = 0 ;
863
- sigaction (SIGHUP, &sa_hup, NULL );
868
+ registerSignalHandler (SIGHUP, HandleSIGHUP);
864
869
865
870
// Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
866
871
signal (SIGPIPE, SIG_IGN);
0 commit comments