]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: admin: haproxy-reload use explicit socat address type
authorWilliam Lallemand <wlallemand@irq6.net>
Sat, 7 Mar 2026 23:41:36 +0000 (00:41 +0100)
committerWilliam Lallemand <wlallemand@irq6.net>
Sun, 8 Mar 2026 00:33:29 +0000 (01:33 +0100)
socat was used with the ${MASTER_SOCKET} variable directly, letting it
auto-detect the network protocol. However, when given a plain filename
that does not point to a UNIX socket, socat would create a file at that
path instead of reporting an error.

To fix this, the address type is now determined explicitly: if
MASTER_SOCKET points to an existing UNIX socket file (checked with -S),
UNIX-CONNECT: is used; if it matches a <host>:<port> pattern, TCP: is
used; otherwise an error is reported. The socat_addr variable is also
properly scoped as local to the reload() function.

Could be backported in 3.3.

admin/cli/haproxy-reload

index 22da7bd9fecfd1e4d7e2ef275e16fcccb1e9f1fb..b592d98e9ef86d9a28079c98cce9a68f44f08db8 100755 (executable)
@@ -4,7 +4,7 @@ set -e
 
 export VERBOSE=1
 export TIMEOUT=90
-export MASTER_SOCKET=${MASTER_SOCKET:-/var/run/haproxy-master.sock}
+export MASTER_SOCKET="${MASTER_SOCKET:-/var/run/haproxy-master.sock}"
 export RET=
 
 alert() {
@@ -15,6 +15,19 @@ alert() {
 
 
 reload() {
+       if [ -S "$MASTER_SOCKET" ]; then
+               socat_addr="UNIX-CONNECT:${MASTER_SOCKET}"
+       else
+               case "$MASTER_SOCKET" in
+                       *:[0-9]*)
+                               socat_addr="TCP:${MASTER_SOCKET}"
+                               ;;
+                       *)
+                               alert "Invalid master socket address '${MASTER_SOCKET}': expected a UNIX socket file or <host>:<port>"
+                               return 1
+                               ;;
+               esac
+       fi
        while read -r line; do
 
                if [ "$line" = "Success=0" ]; then
@@ -33,7 +46,7 @@ reload() {
                        fi
                fi
 
-       done < <(echo "reload" | socat -t"${TIMEOUT}" "${MASTER_SOCKET}" -)
+       done < <(echo "reload" | socat -t"${TIMEOUT}" "$socat_addr" -)
 
        if [ -z "$RET" ]; then
                alert "Couldn't finish the reload before the timeout (${TIMEOUT})."
@@ -52,7 +65,7 @@ usage() {
        echo " EXPERIMENTAL script!"
        echo ""
        echo "Options:"
-       echo "  -S,  --master-socket <path>   Use the master socket at <path> (default: ${MASTER_SOCKET})"
+       echo "  -S,  --master-socket <addr>   Unix socket path or <host>:<port> (default: ${MASTER_SOCKET})"
        echo "  -d,  --debug                  Debug mode, set -x"
        echo "  -t,  --timeout                Timeout (socat -t) (default: ${TIMEOUT})"
        echo "  -s,  --silent                 Silent mode (no output)"