]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
log: introduce a knob to make assert_return() critical
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 16 Nov 2023 01:48:37 +0000 (10:48 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 23 Dec 2023 16:52:26 +0000 (01:52 +0900)
These can be used to check if we trigger assert_return()
unexpectedly.

Co-authored-by: Frantisek Sumsal <frantisek@sumsal.cz>
src/basic/log.c
src/basic/log.h

index 34e0ccd9560611ca3763dc205abd1be14b51b65e..8bcdfa03e5833cf562096529f88794a94bdf7e0e 100644 (file)
@@ -69,6 +69,7 @@ static bool upgrade_syslog_to_journal = false;
 static bool always_reopen_console = false;
 static bool open_when_needed = false;
 static bool prohibit_ipc = false;
+static bool assert_return_is_critical = false;
 
 /* Akin to glibc's __abort_msg; which is private and we hence cannot
  * use here. */
@@ -981,6 +982,10 @@ void log_assert_failed_return(
                 const char *file,
                 int line,
                 const char *func) {
+
+        if (assert_return_is_critical)
+                log_assert_failed(text, file, line, func);
+
         PROTECT_ERRNO;
         log_assert(LOG_DEBUG, text, file, line, func,
                    "Assertion '%s' failed at %s:%u, function %s(). Ignoring.");
@@ -1232,6 +1237,14 @@ static int log_set_ratelimit_kmsg_from_string(const char *e) {
         return 0;
 }
 
+void log_set_assert_return_is_critical(bool b) {
+        assert_return_is_critical = b;
+}
+
+bool log_get_assert_return_is_critical(void) {
+        return assert_return_is_critical;
+}
+
 static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
 
         /*
index 9008d473909e13f642b8e1275ceba1e7f992a739..140e501eb1ef3e109e3c068bdc46a1b6ad0b8960 100644 (file)
@@ -331,6 +331,9 @@ void log_set_open_when_needed(bool b);
  * stderr, the console or kmsg */
 void log_set_prohibit_ipc(bool b);
 
+void log_set_assert_return_is_critical(bool b);
+bool log_get_assert_return_is_critical(void) _pure_;
+
 int log_dup_console(void);
 
 int log_syntax_internal(