mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 17:35:06 -05:00
util: use sigaction() to set signal handler
This commit is contained in:
30
util.c
30
util.c
@@ -845,11 +845,29 @@ UTI_DecodePasswordFromText(char *key)
|
||||
int
|
||||
UTI_SetQuitSignalsHandler(void (*handler)(int))
|
||||
{
|
||||
signal(SIGINT, handler);
|
||||
signal(SIGTERM, handler);
|
||||
#if !defined(WINNT)
|
||||
signal(SIGQUIT, handler);
|
||||
signal(SIGHUP, handler);
|
||||
#endif /* WINNT */
|
||||
struct sigaction sa;
|
||||
|
||||
sa.sa_handler = handler;
|
||||
sa.sa_flags = SA_RESTART;
|
||||
if (sigemptyset(&sa.sa_mask) < 0)
|
||||
return 0;
|
||||
|
||||
#ifdef SIGINT
|
||||
if (sigaction(SIGINT, &sa, NULL) < 0)
|
||||
return 0;
|
||||
#endif
|
||||
#ifdef SIGTERM
|
||||
if (sigaction(SIGTERM, &sa, NULL) < 0)
|
||||
return 0;
|
||||
#endif
|
||||
#ifdef SIGQUIT
|
||||
if (sigaction(SIGQUIT, &sa, NULL) < 0)
|
||||
return 0;
|
||||
#endif
|
||||
#ifdef SIGHUP
|
||||
if (sigaction(SIGHUP, &sa, NULL) < 0)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user