]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mworker: keep and clean the listeners
authorWilliam Lallemand <wlallemand@haproxy.com>
Tue, 11 Sep 2018 08:06:27 +0000 (10:06 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 11 Sep 2018 08:23:24 +0000 (10:23 +0200)
Keep the listeners that should be used in the master process and clean
them in the workers.

include/types/listener.h
src/haproxy.c
src/listener.c

index 09b11044a08ad7c5c0cc0234dc6feda5f5692588..816d1117b340c889d828dcc42922b27d5d1c88ce 100644 (file)
@@ -100,6 +100,7 @@ enum li_state {
 #define LI_O_V4V6               0x0800  /* bind to IPv4/IPv6 on Linux >= 2.4.21 */
 #define LI_O_ACC_CIP            0x1000  /* find the proxied address in the NetScaler Client IP header */
 #define LI_O_INHERITED          0x2000  /* inherited FD from the parent process (fd@) */
+#define LI_O_MWORKER            0x4000  /* keep the FD open in the master but close it in the children */
 
 /* Note: if a listener uses LI_O_UNLIMITED, it is highly recommended that it adds its own
  * maxconn setting to the global.maxsock value so that its resources are reserved.
index 9cf6742af31e7fbdf79f12b238d7fcf26cb482fc..d5345baa50f1c0abb121868cd435840d60dd1a0e 100644 (file)
@@ -617,11 +617,11 @@ static void mworker_cleanlisteners()
                list_for_each_entry_safe(l, l_next, &curproxy->conf.listeners, by_fe) {
                        /* does not close if the FD is inherited with fd@
                         * from the parent process */
-                       if (!(l->options & LI_O_INHERITED))
+                       if (!(l->options & (LI_O_INHERITED|LI_O_MWORKER)))
                                unbind_listener(l);
-                       /* remove the listener, but we might want to keep some
-                        * for the master in the future... */
-                       delete_listener(l);
+                       /* remove the listener, but not those we need in the master... */
+                       if (!(l->options & LI_O_MWORKER))
+                               delete_listener(l);
                }
        }
 }
index a30d4fb4f6dda180fc50b7760bf93564cfad9602..09ac50bd2f908a5b866ecd6e27e9c725e3959c3f 100644 (file)
@@ -48,6 +48,8 @@ static struct bind_kw_list bind_keywords = {
        .list = LIST_HEAD_INIT(bind_keywords.list)
 };
 
+extern int master;
+
 struct xfer_sock_list *xfer_sock_list = NULL;
 
 /* This function adds the specified listener's file descriptor to the polling
@@ -81,6 +83,12 @@ static void enable_listener(struct listener *listener)
                        listener->state = LI_FULL;
                }
        }
+       /* if this listener is supposed to be only in the master, close it in the workers */
+       if ((global.mode & MODE_MWORKER) &&
+           (listener->options & LI_O_MWORKER) &&
+           master == 0) {
+               do_unbind_listener(listener, 1);
+       }
        HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
 }