From: Willy Tarreau Date: Sun, 10 May 2009 07:59:50 +0000 (+0200) Subject: [MEDIUM] convert all signals to asynchronous signals X-Git-Tag: v1.3.18~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01b3a53f49af8c7be32b15ad978ec7c4a9e6851f;p=thirdparty%2Fhaproxy.git [MEDIUM] convert all signals to asynchronous signals The small list of signals currently handled by haproxy were processed as soon as they were received. This has caused trouble with calls to pool_gc2() occuring in the middle of libc's memory management functions seldom causing deadlocks preventing the old process from leaving. Now these signals use the new async signal framework and are called asynchronously, when there is no risk of recursion. This ensures more reliable operation, especially for sensible processing such as memory management. --- diff --git a/src/haproxy.c b/src/haproxy.c index 608dcc5783..31c48e1c05 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -244,7 +244,7 @@ void sig_soft_stop(int sig) { soft_stop(); pool_gc2(); - signal(sig, SIG_IGN); + signal_register(sig, SIG_IGN); } /* @@ -254,7 +254,6 @@ void sig_pause(int sig) { pause_proxies(); pool_gc2(); - signal(sig, sig_pause); } /* @@ -263,7 +262,6 @@ void sig_pause(int sig) void sig_listen(int sig) { listen_proxies(); - signal(sig, sig_listen); } /* @@ -313,7 +311,6 @@ void sig_dump_state(int sig) p = p->next; } - signal(sig, sig_dump_state); } void dump(int sig) @@ -361,8 +358,8 @@ void sig_int(int sig) */ fast_stop(); pool_gc2(); - /* If we are killed twice, we decide to die*/ - signal(sig, SIG_DFL); + /* If we are killed twice, we decide to die */ + signal_register(sig, SIG_DFL); } void sig_term(int sig) @@ -374,8 +371,8 @@ void sig_term(int sig) */ fast_stop(); pool_gc2(); - /* If we are killed twice, we decide to die*/ - signal(sig, SIG_DFL); + /* If we are killed twice, we decide to die */ + signal_register(sig, SIG_DFL); } #endif @@ -909,12 +906,12 @@ int main(int argc, char **argv) FILE *pidfile = NULL; init(argc, argv); - signal(SIGQUIT, dump); - signal(SIGUSR1, sig_soft_stop); - signal(SIGHUP, sig_dump_state); + signal_register(SIGQUIT, dump); + signal_register(SIGUSR1, sig_soft_stop); + signal_register(SIGHUP, sig_dump_state); #ifdef DEBUG_MEMORY - signal(SIGINT, sig_int); - signal(SIGTERM, sig_term); + signal_register(SIGINT, sig_int); + signal_register(SIGTERM, sig_term); #endif /* on very high loads, a sigpipe sometimes happen just between the @@ -974,8 +971,8 @@ int main(int argc, char **argv) } /* prepare pause/play signals */ - signal(SIGTTOU, sig_pause); - signal(SIGTTIN, sig_listen); + signal_register(SIGTTOU, sig_pause); + signal_register(SIGTTIN, sig_listen); /* MODE_QUIET can inhibit alerts and warnings below this line */