From 9952460ad9bd3e4aa7db6107d0b52981ad327258 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 11 Dec 2007 17:37:16 +0100 Subject: [PATCH] server.c: Check return value of signal(). And replace the ugly code that counted the number of calls to para_install_sighandler() by equivalent, but less ugly code. --- server.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/server.c b/server.c index 93de8cc3..17ff7cb4 100644 --- a/server.c +++ b/server.c @@ -283,22 +283,26 @@ out: static void setup_signal_handling(void) { - int ret = 0; - - signal_pipe = para_signal_init(); + signal_pipe = para_signal_init(); /* always successful */ PARA_NOTICE_LOG("setting up signal handlers\n"); - ret += para_install_sighandler(SIGINT); - ret += para_install_sighandler(SIGTERM); - ret += para_install_sighandler(SIGHUP); - ret += para_install_sighandler(SIGCHLD); - signal(SIGPIPE, SIG_IGN); - signal(SIGUSR1, SIG_IGN); - if (ret != 4) { - PARA_EMERG_LOG("%s", "could not install signal handlers\n"); - exit(EXIT_FAILURE); - } + if (para_install_sighandler(SIGINT) < 0) + goto err; + if (para_install_sighandler(SIGTERM) < 0) + goto err; + if (para_install_sighandler(SIGHUP) < 0) + goto err; + if (para_install_sighandler(SIGCHLD) < 0) + goto err; + if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) + goto err; + if (signal(SIGUSR1, SIG_IGN) == SIG_ERR) + goto err; add_close_on_fork_list(signal_pipe); + return; +err: + PARA_EMERG_LOG("could not install signal handlers\n"); + exit(EXIT_FAILURE); } static unsigned init_network(void) -- 2.39.5