From: Zbigniew Jędrzejewski-Szmek Date: Wed, 14 Apr 2021 11:39:14 +0000 (+0200) Subject: basic/log: assert that %m is not used when error is not set X-Git-Tag: v249-rc1~407^2~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=63275a70323f2535aa943e47e827ec65a7358f0e;p=thirdparty%2Fsystemd.git basic/log: assert that %m is not used when error is not set This is only done in developer mode. It is a pretty rare occurence that we make this kind of mistake. And even if it happens, the result is just a misleading error message. So let's only do the check in non-release builds. --- diff --git a/src/basic/log.h b/src/basic/log.h index 4b621097d45..f7785b016b0 100644 --- a/src/basic/log.h +++ b/src/basic/log.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "macro.h" @@ -197,7 +198,12 @@ void log_assert_failed_return( _e < 0 ? _e : -EIO; \ }) -#define log_full(level, ...) (void) log_full_errno((level), 0, __VA_ARGS__) +#define log_full(level, fmt, ...) \ + ({ \ + if (BUILD_MODE_DEVELOPER) \ + assert(!strstr(fmt, "%m")); \ + (void) log_full_errno((level), 0, fmt, ##__VA_ARGS__); \ + }) int log_emergency_level(void);