Author: gherzan Date: Thu Nov 12 15:50:31 2009 New Revision: 1673 Log: pisasd: signal handling, sigaction-style Modified: trunk/pisasd/sdmain.c Modified: trunk/pisasd/sdmain.c ============================================================================== --- trunk/pisasd/sdmain.c Thu Nov 12 15:41:27 2009 (r1672) +++ trunk/pisasd/sdmain.c Thu Nov 12 15:50:31 2009 (r1673) @@ -10,6 +10,9 @@ * @date Jan. 2009 */ +/* required for sa_sigaction member */ +#define _POSIX_C_SOURCE 200112 + #include <stdio.h> #include <signal.h> #include <getopt.h> @@ -229,16 +232,20 @@ * * E.g. sending Ctrl-C the first time tries to shut down gracefully. If that * for some reason fails, a second Ctrl-C quits immediately. - * - * @param quitcode signal quit code */ -static void sd_quit(int quitcode) +static void sd_quit(int signum, UNUSED siginfo_t *info, UNUSED void *ctx) { + struct sigaction sig_dfl_action = { + .sa_flags = 0, + .sa_handler = SIG_DFL + }; + PISA_DEBUG(PL_SHUTDOWN, "Quitting PISA server daemon...\n"); sd_ctx.flag_running = false; /* Reinstall default handler for that signal */ - signal(quitcode, SIG_DFL); + sigemptyset(&sig_dfl_action.sa_mask); + sigaction(signum, &sig_dfl_action, NULL); } /** @@ -290,13 +297,24 @@ static void sd_init(int argc, char *argv[]) { struct in_addr netmask; + struct sigaction sigact; + + /* use the new, extended handler */ + sigact.sa_flags = SA_SIGINFO; + + sigemptyset(&sigact.sa_mask); /* Set signal handler for each signal */ - signal(SIGBUS, sd_quit); - signal(SIGINT, sd_quit); - signal(SIGQUIT, sd_quit); - signal(SIGTERM, sd_quit); - signal(SIGPIPE, SIG_IGN); + + sigact.sa_sigaction = sd_quit; + sigaction(SIGBUS, &sigact, NULL); + sigaction(SIGINT, &sigact, NULL); + sigaction(SIGQUIT, &sigact, NULL); + sigaction(SIGTERM, &sigact, NULL); + + sigact.sa_flags &= ~SA_SIGINFO; + sigact.sa_handler = SIG_IGN; + sigaction(SIGPIPE, &sigact, NULL); /* Set default values in context */ sdctx_init();