[CRIU] [PATCH 2/3] compel/uapi: add prefix to log levels

Kir Kolyshkin kir at openvz.org
Thu Feb 9 20:03:49 PST 2017


These are part of compel UAPI so should be prefixed with COMPEL_
in order to not pollute the namespace. While at it, move from
set of defines to an enum, which looks a bit cleaner.

Also, kill LOG_UNDEF as it's not used anywhere.

Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
 compel/include/log.h            | 13 +++++++------
 compel/include/uapi/log.h       |  4 ++++
 compel/include/uapi/loglevels.h | 23 +++++++++++++++--------
 compel/plugins/std/log.c        |  4 ++--
 compel/src/lib/log.c            |  2 +-
 compel/src/main.c               |  6 +++---
 compel/test/infect/spy.c        |  2 +-
 compel/test/rsys/spy.c          |  2 +-
 8 files changed, 34 insertions(+), 22 deletions(-)

diff --git a/compel/include/log.h b/compel/include/log.h
index 8c43c5b..1eea1f9 100644
--- a/compel/include/log.h
+++ b/compel/include/log.h
@@ -10,22 +10,23 @@
 
 static inline int pr_quelled(unsigned int loglevel)
 {
-	return compel_log_get_loglevel() < loglevel && loglevel != LOG_MSG;
+	return compel_log_get_loglevel() < loglevel
+		&& loglevel != COMPEL_LOG_MSG;
 }
 
 extern void compel_print_on_level(unsigned int loglevel,
 		const char *format, ...);
 
 #define pr_msg(fmt, ...)						\
-	compel_print_on_level(LOG_MSG,					\
+	compel_print_on_level(COMPEL_LOG_MSG,				\
 		       fmt, ##__VA_ARGS__)
 
 #define pr_info(fmt, ...)						\
-	compel_print_on_level(LOG_INFO,					\
+	compel_print_on_level(COMPEL_LOG_INFO,				\
 		       LOG_PREFIX fmt, ##__VA_ARGS__)
 
 #define pr_err(fmt, ...)						\
-	compel_print_on_level(LOG_ERROR,				\
+	compel_print_on_level(COMPEL_LOG_ERROR,				\
 		       "Error (%s:%d): " LOG_PREFIX fmt,		\
 		       __FILE__, __LINE__, ##__VA_ARGS__)
 
@@ -39,7 +40,7 @@ extern void compel_print_on_level(unsigned int loglevel,
 	} while (0)
 
 #define pr_warn(fmt, ...)						\
-	compel_print_on_level(LOG_WARN,					\
+	compel_print_on_level(COMPEL_LOG_WARN,				\
 		       "Warn  (%s:%d): " LOG_PREFIX fmt			\
 		       __FILE__, __LINE__, ##__VA_ARGS__)
 
@@ -53,7 +54,7 @@ extern void compel_print_on_level(unsigned int loglevel,
 	} while (0)
 
 #define pr_debug(fmt, ...)						\
-	compel_print_on_level(LOG_DEBUG,				\
+	compel_print_on_level(COMPEL_LOG_DEBUG,				\
 		       LOG_PREFIX fmt, ##__VA_ARGS__)
 
 #define pr_perror(fmt, ...)						\
diff --git a/compel/include/uapi/log.h b/compel/include/uapi/log.h
index cd3bf2a..79dd1f4 100644
--- a/compel/include/uapi/log.h
+++ b/compel/include/uapi/log.h
@@ -1,7 +1,11 @@
 #ifndef __COMPEL_UAPI_LOG_H__
 #define __COMPEL_UAPI_LOG_H__
+
+#include <stdarg.h>
 #include <compel/loglevels.h>
+
 typedef void (*compel_log_fn)(unsigned int lvl, const char *fmt, va_list parms);
 extern void compel_log_init(compel_log_fn log_fn, unsigned int level);
 extern unsigned int compel_log_get_loglevel(void);
+
 #endif
diff --git a/compel/include/uapi/loglevels.h b/compel/include/uapi/loglevels.h
index f7cdcc4..7bf8847 100644
--- a/compel/include/uapi/loglevels.h
+++ b/compel/include/uapi/loglevels.h
@@ -1,13 +1,20 @@
 #ifndef UAPI_COMPEL_LOGLEVELS_H__
 #define UAPI_COMPEL_LOGLEVELS_H__
 
-#define LOG_UNSET		(-1)
-#define LOG_MSG			(0) /* Print message regardless of log level */
-#define LOG_ERROR		(1) /* Errors only, when we're in trouble */
-#define LOG_WARN		(2) /* Warnings, dazen and confused but trying to continue */
-#define LOG_INFO		(3) /* Informative, everything is fine */
-#define LOG_DEBUG		(4) /* Debug only */
-
-#define DEFAULT_LOGLEVEL	LOG_WARN
+/*
+ * Log levels used by compel itself (see compel_log_init()),
+ * also by log functions in the std plugin.
+ */
+
+enum __compel_log_levels
+{
+	COMPEL_LOG_MSG,		/* Print message regardless of log level */
+	COMPEL_LOG_ERROR,	/* Errors only, when we're in trouble */
+	COMPEL_LOG_WARN,	/* Warnings */
+	COMPEL_LOG_INFO,	/* Informative, everything is fine */
+	COMPEL_LOG_DEBUG,	/* Debug only */
+
+	COMPEL_DEFAULT_LOGLEVEL	= COMPEL_LOG_WARN
+};
 
 #endif /* UAPI_COMPEL_LOGLEVELS_H__ */
diff --git a/compel/plugins/std/log.c b/compel/plugins/std/log.c
index 52a3f1a..2d622d6 100644
--- a/compel/plugins/std/log.c
+++ b/compel/plugins/std/log.c
@@ -2,7 +2,7 @@
 
 #include "common/bitsperlong.h"
 #include <compel/plugins/std/syscall.h>
-#include "uapi/std/string.h"
+#include <compel/plugins/std/string.h>
 #include <compel/plugins/std/log.h>
 #include <compel/loglevels.h>
 
@@ -14,7 +14,7 @@ struct simple_buf {
 };
 
 static int logfd = -1;
-static int cur_loglevel = DEFAULT_LOGLEVEL;
+static int cur_loglevel = COMPEL_DEFAULT_LOGLEVEL;
 static struct timeval start;
 
 static void sbuf_log_flush(struct simple_buf *b);
diff --git a/compel/src/lib/log.c b/compel/src/lib/log.c
index 4c98407..d195343 100644
--- a/compel/src/lib/log.c
+++ b/compel/src/lib/log.c
@@ -11,7 +11,7 @@
 
 #include "log.h"
 
-static unsigned int current_loglevel = DEFAULT_LOGLEVEL;
+static unsigned int current_loglevel = COMPEL_DEFAULT_LOGLEVEL;
 static compel_log_fn logfn;
 
 void compel_log_init(compel_log_fn log_fn, unsigned int level)
diff --git a/compel/src/main.c b/compel/src/main.c
index 33dc2aa..ea3da89 100644
--- a/compel/src/main.c
+++ b/compel/src/main.c
@@ -110,7 +110,7 @@ static void cli_log(unsigned int lvl, const char *fmt, va_list parms)
 	if (pr_quelled(lvl))
 		return;
 
-	if ((lvl == LOG_ERROR) || (lvl == LOG_WARN))
+	if ((lvl == COMPEL_LOG_ERROR) || (lvl == COMPEL_LOG_WARN))
 		f = stderr;
 
 	vfprintf(f, fmt, parms);
@@ -130,7 +130,7 @@ static int usage(int rc) {
 "    -l, --log-level NUM		log level (default: %d)\n"
 "  compel -h|--help\n"
 "  compel -V|--version\n"
-, DEFAULT_LOGLEVEL
+, COMPEL_DEFAULT_LOGLEVEL
 );
 
 	return rc;
@@ -283,7 +283,7 @@ static char *gen_prefix(const char *path)
 
 int main(int argc, char *argv[])
 {
-	int log_level = DEFAULT_LOGLEVEL;
+	int log_level = COMPEL_DEFAULT_LOGLEVEL;
 	bool compat = false;
 	bool is_static = false;
 	int opt, idx;
diff --git a/compel/test/infect/spy.c b/compel/test/infect/spy.c
index c628a0f..b8a65c3 100644
--- a/compel/test/infect/spy.c
+++ b/compel/test/infect/spy.c
@@ -24,7 +24,7 @@ static int do_infection(int pid)
 	struct infect_ctx *ictx;
 	int *arg;
 
-	compel_log_init(print_vmsg, LOG_DEBUG);
+	compel_log_init(print_vmsg, COMPEL_LOG_DEBUG);
 
 	printf("Stopping task\n");
 	state = compel_stop_task(pid);
diff --git a/compel/test/rsys/spy.c b/compel/test/rsys/spy.c
index 82c9725..f5c999d 100644
--- a/compel/test/rsys/spy.c
+++ b/compel/test/rsys/spy.c
@@ -20,7 +20,7 @@ static int do_rsetsid(int pid)
 	long ret;
 	struct parasite_ctl *ctl;
 
-	compel_log_init(print_vmsg, LOG_DEBUG);
+	compel_log_init(print_vmsg, COMPEL_LOG_DEBUG);
 
 	printf("Stopping task\n");
 	state = compel_stop_task(pid);
-- 
2.9.3



More information about the CRIU mailing list