[CLEANUP] proxy: make pause_proxy() perform the required controls and emit the logs

It avoids duplicated code in the caller.
This commit is contained in:
Willy Tarreau 2011-09-07 19:14:57 +02:00
parent b249e8454c
commit ce8fe259b5
2 changed files with 24 additions and 32 deletions

View File

@ -32,7 +32,7 @@
int start_proxies(int verbose);
struct task *manage_proxy(struct task *t);
void soft_stop(void);
void pause_proxy(struct proxy *p);
int pause_proxy(struct proxy *p);
void stop_proxy(struct proxy *p);
void pause_proxies(void);
void resume_proxies(void);

View File

@ -616,17 +616,33 @@ void soft_stop(void)
/* Temporarily disables listening on all of the proxy's listeners. Upon
* success, the proxy enters the PR_PAUSED state. If disabling at least one
* listener returns an error, then the proxy state is set to PR_STERROR
* because we don't know how to resume from this.
* because we don't know how to resume from this. The function returns 0
* if it fails, or non-zero on success.
*/
void pause_proxy(struct proxy *p)
int pause_proxy(struct proxy *p)
{
struct listener *l;
if (!(p->cap & PR_CAP_FE) || p->state == PR_STERROR ||
p->state == PR_STSTOPPED || p->state == PR_STPAUSED)
return 1;
Warning("Pausing %s %s.\n", proxy_cap_str(p->cap), p->id);
send_log(p, LOG_WARNING, "Pausing %s %s.\n", proxy_cap_str(p->cap), p->id);
for (l = p->listen; l != NULL; l = l->next) {
if (!pause_listener(l))
p->state = PR_STERROR;
}
if (p->state != PR_STERROR)
p->state = PR_STPAUSED;
if (p->state == PR_STERROR) {
Warning("%s %s failed to enter pause mode.\n", proxy_cap_str(p->cap), p->id);
send_log(p, LOG_WARNING, "%s %s failed to enter pause mode.\n", proxy_cap_str(p->cap), p->id);
return 0;
}
p->state = PR_STPAUSED;
return 1;
}
@ -668,39 +684,15 @@ void pause_proxies(void)
p = proxy;
tv_update_date(0,1); /* else, the old time before select will be used */
while (p) {
if (p->cap & PR_CAP_FE &&
p->state != PR_STERROR &&
p->state != PR_STSTOPPED &&
p->state != PR_STPAUSED) {
Warning("Pausing %s %s.\n", proxy_cap_str(p->cap), p->id);
send_log(p, LOG_WARNING, "Pausing %s %s.\n", proxy_cap_str(p->cap), p->id);
pause_proxy(p);
if (p->state != PR_STPAUSED) {
err |= 1;
Warning("%s %s failed to enter pause mode.\n", proxy_cap_str(p->cap), p->id);
send_log(p, LOG_WARNING, "%s %s failed to enter pause mode.\n", proxy_cap_str(p->cap), p->id);
}
}
err |= !pause_proxy(p);
p = p->next;
}
prs = peers;
while (prs) {
p = prs->peers_fe;
if (p && (p->cap & PR_CAP_FE &&
p->state != PR_STERROR &&
p->state != PR_STSTOPPED &&
p->state != PR_STPAUSED)) {
Warning("Pausing %s %s.\n", proxy_cap_str(p->cap), p->id);
send_log(p, LOG_WARNING, "Pausing %s %s.\n", proxy_cap_str(p->cap), p->id);
pause_proxy(p);
if (p->state != PR_STPAUSED) {
err |= 1;
Warning("%s %s failed to enter pause mode.\n", proxy_cap_str(p->cap), p->id);
send_log(p, LOG_WARNING, "%s %s failed to enter pause mode.\n", proxy_cap_str(p->cap), p->id);
}
}
prs = prs->next;
err |= !pause_proxy(p);
prs = prs->next;
}
if (err) {