summaryrefslogtreecommitdiffstats
path: root/src/basic/log.h
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-05-10 14:11:55 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-05-11 16:47:40 +0200
commitb9ce5cf9caf52503394ad5eac7a3dee2eee1a296 (patch)
tree81597533b7cc9d504788efa367e2263637250d9c /src/basic/log.h
parentcore: use LOG_UNIT_MESSAGE() where appropriate (diff)
downloadsystemd-b9ce5cf9caf52503394ad5eac7a3dee2eee1a296.tar.xz
systemd-b9ce5cf9caf52503394ad5eac7a3dee2eee1a296.zip
Optionally call printf on LOG_MESSAGE() arguments
With an intentional mistake: ../src/login/logind-dbus.c: In function ‘bus_manager_log_shutdown’: ../src/login/logind-dbus.c:1542:39: error: format ‘%s’ expects a matching ‘char *’ argument [-Werror=format=] 1542 | LOG_MESSAGE("%s %s", message), | ^~~~~~~
Diffstat (limited to '')
-rw-r--r--src/basic/log.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/basic/log.h b/src/basic/log.h
index 6f0d838de3..b03ca3ef21 100644
--- a/src/basic/log.h
+++ b/src/basic/log.h
@@ -300,7 +300,13 @@ bool log_on_console(void) _pure_;
/* Helper to wrap the main message in structured logging. The macro doesn't do much,
* except to provide visual grouping of the format string and its arguments. */
-#define LOG_MESSAGE(fmt, ...) "MESSAGE=" fmt, ##__VA_ARGS__
+#if LOG_MESSAGE_VERIFICATION
+/* Do a fake formatting of the message string to let the scanner verify the arguments
+ * against the format message. */
+# define LOG_MESSAGE(fmt, ...) "MESSAGE=%.0d" fmt, printf(fmt, ##__VA_ARGS__), ##__VA_ARGS__
+#else
+# define LOG_MESSAGE(fmt, ...) "MESSAGE=" fmt, ##__VA_ARGS__
+#endif
void log_received_signal(int level, const struct signalfd_siginfo *si);