diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2013-11-04 18:18:47 +0100 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2013-11-04 18:18:47 +0100 |
commit | d3cfd0e31e7fb9150942aee537af6e38cd4d4058 (patch) | |
tree | 9cc47c8544c54c5cdf4d78d49c2ae6045c1d2195 | |
parent | 26ef7dae09dd27c837290c294063c20f5da9e537 (diff) |
shl: add l+og_ERR() handlers
New l+og_ERR() handlers automatically set errno and then forward the error
code so we can make use of %m.
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
-rw-r--r-- | src/shl_llog.h | 10 | ||||
-rw-r--r-- | src/shl_log.h | 6 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/shl_llog.h b/src/shl_llog.h index 6afb768..1dd4a3c 100644 --- a/src/shl_llog.h +++ b/src/shl_llog.h @@ -55,6 +55,7 @@ #ifndef SHL_LLOG_H #define SHL_LLOG_H +#include <errno.h> #include <stdarg.h> #include <stdbool.h> #include <stdlib.h> @@ -234,4 +235,13 @@ void llog_dummyf(llog_submit_t llog, void *data, unsigned int sev, #define llog_vdERRNO(obj, data) \ ((void)llog_dERRNO((obj), (data))) +#define llog_dERR(obj, data, _r) \ + (errno = -(_r), llog_derror((obj), (data), "syscall failed (%d): %m", (_r)), (_r)) +#define llog_ERR(obj, _r) \ + (llog_dERR((obj)->llog, (obj)->llog_data, (_r))) +#define llog_vERR(obj, _r) \ + ((void)llog_ERR((obj), (_r))) +#define llog_vdERR(obj, data, _r) \ + ((void)llog_dERR((obj), (data), (_r))) + #endif /* SHL_LLOG_H */ diff --git a/src/shl_log.h b/src/shl_log.h index f141db6..d51d001 100644 --- a/src/shl_log.h +++ b/src/shl_log.h @@ -16,6 +16,7 @@ #ifndef SHL_LOG_H #define SHL_LOG_H +#include <errno.h> #include <stdarg.h> #include <stdbool.h> #include <stdlib.h> @@ -187,4 +188,9 @@ extern const char *LOG_SUBSYSTEM; #define log_vERRNO() \ ((void)log_ERRNO()) +#define log_ERR(_r) \ + (errno = -(_r), log_error("syscall failed (%d): %m", (_r)), (_r)) +#define log_vERR(_r) \ + ((void)log_ERR(_r)) + #endif /* SHL_LOG_H */ |