diff --git a/common/os_calls.c b/common/os_calls.c index a58051a5e..9c23d8dde 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -2987,9 +2987,15 @@ g_set_alarm(void (*func)(int), unsigned int secs) #if defined(_WIN32) return 0; #else + struct sigaction action; + + action.sa_handler = func; + action.sa_flags = SA_RESTART; + sigemptyset (&action.sa_mask); + /* Cancel any previous alarm to prevent a race */ unsigned int rv = alarm(0); - signal(SIGALRM, func); + sigaction(SIGALRM, &action, NULL); (void)alarm(secs); return rv; #endif @@ -3002,7 +3008,14 @@ g_signal_child_stop(void (*func)(int)) { #if defined(_WIN32) #else - signal(SIGCHLD, func); + struct sigaction action; + + action.sa_handler = func; + // Don't need to know when children are stopped or started + action.sa_flags = (SA_RESTART | SA_NOCLDSTOP); + sigemptyset (&action.sa_mask); + + sigaction(SIGCHLD, &action, NULL); #endif } @@ -3013,7 +3026,13 @@ g_signal_segfault(void (*func)(int)) { #if defined(_WIN32) #else - signal(SIGSEGV, func); + struct sigaction action; + + action.sa_handler = func; + action.sa_flags = 0; + sigemptyset (&action.sa_mask); + + sigaction(SIGSEGV, &action, NULL); #endif } @@ -3024,7 +3043,13 @@ g_signal_hang_up(void (*func)(int)) { #if defined(_WIN32) #else - signal(SIGHUP, func); + struct sigaction action; + + action.sa_handler = func; + action.sa_flags = SA_RESTART; + sigemptyset (&action.sa_mask); + + sigaction(SIGHUP, &action, NULL); #endif } @@ -3035,7 +3060,13 @@ g_signal_user_interrupt(void (*func)(int)) { #if defined(_WIN32) #else - signal(SIGINT, func); + struct sigaction action; + + action.sa_handler = func; + action.sa_flags = SA_RESTART; + sigemptyset (&action.sa_mask); + + sigaction(SIGINT, &action, NULL); #endif } @@ -3046,7 +3077,13 @@ g_signal_terminate(void (*func)(int)) { #if defined(_WIN32) #else - signal(SIGTERM, func); + struct sigaction action; + + action.sa_handler = func; + action.sa_flags = SA_RESTART; + sigemptyset (&action.sa_mask); + + sigaction(SIGTERM, &action, NULL); #endif } @@ -3057,7 +3094,13 @@ g_signal_pipe(void (*func)(int)) { #if defined(_WIN32) #else - signal(SIGPIPE, func); + struct sigaction action; + + action.sa_handler = func; + action.sa_flags = SA_RESTART; + sigemptyset (&action.sa_mask); + + sigaction(SIGPIPE, &action, NULL); #endif } @@ -3068,7 +3111,13 @@ g_signal_usr1(void (*func)(int)) { #if defined(_WIN32) #else - signal(SIGUSR1, func); + struct sigaction action; + + action.sa_handler = func; + action.sa_flags = SA_RESTART; + sigemptyset (&action.sa_mask); + + sigaction(SIGUSR1, &action, NULL); #endif } diff --git a/common/os_calls.h b/common/os_calls.h index 2374df3e3..9564c925d 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -176,6 +176,14 @@ g_sck_get_peer_ip_address(int sck, const char * g_sck_get_peer_description(int sck, char *desc, unsigned int bytes); +/** + * Sleep for the specified number of milli-seconds + * @param msecs Milli-seconds + * + * If a signal is processed, it is possible that this call will + * sleep for less than the specified number of milli-seconds. This + * is platform-specific + */ void g_sleep(int msecs); int g_pipe(int fd[2]);