]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Always define and use ENABLE_LOGGING
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-elf.c
libkmod/libkmod-internal.h
meson.build

index a8d1a8a692dc90943f09613d181d0e8ca86be6f8..500c21790356c3e6917c190e9d8ab8248aae36bb 100644 (file)
@@ -207,6 +207,8 @@ AC_ARG_ENABLE([logging],
        [], enable_logging=yes)
 AS_IF([test "x$enable_logging" = "xyes"], [
        AC_DEFINE(ENABLE_LOGGING, [1], [System logging.])
+], [
+       AC_DEFINE(ENABLE_LOGGING, [0], [System logging.])
 ])
 
 AC_ARG_ENABLE([debug],
index c8193561cd906926be8694c39414c6cdd87e7da7..23ae76d73de7fa9ebe6ab4bab52bf47a9a52d89e 100644 (file)
@@ -55,7 +55,7 @@ struct kmod_elf {
 
 //#define ENABLE_ELFDBG 1
 
-#if defined(ENABLE_LOGGING) && defined(ENABLE_ELFDBG)
+#if (ENABLE_LOGGING == 1) && defined(ENABLE_ELFDBG)
 #define ELFDBG(elf, ...) _elf_dbg(elf, __FILE__, __LINE__, __func__, __VA_ARGS__);
 
 static inline void _elf_dbg(const struct kmod_elf *elf, const char *fname, unsigned line,
index 5402eb46e4bbc9032462841475204941aee40082..b4828887cc6e77c10774c2514fffc410d59913ef 100644 (file)
@@ -17,11 +17,10 @@ static _always_inline_ _printf_format_(2, 3) void kmod_log_null(const struct kmo
 
 #define kmod_log_cond(ctx, prio, arg...)                                          \
        do {                                                                      \
-               if (kmod_get_log_priority(ctx) >= prio)                           \
+               if (ENABLE_LOGGING == 1 && kmod_get_log_priority(ctx) >= prio)    \
                        kmod_log(ctx, prio, __FILE__, __LINE__, __func__, ##arg); \
        } while (0)
 
-#ifdef ENABLE_LOGGING
 #ifdef ENABLE_DEBUG
 #define DBG(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ##arg)
 #else
@@ -30,12 +29,6 @@ static _always_inline_ _printf_format_(2, 3) void kmod_log_null(const struct kmo
 #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)
-#else
-#define DBG(ctx, arg...) kmod_log_null(ctx, ##arg)
-#define NOTICE(ctx, arg...) kmod_log_null(ctx, ##arg)
-#define INFO(ctx, arg...) kmod_log_null(ctx, ##arg)
-#define ERR(ctx, arg...) kmod_log_null(ctx, ##arg)
-#endif
 
 #define KMOD_EXPORT __attribute__((visibility("default")))
 
index 251023a66fb962bf570ee4e36b2ddc65a9d6ef75..ed16125730c73bd4d63f6e53fad9e10e7b4a6c44 100644 (file)
@@ -18,9 +18,7 @@ cdata = configuration_data()
 cdata.set_quoted('PACKAGE', meson.project_name())
 cdata.set_quoted('VERSION', meson.project_version())
 
-if get_option('logging')
-  cdata.set('ENABLE_LOGGING', true)
-endif
+cdata.set10('ENABLE_LOGGING', get_option('logging'))
 if get_option('debug-messages')
   cdata.set('ENABLE_DEBUG', true)
 endif