]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: turn on log-message-verification by default in developer builds 23351/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 11 May 2022 14:42:13 +0000 (16:42 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 11 May 2022 16:18:59 +0000 (18:18 +0200)
I'm not _quite_ convinced that this a good idea… I'm at least keeping
it separate to make it easy to revert ;)

meson.build
meson_options.txt
src/basic/log.c
src/basic/log.h

index 46f062d5303acd930edb4f394444ea3516467afe..7d4233ca7fa079cf4c64b32fd0ec2a98d23d23b8 100644 (file)
@@ -33,7 +33,13 @@ conf.set_quoted('RELATIVE_SOURCE_PATH', relative_source_path)
 
 conf.set10('BUILD_MODE_DEVELOPER', get_option('mode') == 'developer',
            description : 'tailor build to development or release builds')
-conf.set10('LOG_MESSAGE_VERIFICATION', get_option('log-message-verification'))
+verification = get_option('log-message-verification')
+if verification == 'auto'
+        verification = conf.get('BUILD_MODE_DEVELOPER') == 1
+else
+        verification = verification == 'true'
+endif
+conf.set10('LOG_MESSAGE_VERIFICATION', verification)
 
 want_ossfuzz = get_option('oss-fuzz')
 want_libfuzzer = get_option('llvm-fuzz')
index ff59120f77d0ae6420c3f0e4497314afef0ebadf..26d1170c5046c295d9a2ff4e25a76e0f06da4837 100644 (file)
@@ -470,7 +470,7 @@ option('fuzz-tests', type : 'boolean', value : 'false',
        description : 'run the fuzzer regression tests by default (with sanitizers)')
 option('install-tests', type : 'boolean', value : 'false',
        description : 'install test executables')
-option('log-message-verification', type : 'boolean', value : 'false',
+option('log-message-verification', type : 'combo', choices : ['auto', 'true', 'false'],
        description : 'do fake printf() calls to verify format strings')
 
 option('ok-color', type : 'combo',
index 12071e2ebd3e6edc8639f00e32a4218163c940f9..8f36c1dfadd4127731d4fda7ea2f83a71f601e70 100644 (file)
@@ -67,6 +67,10 @@ static bool prohibit_ipc = false;
  * use here. */
 static char *log_abort_msg = NULL;
 
+#if LOG_MESSAGE_VERIFICATION || defined(__COVERITY__)
+bool _log_message_dummy = false; /* Always false */
+#endif
+
 /* An assert to use in logging functions that does not call recursively
  * into our logging functions (since that might lead to a loop). */
 #define assert_raw(expr)                                                \
index 7b89c4df6348786949eb2ede443c377b409fe361..b7b0a42e49454dc9aa89b007ba094870c94f23b9 100644 (file)
@@ -301,9 +301,10 @@ 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. */
 #if LOG_MESSAGE_VERIFICATION || defined(__COVERITY__)
-/* 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__
+/* Do a fake formatting of the message string to let the scanner verify the arguments against the format
+ * message. The variable will never be set to true, but we don't tell the compiler that :) */
+extern bool _log_message_dummy;
+#  define LOG_MESSAGE(fmt, ...) "MESSAGE=%.0d" fmt, (_log_message_dummy && printf(fmt, ##__VA_ARGS__)), ##__VA_ARGS__
 #else
 #  define LOG_MESSAGE(fmt, ...) "MESSAGE=" fmt, ##__VA_ARGS__
 #endif