Files
systemd/src/basic/assert-util.h
Zbigniew Jędrzejewski-Szmek 0bb0316f5e Do not use "critical assert_return" in libsystemd or libudev
Previously, when compiled in developer mode, a call into libsystemd with
invalid parameters would result in an abort. This means that it's effectively
impossible to install such libsystemd in a normal system, since various
third-party programs may now abort. A shared library should generally never
abort or exit the calling program.

In python-systemd, the test suite calls into libsystemd, to check if the proper
return values are received and propagated through the Python wrappers.
Obviously with libsystemd compiled from git, the test suite now fails
in a nasty way.

So rework the code to set assert_return_is_critical similarly to how we handle
mempool enablement: the function that returns true is declared as a week
symbol, and we "opt in" by linking a file that provides the function in
libsystemd-shared. Effectively, libsystemd and libudev always have
assert_return_is_critical==false, and our binaries and modules enable it
conditionally.
2025-10-22 10:10:24 +02:00

30 lines
1.4 KiB
C

/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "assert-fundamental.h" /* IWYU pragma: export */
/* Logging for various assertions */
bool log_get_assert_return_is_critical(void) _weak_ _pure_;
void log_assert_failed_return(const char *text, const char *file, int line, const char *func);
#define assert_log(expr) \
(_likely_(expr) ? \
true : \
(log_assert_failed_return(#expr, PROJECT_FILE, __LINE__, __func__), false))
#define assert_return(expr, r) \
do { \
if (!assert_log(expr)) \
return (r); \
} while (false)
#define assert_return_errno(expr, r, err) \
do { \
if (!assert_log(expr)) { \
errno = err; \
return (r); \
} \
} while (false)