From: Willy Tarreau Date: Mon, 10 Aug 2026 17:27:01 +0000 (+0200) Subject: MEDIUM: debug: use \x1e (RS) to delimit the condition from vaargs in complain() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85c897f30675e63b399e87149bee9761f42bb365;p=thirdparty%2Fhaproxy.git MEDIUM: debug: use \x1e (RS) to delimit the condition from vaargs in complain() This is the same principle as for DBG_COUNT() but applied to complain(). For now it doesn't bring any particular benefit but we needed to know where the end of the string is in order to continue to turn other fields to variables. --- diff --git a/include/haproxy/bug.h b/include/haproxy/bug.h index 061e5bad9..8844feca2 100644 --- a/include/haproxy/bug.h +++ b/include/haproxy/bug.h @@ -412,7 +412,7 @@ extern __attribute__((__weak__)) struct debug_count __stop_dbg_cnt HA_SECTION_S #define __BUG_ON(cond, file, line, details, sfx, ...) do { \ const char *msg; \ if (sizeof("" __VA_ARGS__) > 1) \ - msg = "\"" #cond "\" matched at " file ":" #line "" sfx "\n" __VA_ARGS__; \ + msg = "\"" #cond "\" matched at " file ":" #line "" sfx "\x1e" __VA_ARGS__; \ else \ msg = "\"" #cond "\" matched at " file ":" #line "" sfx; \ complain(details, msg); \ @@ -438,7 +438,7 @@ extern __attribute__((__weak__)) struct debug_count __stop_dbg_cnt HA_SECTION_S static int __match_count_##line; \ const char *msg; \ if (sizeof("" __VA_ARGS__) > 1) \ - msg = "\"" #cond "\" matched at " file ":" #line "" sfx "\n" __VA_ARGS__; \ + msg = "\"" #cond "\" matched at " file ":" #line "" sfx "\x1e" __VA_ARGS__; \ else \ msg = "\"" #cond "\" matched at " file ":" #line "" sfx; \ if (_HA_ATOMIC_FETCH_ADD(&__match_count_##line, 1)) \ diff --git a/src/debug.c b/src/debug.c index a9cb9ed8f..f107fa783 100644 --- a/src/debug.c +++ b/src/debug.c @@ -968,12 +968,16 @@ void ha_stuck_warning(void) /* Complain with message on stderr with a '\n' at the begin and at the * end. Depending on the fatality, and type of the event in
, a * different prefix will be appended. Then the event type may result in some - * taining of the process to happen. + * taining of the process to happen. If the string contains an RS char (\x1e) + * then it's used as a delimiter: the main message stops there, and what + * follows is a new line that will be appended after another LF (normally it's + * used to give extra info to the user about the issue's location). */ void complain(uint details, const char *msg) { struct iovec iovec[10]; const char *pfx; + const char *rs; int vec = 0; iovec[vec].iov_base = "\n"; @@ -1008,10 +1012,26 @@ void complain(uint details, const char *msg) vec++; } + /* make rs point either to the RS or to \0 */ + rs = strchr(msg, '\x1e'); + if (!rs) + rs = msg + strlen(msg); + iovec[vec].iov_base = (char *)msg; - iovec[vec].iov_len = strlen(msg); + iovec[vec].iov_len = rs - msg; vec++; + if (*rs) { + /* there's an extra string */ + iovec[vec].iov_base = "\n"; + iovec[vec].iov_len = 1; + vec++; + + iovec[vec].iov_base = (char *)rs + 1; + iovec[vec].iov_len = strlen(rs + 1); + vec++; + } + iovec[vec].iov_base = "\n"; iovec[vec].iov_len = 1; vec++;