[CRIU] [PATCH 1/3] log: add pr_err_once

Andrey Vagin avagin at openvz.org
Thu Nov 29 07:43:37 EST 2012


This function prints an error message only once.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 include/log.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/log.h b/include/log.h
index d02c4a6..375dd38 100644
--- a/include/log.h
+++ b/include/log.h
@@ -30,6 +30,14 @@ extern void print_on_level(unsigned int loglevel, const char *format, ...)
 #define pr_info(fmt, ...)	\
 	print_on_level(LOG_INFO,	LOG_PREFIX fmt, ##__VA_ARGS__)
 
+#define pr_err_once(fmt, ...) ({	\
+	static bool __printed;		\
+	if (!__printed) {		\
+		print_on_level(LOG_ERROR,	"Error (%s:%d): " LOG_PREFIX fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
+		__printed = 1;		\
+	}				\
+})
+
 #define pr_err(fmt, ...)	\
 	print_on_level(LOG_ERROR,	"Error (%s:%d): " LOG_PREFIX fmt, __FILE__, __LINE__, ##__VA_ARGS__)
 
-- 
1.7.11.7



More information about the CRIU mailing list