From: Emil Velikov Date: Tue, 15 Oct 2024 19:36:50 +0000 (+0100) Subject: Always define and use ENABLE_LOGGING X-Git-Tag: v34~224 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=75a02302a78d8908561bb7cf3d4de3ddfd486f4f;p=thirdparty%2Fkmod.git Always define and use ENABLE_LOGGING 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 Link: https://github.com/kmod-project/kmod/pull/173 Signed-off-by: Lucas De Marchi --- diff --git a/configure.ac b/configure.ac index a8d1a8a6..500c2179 100644 --- a/configure.ac +++ b/configure.ac @@ -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], diff --git a/libkmod/libkmod-elf.c b/libkmod/libkmod-elf.c index c8193561..23ae76d7 100644 --- a/libkmod/libkmod-elf.c +++ b/libkmod/libkmod-elf.c @@ -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, diff --git a/libkmod/libkmod-internal.h b/libkmod/libkmod-internal.h index 5402eb46..b4828887 100644 --- a/libkmod/libkmod-internal.h +++ b/libkmod/libkmod-internal.h @@ -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"))) diff --git a/meson.build b/meson.build index 251023a6..ed161257 100644 --- a/meson.build +++ b/meson.build @@ -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