]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: proxy: merge zombify_proxy() with stop_proxy()
authorWilly Tarreau <w@1wt.eu>
Thu, 24 Sep 2020 08:51:29 +0000 (10:51 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Oct 2020 09:27:30 +0000 (11:27 +0200)
The two functions don't need to be distinguished anymore since they have
all the necessary info to act as needed on their listeners. Let's just
pass via stop_proxy() and make it check for each listener which one to
close or not.

include/haproxy/proxy.h
src/haproxy.c
src/proxy.c

index b714bda8174e8224206c20df9675469deebcdb68..043ffe6d79148cd31ad183664480738ed13f64ab 100644 (file)
@@ -44,7 +44,6 @@ void soft_stop(void);
 int pause_proxy(struct proxy *p);
 int resume_proxy(struct proxy *p);
 void stop_proxy(struct proxy *p);
-void zombify_proxy(struct proxy *p);
 void pause_proxies(void);
 void resume_proxies(void);
 int  stream_set_backend(struct stream *s, struct proxy *be);
index bd05430fa5b042f0e1fb403198bbabade527fa08..f256dd871590004b2b8c11f87d0e859d36ff876a 100644 (file)
@@ -3510,12 +3510,8 @@ int main(int argc, char **argv)
                px = proxies_list;
                while (px != NULL) {
                        if (px->bind_proc && !px->disabled) {
-                               if (!(px->bind_proc & (1UL << proc))) {
-                                       if (global.tune.options & GTUNE_SOCKET_TRANSFER)
-                                               zombify_proxy(px);
-                                       else
-                                               stop_proxy(px);
-                               }
+                               if (!(px->bind_proc & (1UL << proc)))
+                                       stop_proxy(px);
                        }
                        px = px->next;
                }
@@ -3524,12 +3520,8 @@ int main(int argc, char **argv)
                px = cfg_log_forward;
                while (px != NULL) {
                        if (px->bind_proc && !px->disabled) {
-                               if (!(px->bind_proc & (1UL << proc))) {
-                                       if (global.tune.options & GTUNE_SOCKET_TRANSFER)
-                                               zombify_proxy(px);
-                                       else
-                                               stop_proxy(px);
-                               }
+                               if (!(px->bind_proc & (1UL << proc)))
+                                       stop_proxy(px);
                        }
                        px = px->next;
                }
index 217ca6fd3b509807d0e598cf4c389e152eedbbd7..1e889f7a21704ff78edadeca0591e489c20d656d 100644 (file)
@@ -1289,22 +1289,6 @@ int pause_proxy(struct proxy *p)
        return 1;
 }
 
-/* This function makes the proxy unusable, but keeps the listening sockets
- * opened, so that if any process requests them, we are able to serve them.
- * This should only be called early, before we started accepting requests.
- */
-void zombify_proxy(struct proxy *p)
-{
-       struct listener *l;
-
-       list_for_each_entry(l, &p->conf.listeners, by_fe) {
-               unbind_listener_no_close(l);
-               if (l->state >= LI_ASSIGNED)
-                       delete_listener(l);
-       }
-       p->disabled = 1;
-}
-
 /*
  * This function completely stops a proxy and releases its listeners. It has
  * to be called when going down in order to release the ports so that another
@@ -1316,26 +1300,30 @@ void zombify_proxy(struct proxy *p)
 void stop_proxy(struct proxy *p)
 {
        struct listener *l;
-       int nostop = 0;
 
        HA_SPIN_LOCK(PROXY_LOCK, &p->lock);
 
        list_for_each_entry(l, &p->conf.listeners, by_fe) {
                if (l->options & LI_O_NOSTOP) {
                        HA_ATOMIC_ADD(&unstoppable_jobs, 1);
-                       nostop = 1;
                        continue;
                }
-               /* The master should not close an inherited FD */
-               if (master && (l->rx.flags & RX_F_INHERITED))
+
+               /* There are several cases where we must not close an FD:
+                *   - we're starting up and we have socket transfers enabled;
+                *   - we're the master and this FD was inherited;
+                */
+               if ((global.tune.options & GTUNE_SOCKET_TRANSFER && global.mode & MODE_STARTING) ||
+                   (master && (l->rx.flags & RX_F_INHERITED)))
                        unbind_listener_no_close(l);
                else
                        unbind_listener(l);
-               if (l->state >= LI_ASSIGNED) {
+
+               if (l->state >= LI_ASSIGNED)
                        delete_listener(l);
-               }
        }
-       if (!nostop)
+
+       if (p->li_ready + p->li_bound + p->li_paused == 0)
                p->disabled = 1;
 
        HA_SPIN_UNLOCK(PROXY_LOCK, &p->lock);