From 2a0cf52cfc3a7290d1e016b9e2877638462101ac Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Sun, 8 Mar 2026 01:10:45 +0100 Subject: [PATCH] MEDIUM: admin: haproxy-reload conversion to POSIX sh The script relied on a bash-specific process substitution (< <(...)) to feed socat's output into the read loop. This is replaced with a standard POSIX pipe into a command group. The response parsing is also simplified: instead of iterating over each line with a while loop and echoing them individually, the status line is read first, the "--" separator consumed, and the remaining output is streamed to stderr or discarded as a whole depending on the verbosity level. Could be backported to 3.3 as it makes it more portable, but introduce a slight change in the error format. --- admin/cli/haproxy-reload | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/admin/cli/haproxy-reload b/admin/cli/haproxy-reload index b592d98e9..a3f07ef45 100755 --- a/admin/cli/haproxy-reload +++ b/admin/cli/haproxy-reload @@ -1,11 +1,10 @@ -#!/bin/bash +#!/bin/sh set -e export VERBOSE=1 export TIMEOUT=90 export MASTER_SOCKET="${MASTER_SOCKET:-/var/run/haproxy-master.sock}" -export RET= alert() { if [ "$VERBOSE" -ge "1" ]; then @@ -28,32 +27,25 @@ reload() { ;; esac fi - while read -r line; do - if [ "$line" = "Success=0" ]; then - RET=1 - elif [ "$line" = "Success=1" ]; then - RET=0 - elif [ "$line" = "Another reload is still in progress." ]; then - alert "$line" - elif [ "$line" = "--" ]; then - continue; + echo "reload" | socat -t"${TIMEOUT}" "$socat_addr" - | { + read -r status || { alert "No status received (connection error or timeout after ${TIMEOUT}s)."; exit 1; } + case "$status" in + "Success=1") ret=0 ;; + "Success=0") ret=1 ;; + *) alert "Unexpected response: '$status'"; exit 1 ;; + esac + + read -r _ # consume "--" + + if [ "$VERBOSE" -ge 3 ] || { [ "$ret" = 1 ] && [ "$VERBOSE" -ge 2 ]; }; then + cat >&2 else - if [ "$RET" = 1 ] && [ "$VERBOSE" = "2" ]; then - echo "$line" >&2 - elif [ "$VERBOSE" = "3" ]; then - echo "$line" >&2 - fi + cat >/dev/null fi - done < <(echo "reload" | socat -t"${TIMEOUT}" "$socat_addr" -) - - if [ -z "$RET" ]; then - alert "Couldn't finish the reload before the timeout (${TIMEOUT})." - return 1 - fi - - return "$RET" + exit "$ret" + } } usage() {