From: Willy Tarreau Date: Mon, 10 Aug 2026 16:28:38 +0000 (+0200) Subject: MINOR: debug: make the complain() function start to complete the message X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53ed9fe86ba42abb275bac8008791303e809fe2b;p=thirdparty%2Fhaproxy.git MINOR: debug: make the complain() function start to complete the message The function will be extended to automatically prepend/append some info. For now all it does is to always prepend/append the "\n" that each message has at the beggining and at the end. We're doing this into a locally allocated iovec and emit it at once using writev(). This will be easy to extend to pass extra info. The \n alone removed 1.5 kB of code. --- diff --git a/include/haproxy/bug.h b/include/haproxy/bug.h index 5b408db23..20e9ae758 100644 --- a/include/haproxy/bug.h +++ b/include/haproxy/bug.h @@ -301,7 +301,7 @@ static __attribute__((noinline,noreturn,unused)) void abort_with_line(uint line) #define __ABORT_NOW(file, line, ...) do { \ if (sizeof("" __VA_ARGS__) > 1) \ - complain(DBG_FATL_ABT, "\nABORT at " file ":" #line ": " __VA_ARGS__ "\n"); \ + complain(DBG_FATL_ABT, "ABORT at " file ":" #line ": " __VA_ARGS__); \ ha_backtrace_to_stderr(1); \ abort_with_line(__LINE__); \ } while (0) @@ -411,9 +411,9 @@ extern __attribute__((__weak__)) struct debug_count __stop_dbg_cnt HA_SECTION_S #define __BUG_ON(cond, file, line, details, pfx, sfx, ...) do { \ const char *msg; \ if (sizeof("" __VA_ARGS__) > 1) \ - msg ="\n" pfx "condition \"" #cond "\" matched at " file ":" #line "" sfx "\n" __VA_ARGS__ "\n"; \ + msg = pfx "condition \"" #cond "\" matched at " file ":" #line "" sfx "\n" __VA_ARGS__; \ else \ - msg = "\n" pfx "condition \"" #cond "\" matched at " file ":" #line "" sfx "\n"; \ + msg = pfx "condition \"" #cond "\" matched at " file ":" #line "" sfx; \ complain(details, msg); \ if (details & DBG_DET_FAT_FATL) \ ABORT_NOW(); \ @@ -437,9 +437,9 @@ 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 ="\n" pfx "condition \"" #cond "\" matched at " file ":" #line "" sfx "\n" __VA_ARGS__ "\n"; \ + msg = pfx "condition \"" #cond "\" matched at " file ":" #line "" sfx "\n" __VA_ARGS__; \ else \ - msg = "\n" pfx "condition \"" #cond "\" matched at " file ":" #line "" sfx "\n"; \ + msg = pfx "condition \"" #cond "\" matched at " file ":" #line "" sfx; \ if (_HA_ATOMIC_FETCH_ADD(&__match_count_##line, 1)) \ break; \ complain(details, msg); \ diff --git a/src/debug.c b/src/debug.c index 9c029837a..42f65af6e 100644 --- a/src/debug.c +++ b/src/debug.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -964,13 +965,30 @@ void ha_stuck_warning(void) DISGUISE(write(2, buf.area, buf.data)); } -/* Complain with message on stderr.
is only - * checked on DBG_DET_TYP_BUG, and will taint the process either for a - * bug or warn. +/* 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. */ void complain(uint details, const char *msg) { - DISGUISE(write(2, msg, strlen(msg))); + struct iovec iovec[10]; + int vec = 0; + + iovec[vec].iov_base = "\n"; + iovec[vec].iov_len = 1; + vec++; + + iovec[vec].iov_base = (char *)msg; + iovec[vec].iov_len = strlen(msg); + vec++; + + iovec[vec].iov_base = "\n"; + iovec[vec].iov_len = 1; + vec++; + + DISGUISE(writev(2, iovec, vec)); + if (details & (DBG_DET_TYP_BUG|DBG_DET_TYP_ABT)) mark_tainted(TAINTED_BUG); else if (details & DBG_DET_TYP_WRN)