]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[CLEANUP] proxy: make pause_proxy() perform the required controls and emit the logs
authorWilly Tarreau <w@1wt.eu>
Wed, 7 Sep 2011 17:14:57 +0000 (19:14 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 7 Sep 2011 20:47:43 +0000 (22:47 +0200)
It avoids duplicated code in the caller.

include/proto/proxy.h
src/proxy.c

index f5303bc72e327c56b432722e0faa1a6007df1965..2f82397e74438f515065a9d976f28090c11cf28d 100644 (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);
index 7bbc6a7c9d3c4ebcec0a93216f0bf9a35033fb3c..2000fd3b327979332bd0cdde63c6cdebde51fbcb 100644 (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) {