[CRIU] [PATCH 3/4] Move pr_ helpers to log.[ch]
Cyrill Gorcunov
gorcunov at openvz.org
Fri Feb 17 05:08:49 EST 2012
This is a place where they should belong to.
util.c is too big already.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
include/log.h | 32 ++++++++++++++++++++++++++++++++
include/util.h | 34 +---------------------------------
log.c | 14 ++++++++++----
util.c | 10 ----------
4 files changed, 43 insertions(+), 47 deletions(-)
diff --git a/include/log.h b/include/log.h
index 828e631..e6eaaa5 100644
--- a/include/log.h
+++ b/include/log.h
@@ -1,8 +1,40 @@
#ifndef LOG_H__
#define LOG_H__
+extern void printk(const char *format, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
+
extern int init_log(const char *name);
extern void fini_log(void);
extern int get_logfd(void);
+#define pr_info(fmt, ...) printk(fmt, ##__VA_ARGS__)
+#define pr_err(fmt, ...) printk("Error (%s:%d): " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
+#define pr_panic(fmt, ...) printk("PANIC (%s:%d): " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
+#define pr_warning(fmt, ...) printk("Warning (%s:%d): " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
+
+#ifdef CR_DEBUG
+#define pr_debug(fmt, ...) \
+ do { \
+ printk("%s:%d:%s: " fmt, \
+ __FILE__, __LINE__,__func__, \
+ ##__VA_ARGS__); \
+ } while (0)
+#define dprintk(fmt, ...) printk(fmt, ##__VA_ARGS__)
+#else
+#define pr_debug(fmt, ...)
+#define dprintk(fmt, ...)
+#endif
+
+#define die(fmt, ...) \
+ do { \
+ printk("die (%s:%d): " fmt, __FILE__, \
+ __LINE__, ##__VA_ARGS__); \
+ exit(1); \
+ } while (0)
+
+#define pr_perror(fmt, ...) \
+ do { \
+ pr_err(fmt ": %m\n", ##__VA_ARGS__); \
+ } while (0)
+
#endif /* LOG_H__ */
diff --git a/include/util.h b/include/util.h
index 6afb85d..b499ede 100644
--- a/include/util.h
+++ b/include/util.h
@@ -15,9 +15,7 @@
#include "compiler.h"
#include "types.h"
-
-extern void printk(const char *format, ...)
- __attribute__ ((__format__ (__printf__, 1, 2)));
+#include "log.h"
#define PREF_SHIFT_OP(pref, op, size) ((size) op (pref ##BYTES_SHIFT))
#define KBYTES_SHIFT 10
@@ -32,36 +30,6 @@ extern void printk(const char *format, ...)
#define MEGA(size) PREF_SHIFT_OP(K, <<, size)
#define GIGA(size) PREF_SHIFT_OP(K, <<, size)
-#define pr_info(fmt, ...) printk(fmt, ##__VA_ARGS__)
-#define pr_err(fmt, ...) printk("Error (%s:%d): " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
-#define pr_panic(fmt, ...) printk("PANIC (%s:%d): " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
-#define pr_warning(fmt, ...) printk("Warning (%s:%d): " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
-
-#ifdef CR_DEBUG
-#define pr_debug(fmt, ...) \
- do { \
- printk("%s:%d:%s: " fmt, \
- __FILE__, __LINE__,__func__, \
- ##__VA_ARGS__); \
- } while (0)
-#define dprintk(fmt, ...) printk(fmt, ##__VA_ARGS__)
-#else
-#define pr_debug(fmt, ...)
-#define dprintk(fmt, ...)
-#endif
-
-#define die(fmt, ...) \
- do { \
- printk("die (%s:%d): " fmt, __FILE__, \
- __LINE__, ##__VA_ARGS__); \
- exit(1); \
- } while (0)
-
-#define pr_perror(fmt, ...) \
- do { \
- pr_err(fmt ": %m\n", ##__VA_ARGS__); \
- } while (0)
-
#ifndef BUG_ON_HANDLER
#ifdef CR_NOGLIBC
diff --git a/log.c b/log.c
index 8d1929a..3776873 100644
--- a/log.c
+++ b/log.c
@@ -16,10 +16,7 @@
#include "types.h"
#include "util.h"
-/*
- * Note pr_ helpers rely on this
- * descriptor!
- */
+/* Note pr_ helpers rely on this descriptor! */
static int logfd = STDERR_FILENO;
int get_logfd(void)
@@ -69,3 +66,12 @@ void fini_log(void)
logfd = STDERR_FILENO;
}
+
+void printk(const char *format, ...)
+{
+ va_list params;
+
+ va_start(params, format);
+ vdprintf(get_logfd(), format, params);
+ va_end(params);
+}
diff --git a/util.c b/util.c
index d6ca8a4..a159416 100644
--- a/util.c
+++ b/util.c
@@ -34,19 +34,9 @@
#include "types.h"
#include "list.h"
#include "util.h"
-#include "log.h"
#include "crtools.h"
-void printk(const char *format, ...)
-{
- va_list params;
-
- va_start(params, format);
- vdprintf(get_logfd(), format, params);
- va_end(params);
-}
-
void hex_dump(void *addr, unsigned long len)
{
unsigned char *p = addr;
--
1.7.7.6
More information about the CRIU
mailing list