From: Willy Tarreau Date: Wed, 25 Aug 2010 10:58:59 +0000 (+0200) Subject: [MINOR] startup: don't wait for nothing when no old pid remains X-Git-Tag: v1.5-dev8~484 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb545b4cfcca18e7adf4a56ef63c162273a85416;p=thirdparty%2Fhaproxy.git [MINOR] startup: don't wait for nothing when no old pid remains In case of binding failure during startup, we wait for some time sending signals to old pids so that they release the ports we need. But if there aren't any old pids anymore, it's useless to wait, we prefer to fail fast. Along with this change, we now have the number of old pids really found in the nb_oldpids variable. --- diff --git a/include/types/global.h b/include/types/global.h index 9c62461d54..12ba8d42c5 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -104,6 +104,7 @@ extern int actconn; /* # of active sessions */ extern int listeners; extern char trash[BUFSIZE]; extern char *swap_buffer; +extern int nb_oldpids; /* contains the number of old pids found */ extern const int zero; extern const int one; extern const struct linger nolinger; diff --git a/src/haproxy.c b/src/haproxy.c index 75a310d107..ece95264c7 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -130,7 +130,6 @@ int stopping; /* non zero means stopping in progress */ * our ports. With 200 retries, that's about 2 seconds. */ #define MAX_START_RETRIES 200 -static int nb_oldpids = 0; static int *oldpids = NULL; static int oldpids_sig; /* use USR1 or TERM */ @@ -142,6 +141,7 @@ char trash[BUFSIZE]; */ char *swap_buffer = NULL; +int nb_oldpids = 0; const int zero = 0; const int one = 1; const struct linger nolinger = { .l_onoff = 1, .l_linger = 0 }; @@ -934,12 +934,17 @@ void deinit(void) } /* end deinit() */ -/* sends the signal to all pids found in */ -static void tell_old_pids(int sig) +/* sends the signal to all pids found in . Returns the number of + * pids the signal was correctly delivered to. + */ +static int tell_old_pids(int sig) { int p; + int ret = 0; for (p = 0; p < nb_oldpids; p++) - kill(oldpids[p], sig); + if (kill(oldpids[p], sig) == 0) + ret++; + return ret; } /* @@ -1012,14 +1017,18 @@ int main(int argc, char **argv) /* exit the loop on no error or fatal error */ if ((err & (ERR_RETRYABLE|ERR_FATAL)) != ERR_RETRYABLE) break; - if (nb_oldpids == 0) + if (nb_oldpids == 0 || retry == 0) break; /* FIXME-20060514: Solaris and OpenBSD do not support shutdown() on * listening sockets. So on those platforms, it would be wiser to * simply send SIGUSR1, which will not be undoable. */ - tell_old_pids(SIGTTOU); + if (tell_old_pids(SIGTTOU) == 0) { + /* no need to wait if we can't contact old pids */ + retry = 0; + continue; + } /* give some time to old processes to stop listening */ w.tv_sec = 0; w.tv_usec = 10*1000; @@ -1149,7 +1158,7 @@ int main(int argc, char **argv) } if (nb_oldpids) - tell_old_pids(oldpids_sig); + nb_oldpids = tell_old_pids(oldpids_sig); /* Note that any error at this stage will be fatal because we will not * be able to restart the old pids.