mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-02-04 17:47:03 +03:00
basic/log: add an assert that does not recurse into logging functions
Then it can be used in the asserts in logging functions without causing infinite recursion. The error is just printed to stderr, it should be good enough for the common case.
This commit is contained in:
parent
73fc96c8ac
commit
780747da75
@ -83,6 +83,16 @@ static bool prohibit_ipc = false;
|
||||
* use here. */
|
||||
static char *log_abort_msg = NULL;
|
||||
|
||||
/* 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) \
|
||||
do { \
|
||||
if (_unlikely_(!(expr))) { \
|
||||
fputs(#expr "\n", stderr); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
static void log_close_console(void) {
|
||||
|
||||
if (console_fd < 0)
|
||||
@ -531,7 +541,7 @@ static int log_do_header(
|
||||
isempty(extra) ? "" : extra,
|
||||
isempty(extra) ? "" : "\n",
|
||||
program_invocation_short_name);
|
||||
assert((size_t) r < size);
|
||||
assert_raw((size_t) r < size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -583,7 +593,7 @@ int log_dispatch_internal(
|
||||
const char *extra,
|
||||
char *buffer) {
|
||||
|
||||
assert(buffer);
|
||||
assert_raw(buffer);
|
||||
|
||||
if (error < 0)
|
||||
error = -error;
|
||||
|
Loading…
x
Reference in New Issue
Block a user