]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
DEBUG: rename WARN_ON_ONCE() to CHECK_IF()
authorWilly Tarreau <w@1wt.eu>
Mon, 28 Feb 2022 10:51:23 +0000 (11:51 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 28 Feb 2022 10:51:23 +0000 (11:51 +0100)
The only reason for warning once is to check if a condition really
happens. Let's use a term that better translates the intent, that's
important when reading the code.

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

index cc62e22697e7505d6967bd5892a3a748e8e39ab2..03dea5156f90e97426ecb40a8eaf26b727a722e7 100644 (file)
 #if defined(DEBUG_STRICT)
 #define BUG_ON(cond)       _BUG_ON     (cond, __FILE__, __LINE__, 3, "FATAL: bug ", "")
 #define WARN_ON(cond)      _BUG_ON     (cond, __FILE__, __LINE__, 0, "WARNING: ",   " (please report to developers)")
-#define WARN_ON_ONCE(cond) _BUG_ON_ONCE(cond, __FILE__, __LINE__, 0, "WARNING: ",   " (please report to developers)")
+#define CHECK_IF(cond)     _BUG_ON_ONCE(cond, __FILE__, __LINE__, 0, "WARNING: ",   " (please report to developers)")
 #elif defined(DEBUG_STRICT_NOCRASH)
 #define BUG_ON(cond)       _BUG_ON     (cond, __FILE__, __LINE__, 2, "FATAL: bug ", " (not crashing but process is untrusted now)")
 #define WARN_ON(cond)      _BUG_ON     (cond, __FILE__, __LINE__, 0, "WARNING: ",   " (please report to developers)")
-#define WARN_ON_ONCE(cond) _BUG_ON_ONCE(cond, __FILE__, __LINE__, 0, "WARNING: ",   " (please report to developers)")
+#define CHECK_IF(cond)     _BUG_ON_ONCE(cond, __FILE__, __LINE__, 0, "WARNING: ",   " (please report to developers)")
 #else
 #define BUG_ON(cond)
 #define WARN_ON(cond)
-#define WARN_ON_ONCE(cond)
+#define CHECK_IF(cond)
 #endif
 
 /* When not optimizing, clang won't remove that code, so only compile it in when optimizing */
index e0d3c07f67f4fe5c77bdd44d1505e76522b5fd02..4bc70a0d34d501f64ee36aef20ebf4d7ed2fbfde 100644 (file)
@@ -376,16 +376,16 @@ int debug_parse_cli_warn(char **args, char *payload, struct appctx *appctx, void
        return 1;
 }
 
-/* parse a "debug dev warn1" command. It always returns 1.
+/* parse a "debug dev check" command. It always returns 1.
  * Note: we make sure not to make the function static so that it appears in the trace.
  */
-int debug_parse_cli_warn1(char **args, char *payload, struct appctx *appctx, void *private)
+int debug_parse_cli_check(char **args, char *payload, struct appctx *appctx, void *private)
 {
        if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
                return 1;
 
        _HA_ATOMIC_INC(&debug_commands_issued);
-       WARN_ON_ONCE(one > zero);
+       CHECK_IF(one > zero);
        return 1;
 }
 
@@ -1398,6 +1398,7 @@ REGISTER_PER_THREAD_INIT(init_debug_per_thread);
 /* register cli keywords */
 static struct cli_kw_list cli_kws = {{ },{
        {{ "debug", "dev", "bug", NULL },      "debug dev bug                           : call BUG_ON() and crash",                 debug_parse_cli_bug,   NULL, NULL, NULL, ACCESS_EXPERT },
+       {{ "debug", "dev", "check", NULL },    "debug dev check                         : call CHECK_IF() and possibly crash",      debug_parse_cli_check, NULL, NULL, NULL, ACCESS_EXPERT },
        {{ "debug", "dev", "close", NULL },    "debug dev close  <fd>                   : close this file descriptor",              debug_parse_cli_close, NULL, NULL, NULL, ACCESS_EXPERT },
        {{ "debug", "dev", "delay", NULL },    "debug dev delay  [ms]                   : sleep this long",                         debug_parse_cli_delay, NULL, NULL, NULL, ACCESS_EXPERT },
 #if defined(DEBUG_DEV)
@@ -1417,7 +1418,6 @@ static struct cli_kw_list cli_kws = {{ },{
        {{ "debug", "dev", "sym",   NULL },    "debug dev sym    <addr>                 : resolve symbol address",                  debug_parse_cli_sym,   NULL, NULL, NULL, ACCESS_EXPERT },
        {{ "debug", "dev", "tkill", NULL },    "debug dev tkill  [thr] [sig]            : send signal to thread",                   debug_parse_cli_tkill, NULL, NULL, NULL, ACCESS_EXPERT },
        {{ "debug", "dev", "warn",  NULL },    "debug dev warn                          : call WARN_ON() and possibly crash",       debug_parse_cli_warn,  NULL, NULL, NULL, ACCESS_EXPERT },
-       {{ "debug", "dev", "warn1", NULL },    "debug dev warn1                         : call WARN_ON_ONCE() and possibly crash",  debug_parse_cli_warn1, NULL, NULL, NULL, ACCESS_EXPERT },
        {{ "debug", "dev", "write", NULL },    "debug dev write  [size]                 : write that many bytes in return",         debug_parse_cli_write, NULL, NULL, NULL, ACCESS_EXPERT },
 #if defined(HA_HAVE_DUMP_LIBS)
        {{ "show", "libs", NULL, NULL },       "show libs                               : show loaded object files and libraries", debug_parse_cli_show_libs, NULL, NULL },