]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Always define and use ENABLE_DEBUG
authorEmil Velikov <emil.l.velikov@gmail.com>
Tue, 15 Oct 2024 19:36:50 +0000 (20:36 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 17 Oct 2024 14:27:15 +0000 (09:27 -0500)
Convert the "if defined FOO" pre-processor checks for compiler ones "if
(FOO == 1)".

This makes things easier to reason with and ensures both code-paths are
build-tested. In case, the option is disabled DCE will kick in (assuming
you're not force disabling all optimisations) and remove the respective
code.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/173
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
configure.ac
libkmod/libkmod-internal.h
libkmod/libkmod.c
meson.build
tools/log.c

index 500c21790356c3e6917c190e9d8ab8248aae36bb..96749f4b3f0da2660cefa1691fdba5d8b5a818e3 100644 (file)
@@ -216,6 +216,8 @@ AC_ARG_ENABLE([debug],
        [], [enable_debug=no])
 AS_IF([test "x$enable_debug" = "xyes"], [
        AC_DEFINE(ENABLE_DEBUG, [1], [Debug messages.])
+], [
+       AC_DEFINE(ENABLE_DEBUG, [0], [Debug messages.])
 ])
 
 AC_ARG_ENABLE([coverage],
index b4828887cc6e77c10774c2514fffc410d59913ef..cdbd33cf259ffe19bc621e1be4edd6e942389f68 100644 (file)
 
 #include "libkmod.h"
 
-static _always_inline_ _printf_format_(2, 3) void kmod_log_null(const struct kmod_ctx *ctx,
-                                                               const char *format, ...)
-{
-}
-
-#define kmod_log_cond(ctx, prio, arg...)                                          \
-       do {                                                                      \
-               if (ENABLE_LOGGING == 1 && kmod_get_log_priority(ctx) >= prio)    \
-                       kmod_log(ctx, prio, __FILE__, __LINE__, __func__, ##arg); \
+#define kmod_log_cond(ctx, prio, arg...)                                           \
+       do {                                                                       \
+               if (ENABLE_LOGGING == 1 &&                                         \
+                   (ENABLE_DEBUG == 1 || (!ENABLE_DEBUG && prio != LOG_DEBUG)) && \
+                   kmod_get_log_priority(ctx) >= prio)                            \
+                       kmod_log(ctx, prio, __FILE__, __LINE__, __func__, ##arg);  \
        } while (0)
 
-#ifdef ENABLE_DEBUG
 #define DBG(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ##arg)
-#else
-#define DBG(ctx, arg...) kmod_log_null(ctx, ##arg)
-#endif
 #define NOTICE(ctx, arg...) kmod_log_cond(ctx, LOG_NOTICE, ##arg)
 #define INFO(ctx, arg...) kmod_log_cond(ctx, LOG_INFO, ##arg)
 #define ERR(ctx, arg...) kmod_log_cond(ctx, LOG_ERR, ##arg)
index 16b09de715e7722e0f633dd6cb3a4413696930e8..51a10b482397d6423137139317f2c21ff987373e 100644 (file)
@@ -116,11 +116,10 @@ _printf_format_(6, 0) static void log_filep(void *data, int priority, const char
                snprintf(buf, sizeof(buf), "L:%d", priority);
                priname = buf;
        }
-#ifdef ENABLE_DEBUG
-       fprintf(fp, "libkmod: %s %s:%d %s: ", priname, file, line, fn);
-#else
-       fprintf(fp, "libkmod: %s: %s: ", priname, fn);
-#endif
+       if (ENABLE_DEBUG == 1)
+               fprintf(fp, "libkmod: %s %s:%d %s: ", priname, file, line, fn);
+       else
+               fprintf(fp, "libkmod: %s: %s: ", priname, fn);
        vfprintf(fp, format, args);
 }
 
index ed16125730c73bd4d63f6e53fad9e10e7b4a6c44..aac442f13abc90e6970a6523062bb87c0d15b43f 100644 (file)
@@ -19,9 +19,7 @@ cdata.set_quoted('PACKAGE', meson.project_name())
 cdata.set_quoted('VERSION', meson.project_version())
 
 cdata.set10('ENABLE_LOGGING', get_option('logging'))
-if get_option('debug-messages')
-  cdata.set('ENABLE_DEBUG', true)
-endif
+cdata.set10('ENABLE_DEBUG', get_option('debug-messages'))
 
 pkg = import('pkgconfig')
 cc = meson.get_compiler('c')
index 8bd6a59531087cacde075bfaa2e14eb99b49874f..e2e34cae8bfdd716b161ad21b3ca954d5a631309 100644 (file)
@@ -62,19 +62,19 @@ _printf_format_(6, 0) static void log_kmod(void *data, int priority, const char
                return;
 
        if (log_use_syslog) {
-#ifdef ENABLE_DEBUG
-               syslog(priority, "%s: %s:%d %s() %s", prioname, file, line, fn, str);
-#else
-               syslog(priority, "%s: %s", prioname, str);
-#endif
+               if (ENABLE_DEBUG == 1)
+                       syslog(priority, "%s: %s:%d %s() %s", prioname, file, line, fn,
+                              str);
+               else
+                       syslog(priority, "%s: %s", prioname, str);
        } else {
-#ifdef ENABLE_DEBUG
-               fprintf(stderr, "%s: %s: %s:%d %s() %s", program_invocation_short_name,
-                       prioname, file, line, fn, str);
-#else
-               fprintf(stderr, "%s: %s: %s", program_invocation_short_name, prioname,
-                       str);
-#endif
+               if (ENABLE_DEBUG == 1)
+                       fprintf(stderr, "%s: %s: %s:%d %s() %s",
+                               program_invocation_short_name, prioname, file, line, fn,
+                               str);
+               else
+                       fprintf(stderr, "%s: %s: %s", program_invocation_short_name,
+                               prioname, str);
        }
 
        free(str);