[lxc-devel] [lxc/master] lxc/log: Adds error_log_errno macro

tomponline on Github lxc-bot at linuxcontainers.org
Tue May 21 16:28:46 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 615 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190521/834e7c39/attachment.bin>
-------------- next part --------------
From 87e16f3c31f4dd3d1f7e61d0fab774ed6a8bc6cd Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 21 May 2019 17:25:52 +0100
Subject: [PATCH] lxc/log: Adds error_log_errno macro

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.

Suggested-by: Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 src/lxc/log.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/lxc/log.h b/src/lxc/log.h
index 5afe4e0935..8b093de90b 100644
--- a/src/lxc/log.h
+++ b/src/lxc/log.h
@@ -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);


More information about the lxc-devel mailing list