summaryrefslogtreecommitdiff
path: root/src/shared/log.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-11-28 03:10:55 +0100
committerLennart Poettering <lennart@poettering.net>2014-11-28 03:16:56 +0100
commitbf371116f69261c17e47dc3dbb51cfaa3c9369ff (patch)
treebad4b11c474ecc5c652e12dbf159e6a7a67ba9a4 /src/shared/log.h
parent95066a906119998011d49d2602f063e74d97f680 (diff)
log: change log_xyz_errno() calls to always return the negative error
This enables us to write things like this: int open_some_file(void) { fd = open("/dev/foobar", O_RDWR|O_CLOEXEC); if (fd < 0) return log_error_errno(errno, "Failed to reboot: %m"); return fd; } Which is function that returns -errno on failure, as well as printing an error message, all in one line.
Diffstat (limited to 'src/shared/log.h')
-rw-r--r--src/shared/log.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/shared/log.h b/src/shared/log.h
index 3180dfd638..a6b933605d 100644
--- a/src/shared/log.h
+++ b/src/shared/log.h
@@ -155,11 +155,13 @@ void log_assert_failed_return(
const char *func);
/* Logging with level */
-#define log_full_errno(level, error, ...) \
- do { \
- if (log_get_max_level() >= (level)) \
- log_internal((level), error, __FILE__, __LINE__, __func__, __VA_ARGS__); \
- } while (false)
+#define log_full_errno(level, error, ...) \
+ ({ \
+ int _l = (level), _e = (error); \
+ (log_get_max_level() >= _l) \
+ ? log_internal(_l, _e, __FILE__, __LINE__, __func__, __VA_ARGS__) \
+ : -abs(_e); \
+ })
#define log_full(level, ...) log_full_errno(level, 0, __VA_ARGS__)