]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: debug: use \x1e (RS) to delimit the condition from vaargs in complain()
authorWilly Tarreau <w@1wt.eu>
Mon, 10 Aug 2026 17:27:01 +0000 (19:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 13 Aug 2026 15:43:30 +0000 (17:43 +0200)
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.

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

index 061e5bad92310b17f456fc09eaede82518f5d25d..8844feca2b7bbbaf0eea97fcff02fb653ebc2031 100644 (file)
@@ -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))     \
index a9cb9ed8ff02caa9db12993d54907b23b3f1242e..f107fa783bfda39f444fe1ae3e1240fd9eeaabba 100644 (file)
@@ -968,12 +968,16 @@ void ha_stuck_warning(void)
 /* 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.
+ * 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++;