util: use sigaction() to set signal handler
This commit is contained in:
parent
ceef8ad2d8
commit
206e597b04
1 changed files with 24 additions and 6 deletions
30
util.c
30
util.c
|
@ -845,11 +845,29 @@ UTI_DecodePasswordFromText(char *key)
|
||||||
int
|
int
|
||||||
UTI_SetQuitSignalsHandler(void (*handler)(int))
|
UTI_SetQuitSignalsHandler(void (*handler)(int))
|
||||||
{
|
{
|
||||||
signal(SIGINT, handler);
|
struct sigaction sa;
|
||||||
signal(SIGTERM, handler);
|
|
||||||
#if !defined(WINNT)
|
sa.sa_handler = handler;
|
||||||
signal(SIGQUIT, handler);
|
sa.sa_flags = SA_RESTART;
|
||||||
signal(SIGHUP, handler);
|
if (sigemptyset(&sa.sa_mask) < 0)
|
||||||
#endif /* WINNT */
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue