]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc/log: Adds error_log_errno macro
authorThomas Parrott <thomas.parrott@canonical.com>
Tue, 21 May 2019 16:25:52 +0000 (17:25 +0100)
committerThomas Parrott <thomas.parrott@canonical.com>
Thu, 11 Jul 2019 10:29:38 +0000 (11:29 +0100)
Suggested usage:

return error_log_errno(err, "Failed: %s", "some error");

It sets errno to the value of err, then calls SYSERROR with the format and remaining args.

It always returns -1.

Suggested-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
src/lxc/log.h

index 5afe4e0935ef1a4a08e6664cf34842729a54e2a8..8b093de90b1d0cc656c5e3be77f6725252a7fa25 100644 (file)
@@ -505,6 +505,13 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo,        \
        } while (0)
 #endif
 
+#define error_log_errno(__errno__, format, ...)        \
+       ({                                              \
+               errno = __errno__;                      \
+               SYSERROR(format, ##__VA_ARGS__);        \
+               -1;                                     \
+       })
+
 extern int lxc_log_fd;
 
 extern int lxc_log_syslog(int facility);