chiark / gitweb /
macro: log assertion at debug level in assert_return()
authorLennart Poettering <lennart@poettering.net>
Tue, 10 Dec 2013 17:01:10 +0000 (17:01 +0000)
committerLennart Poettering <lennart@poettering.net>
Tue, 10 Dec 2013 17:01:10 +0000 (17:01 +0000)
src/libsystemd-bus/bus-control.c
src/libsystemd-id128/sd-id128.c
src/login/sd-login.c
src/shared/log.c
src/shared/log.h
src/shared/macro.h

index 966398944f9799edd23e8205f84fcef1ed3a468e..47e91118a43905db6c36a869dbbc4dde35190e49 100644 (file)
@@ -27,7 +27,6 @@
 #include <errno.h>
 
 #include "strv.h"
-
 #include "sd-bus.h"
 #include "bus-internal.h"
 #include "bus-message.h"
index 3fbad71a52b91a1679718c58334ac3da5f1424f6..07d241534e53378c1d4c6a9042396264b58a28fe 100644 (file)
 #include <fcntl.h>
 #include <unistd.h>
 
-#include "sd-id128.h"
-
 #include "util.h"
 #include "macro.h"
+#include "sd-id128.h"
 
 _public_ char *sd_id128_to_string(sd_id128_t id, char s[33]) {
         unsigned n;
index 7ae3db0397db8df7a9d62204b992f81c0048f85e..c9a2e8a07fbb883e007f553d77779f92d726e880 100644 (file)
 #include "util.h"
 #include "cgroup-util.h"
 #include "macro.h"
-#include "sd-login.h"
 #include "strv.h"
 #include "fileio.h"
 #include "login-shared.h"
+#include "sd-login.h"
 
 _public_ int sd_pid_get_session(pid_t pid, char **session) {
 
index 8f4995a0c8834f3cb5c4e95cc9071705994758da..2531e0da0376cbba486e12fa243f73a70103b4f6 100644 (file)
@@ -687,7 +687,7 @@ int log_meta_object(
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
-_noreturn_ static void log_assert(const char *text, const char *file, int line, const char *func, const char *format) {
+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];
 
         snprintf(buffer, sizeof(buffer), format, text, file, line, func);
@@ -695,17 +695,22 @@ _noreturn_ static void log_assert(const char *text, const char *file, int line,
         char_array_0(buffer);
         log_abort_msg = buffer;
 
-        log_dispatch(LOG_CRIT, file, line, func, NULL, NULL, buffer);
-        abort();
+        log_dispatch(level, file, line, func, NULL, NULL, buffer);
 }
 #pragma GCC diagnostic pop
 
 _noreturn_ void log_assert_failed(const char *text, const char *file, int line, const char *func) {
-        log_assert(text, file, line, func, "Assertion '%s' failed at %s:%u, function %s(). Aborting.");
+        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 *text, const char *file, int line, const char *func) {
-        log_assert(text, file, line, func, "Code should not be reached '%s' at %s:%u, function %s(). Aborting.");
+        log_assert(LOG_CRIT, text, file, line, func, "Code should not be reached '%s' at %s:%u, function %s(). Aborting.");
+        abort();
+}
+
+void log_assert_failed_return(const char *text, const char *file, int line, const char *func) {
+        log_assert(LOG_DEBUG, text, file, line, func, "Assertion '%s' failed at %s:%u, function %s(). Ignoring.");
 }
 
 int log_oom_internal(const char *file, int line, const char *func) {
index 0dc5c261008fd46c22e1b794d566c26a47650581..de0e000371adbbfd081cf9af3bbb04566441497c 100644 (file)
@@ -136,6 +136,12 @@ _noreturn_ void log_assert_failed_unreachable(
                 int line,
                 const char *func);
 
+void log_assert_failed_return(
+                const char *text,
+                const char *file,
+                int line,
+                const char *func);
+
 #define log_full(level, ...) \
 do { \
         if (log_get_max_level() >= (level)) \
index 4198095011c0750437c44041de5cc8d92ac314be..fd3762eed4aae50976bff45148966dbde4cb6764 100644 (file)
@@ -153,10 +153,12 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
 #define assert_cc(expr) struct UNIQUE(_assert_struct_) { char x[(expr) ? 0 : -1]; };
 #endif
 
-#define assert_return(expr, r)                    \
-        do {                                      \
-                if (_unlikely_(!(expr)))          \
-                        return (r);               \
+#define assert_return(expr, r)                                          \
+        do {                                                            \
+                if (_unlikely_(!(expr))) {                              \
+                        log_assert_failed_return(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
+                        return (r);                                     \
+                }                                                       \
         } while (false)
 
 #define PTR_TO_INT(p) ((int) ((intptr_t) (p)))