Author: tjansen Date: Tue Nov 10 11:38:20 2009 New Revision: 1598 Log: Simplified signal handling. The purpose of having signal handlers is to have one handler for each task. If another signal is handled differently, create a new handler instead. The function {c,s}d_quit is used for graceful shutdown of the daemon. The default case is not necessary, as the function is only called for a defined set of signals. SIGILL is not something that should trigger graceful shutdown. Modified: trunk/pisacd/cdmain.c trunk/pisasd/sdmain.c Modified: trunk/pisacd/cdmain.c ============================================================================== --- trunk/pisacd/cdmain.c Tue Nov 10 10:45:15 2009 (r1597) +++ trunk/pisacd/cdmain.c Tue Nov 10 11:38:20 2009 (r1598) @@ -267,42 +267,21 @@ } /** - * Terminate PISA client daemon by receiving signal + * Terminate PISA client daemon by receiving signal. We set the running flag + * to false to give pisacd the opportunity to shut down gracefully. Restoring + * the default signal handler allows us to forcefully quit the second time we + * get the same signal. * - * @param quitcode signal quit code + * 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 cd_quit(int quitcode) { - if (quitcode != 0) { - switch (quitcode) { - case SIGINT: - PISA_INFO("WARNING: Got a SIGINT signal.\n"); - cd_ctx.flag_running = false; - break; - case SIGQUIT: - PISA_INFO("WARNING: Got a SIGQUIT signal.\n"); - cd_ctx.flag_running = false; - break; - case SIGILL: - PISA_INFO("WARNING: Got a SIGILL signal.\n"); - break; - case SIGBUS: - PISA_INFO("WARNING: Got a SIGBUS signal.\n"); - cd_ctx.flag_running = false; - break; - case SIGTERM: - PISA_INFO("WARNING: Got a SIGTERM signal.\n"); - cd_ctx.flag_running = false; - break; - default: - PISA_INFO("WARNING: Got an unknown signal(signum=%d).\n", - quitcode); - break; - } - } - - PISA_INFO("Quitting PISA client daemon...\n"); + PISA_DEBUG(PL_SHUTDOWN, "Quitting PISA client daemon...\n"); pisa_client_disconnect_from_all_servers(); + cd_ctx.flag_running = false; /* Reinstall default handler for that signal */ signal(quitcode, SIG_DFL); @@ -350,7 +329,6 @@ { /* Set signal handler for each signal */ signal(SIGBUS, cd_quit); - signal(SIGILL, cd_quit); signal(SIGINT, cd_quit); signal(SIGQUIT, cd_quit); signal(SIGTERM, cd_quit); Modified: trunk/pisasd/sdmain.c ============================================================================== --- trunk/pisasd/sdmain.c Tue Nov 10 10:45:15 2009 (r1597) +++ trunk/pisasd/sdmain.c Tue Nov 10 11:38:20 2009 (r1598) @@ -281,28 +281,20 @@ } /** - * Terminate PISA server daemon by receiving signal + * Terminate PISA server daemon by receiving signal. We set the running flag + * to false to give pisasd the opportunity to shut down gracefully. Restoring + * the default signal handler allows us to forcefully quit the second time we + * get the same signal. * - * @param quitcode signal quit code + * 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) { - switch (quitcode) { - case SIGTERM: - case SIGINT: - case SIGQUIT: - case SIGBUS: - PISA_DEBUG(PL_SHUTDOWN, "Quitting PISA server daemon...\n"); - sd_ctx.flag_running = false; - break; - - case SIGILL: - break; - - default: - PISA_INFO("WARNING: Got an unknown signal(signum=%d).\n", quitcode); - break; - } + PISA_DEBUG(PL_SHUTDOWN, "Quitting PISA server daemon...\n"); + sd_ctx.flag_running = false; /* Reinstall default handler for that signal */ signal(quitcode, SIG_DFL); @@ -360,7 +352,6 @@ /* Set signal handler for each signal */ signal(SIGBUS, sd_quit); - signal(SIGILL, sd_quit); signal(SIGINT, sd_quit); signal(SIGQUIT, sd_quit); signal(SIGTERM, sd_quit);