]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: debug: make the complain() function start to complete the message
authorWilly Tarreau <w@1wt.eu>
Mon, 10 Aug 2026 16:28:38 +0000 (18:28 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 13 Aug 2026 15:43:30 +0000 (17:43 +0200)
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.

include/haproxy/bug.h
src/debug.c

index 5b408db23bde63593e4889458a476d42e5876e2e..20e9ae7586399c615209b41653ec7093c7a7aed1 100644 (file)
@@ -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);                                 \
index 9c029837a10eeb9f64fbd9adb358cdbd925f49e0..42f65af6ef29211dbd63736cba1be2bc7c8997c8 100644 (file)
@@ -21,6 +21,7 @@
 #include <sys/resource.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <sys/uio.h>
 #include <sys/utsname.h>
 #include <sys/wait.h>
 #include <unistd.h>
@@ -964,13 +965,30 @@ void ha_stuck_warning(void)
        DISGUISE(write(2, buf.area, buf.data));
 }
 
-/* Complain with message <msg> on stderr. <details> is only
- * checked on DBG_DET_TYP_BUG, and will taint the process either for a
- * bug or warn.
+/* Complain with message <msg> on stderr with a '\n' at the begin and at the
+ * end. Depending on the fatality, and type of the event in <details>, 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)