summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-02-23 13:29:03 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-02-23 13:29:03 +0100
commit780747da75b737b5036f8c17fb99c54c52762eed (patch)
tree56677f5d576547c254814c92bd67d722651d8c1f /src
parent73fc96c8ac0aa95477e53838a22ce94918c9d06f (diff)
downloadsystemd-780747da75b737b5036f8c17fb99c54c52762eed.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/basic/log.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/basic/log.c b/src/basic/log.c
index 19c4ec7649..72b60da6c6 100644
--- a/src/basic/log.c
+++ b/src/basic/log.c
@@ -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;