]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/log: assert that %m is not used when error is not set
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 14 Apr 2021 11:39:14 +0000 (13:39 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 14 Apr 2021 14:19:54 +0000 (16:19 +0200)
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.

src/basic/log.h

index 4b621097d45f4006579c39af57d71b8c41d388c5..f7785b016b0f446ecf6b9a99b0ad84ebea3fd469 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdarg.h>
 #include <stdbool.h>
 #include <stdlib.h>
+#include <string.h>
 #include <syslog.h>
 
 #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);