basic: Move assertion specific functions to assert-util.h

Various functions in log.h are only used by asserts, and there's
enough assertion related stuff in macro.h to justify a separate header
which also makes it easier to avoid circular dependencies.

Let's introduce assert-util.h and an accompanying fundamental header
and move all the assertion related stuff over there. PROJECT_FILE is
moved over to macro.h.
This commit is contained in:
Daan De Meyer
2025-04-18 13:59:06 +02:00
parent edfd847d47
commit 03e17cbe6e
27 changed files with 218 additions and 196 deletions
-68
View File
@@ -78,11 +78,6 @@ 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 = BUILD_MODE_DEVELOPER;
/* Akin to glibc's __abort_msg; which is private and we hence cannot
* use here. */
static char *log_abort_msg = NULL;
static thread_local const char *log_prefix = NULL;
@@ -950,61 +945,6 @@ int log_object_internal(
return r;
}
static void log_assert(
int level,
const char *text,
const char *file,
int line,
const char *func,
const char *format) {
static char buffer[LINE_MAX];
if (_likely_(LOG_PRI(level) > log_max_level))
return;
DISABLE_WARNING_FORMAT_NONLITERAL;
(void) snprintf(buffer, sizeof buffer, format, text, file, line, func);
REENABLE_WARNING;
log_abort_msg = buffer;
log_dispatch_internal(level, 0, file, line, func, NULL, NULL, NULL, NULL, buffer);
}
_noreturn_ void log_assert_failed(
const char *text,
const char *file,
int line,
const char *func) {
log_assert(LOG_CRIT, text, file, line, func,
"Assertion '%s' failed at %s:%u, function %s(). Aborting.");
abort();
}
_noreturn_ void log_assert_failed_unreachable(
const char *file,
int line,
const char *func) {
log_assert(LOG_CRIT, "Code should not be reached", file, line, func,
"%s at %s:%u, function %s(). Aborting. 💥");
abort();
}
void log_assert_failed_return(
const char *text,
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.");
}
int log_oom_internal(int level, const char *file, int line, const char *func) {
return log_internal(level, ENOMEM, file, line, func, "Out of memory.");
}
@@ -1318,14 +1258,6 @@ 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) {
/*