From: Willy Tarreau Date: Wed, 7 Oct 2020 14:50:49 +0000 (+0200) Subject: MINOR: protocol: add protocol_stop_now() to instant-stop listeners X-Git-Tag: v2.3-dev6~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=02e8557e8812892ee61218797b61e3e60cb2764c;p=thirdparty%2Fhaproxy.git MINOR: protocol: add protocol_stop_now() to instant-stop listeners This will instantly stop all listeners except those which belong to a proxy configured with a grace time. This means that UDP listeners, and peers will also be stopped when called this way. --- diff --git a/include/haproxy/protocol.h b/include/haproxy/protocol.h index a752f98d96..81f4d5bdbb 100644 --- a/include/haproxy/protocol.h +++ b/include/haproxy/protocol.h @@ -50,6 +50,14 @@ int protocol_bind_all(int verbose); */ int protocol_unbind_all(void); +/* stops all listeners of all registered protocols, except when the belong to a + * proxy configured with a grace time. This will normally catch every single + * listener, all protocols included, and the grace ones will have to be handled + * by the proxy stopping loop. This is to be used during soft_stop() only. It + * does not return any error. + */ +void protocol_stop_now(void); + /* pauses all listeners of all registered protocols. This is typically * used on SIG_TTOU to release all listening sockets for the time needed to * try to bind a new process. The listeners enter LI_PAUSED. It returns diff --git a/src/protocol.c b/src/protocol.c index c0a00904ca..82deaad4f8 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -151,6 +151,26 @@ int protocol_unbind_all(void) return err; } +/* stops all listeners of all registered protocols, except when the belong to a + * proxy configured with a grace time. This will normally catch every single + * listener, all protocols included, and the grace ones will have to be handled + * by the proxy stopping loop. This is to be used during soft_stop() only. It + * does not return any error. + */ +void protocol_stop_now(void) +{ + struct protocol *proto; + struct listener *listener, *lback; + + HA_SPIN_LOCK(PROTO_LOCK, &proto_lock); + list_for_each_entry(proto, &protocols, list) { + list_for_each_entry_safe(listener, lback, &proto->receivers, rx.proto_list) + if (!listener->bind_conf->frontend->grace) + stop_listener(listener, 0, 1, 0); + } + HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock); +} + /* pauses all listeners of all registered protocols. This is typically * used on SIG_TTOU to release all listening sockets for the time needed to * try to bind a new process. The listeners enter LI_PAUSED. It returns