From 5f1fad169063e3ff5c1b41bc387cb9e7a1070320 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Wed, 4 Jun 2025 11:26:27 +0200 Subject: [PATCH] BUG/MINOR: config: emit warning for empty args only in discovery mode Hide warning about empty argument outside of discovery mode. This is necessary, else the message will be displayed twice, which hampers haproxy output lisibility. This should fix github isue #2995. This should be backported up to 3.2. --- src/cfgparse.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/cfgparse.c b/src/cfgparse.c index d0b86d65a..eff0c0296 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -2066,28 +2066,31 @@ next_line: goto next_line; } - for (check_arg = 0; check_arg < arg; check_arg++) { - if (!*args[check_arg]) { - size_t newpos; - - /* if an empty arg was found, its pointer should be in , except - * for rare cases such as '\x00' etc. We need to check errptr in any case - * and if it's not set, we'll fall back to args's position in the output - * string instead (less accurate but still useful). - */ - if (!errptr) { - newpos = args[check_arg] - outline; - if (newpos >= strlen(line)) - newpos = 0; // impossible to report anything, start at the beginning. - errptr = line + newpos; - } + if ((global.mode & MODE_DISCOVERY)) { + /* Only print empty arg warning in discovery mode to prevent double display. */ + for (check_arg = 0; check_arg < arg; check_arg++) { + if (!*args[check_arg]) { + size_t newpos; + + /* if an empty arg was found, its pointer should be in , except + * for rare cases such as '\x00' etc. We need to check errptr in any case + * and if it's not set, we'll fall back to args's position in the output + * string instead (less accurate but still useful). + */ + if (!errptr) { + newpos = args[check_arg] - outline; + if (newpos >= strlen(line)) + newpos = 0; // impossible to report anything, start at the beginning. + errptr = line + newpos; + } - /* sanitize input line in-place */ - newpos = sanitize_for_printing(line, errptr - line, 80); - ha_warning("parsing [%s:%d]: argument number %d at position %d is empty and marks the end of the " - "argument list; all subsequent arguments will be ignored:\n %s\n %*s\n", - file, linenum, check_arg + 1, (int)(errptr - thisline + 1), line, (int)(newpos+1), "^"); - break; + /* sanitize input line in-place */ + newpos = sanitize_for_printing(line, errptr - line, 80); + ha_warning("parsing [%s:%d]: argument number %d at position %d is empty and marks the end of the " + "argument list; all subsequent arguments will be ignored:\n %s\n %*s\n", + file, linenum, check_arg + 1, (int)(errptr - thisline + 1), line, (int)(newpos+1), "^"); + break; + } } } -- 2.47.3