[CRIU] [PATCH 1/6] criu: pie, log -- Prepate to move into compel std plugin

Cyrill Gorcunov gorcunov at openvz.org
Wed Nov 16 07:06:48 PST 2016


 - Add uapi header and start using it
 - Add std_ prefix into functions and constants
 - Drop unneeded headers

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 compel/plugins/include/uapi/std/log.h | 14 ++++++++++++++
 criu/include/log.h                    |  9 ---------
 criu/pie/infect.c                     |  7 ++++---
 criu/pie/log-simple.c                 | 23 +++++++++++------------
 criu/pie/restorer.c                   | 13 +++++++------
 5 files changed, 36 insertions(+), 30 deletions(-)
 create mode 100644 compel/plugins/include/uapi/std/log.h

diff --git a/compel/plugins/include/uapi/std/log.h b/compel/plugins/include/uapi/std/log.h
new file mode 100644
index 000000000000..9189d9f80364
--- /dev/null
+++ b/compel/plugins/include/uapi/std/log.h
@@ -0,0 +1,14 @@
+#ifndef COMPEL_PLUGIN_STD_LOG_H__
+#define COMPEL_PLUGIN_STD_LOG_H__
+
+#define STD_LOG_SIMPLE_CHUNK	72
+
+extern void std_log_set_fd(int fd);
+extern void std_log_set_loglevel(unsigned int level);
+extern int std_vprint_num(char *buf, int blen, int num, char **ps);
+extern void std_sprintf(char output[STD_LOG_SIMPLE_CHUNK], const char *format, ...)
+	__attribute__ ((__format__ (__printf__, 2, 3)));
+extern void print_on_level(unsigned int loglevel, const char *format, ...)
+	__attribute__ ((__format__ (__printf__, 2, 3)));
+
+#endif /* COMPEL_PLUGIN_STD_LOG_H__ */
diff --git a/criu/include/log.h b/criu/include/log.h
index f4d04c030370..9c4c28386c40 100644
--- a/criu/include/log.h
+++ b/criu/include/log.h
@@ -72,15 +72,6 @@ extern void print_on_level(unsigned int loglevel, const char *format, ...)
 #define pr_perror(fmt, ...)						\
 	pr_err(fmt ": %s\n", ##__VA_ARGS__, strerror(errno))
 
-#else
-
-#define LOG_SIMPLE_CHUNK	72
-
-extern int vprint_num(char *buf, int blen, int num, char **ps);
-extern void simple_sprintf(char output[LOG_SIMPLE_CHUNK], const char *format, ...)
-	__attribute__ ((__format__ (__printf__, 2, 3)));
-
 #endif /* CR_NOGLIBC */
 
-
 #endif /* __CR_LOG_H__ */
diff --git a/criu/pie/infect.c b/criu/pie/infect.c
index 8ba3f897dd53..384ba7ffb9bc 100644
--- a/criu/pie/infect.c
+++ b/criu/pie/infect.c
@@ -3,6 +3,7 @@
 #include "int.h"
 #include "util-pie.h"
 
+#include <compel/plugins/std/log.h>
 #include "criu-log.h"
 #include "common/bug.h"
 #include "sigframe.h"
@@ -79,7 +80,7 @@ static int fini(void)
 		  new_sp, RT_SIGFRAME_REGIP(sigframe));
 
 	sys_close(tsock);
-	log_set_fd(-1);
+	std_log_set_fd(-1);
 
 	fini_sigreturn(new_sp);
 
@@ -168,8 +169,8 @@ static noinline __used int parasite_init_daemon(void *data)
 
 	ret = recv_fd(tsock);
 	if (ret >= 0) {
-		log_set_fd(ret);
-		log_set_loglevel(args->log_level);
+		std_log_set_fd(ret);
+		std_log_set_loglevel(args->log_level);
 		ret = 0;
 	} else
 		goto err;
diff --git a/criu/pie/log-simple.c b/criu/pie/log-simple.c
index 3a1361a74fe7..b60a82e8946e 100644
--- a/criu/pie/log-simple.c
+++ b/criu/pie/log-simple.c
@@ -1,13 +1,12 @@
 #include <stdarg.h>
 
-#include "int.h"
-#include "types.h"
 #include "common/bitsperlong.h"
 #include <compel/plugins/std/syscall.h>
-#include "log.h"
+#include <compel/plugins/std/log.h>
+#include <compel/loglevels.h>
 
 struct simple_buf {
-	char buf[LOG_SIMPLE_CHUNK];
+	char buf[STD_LOG_SIMPLE_CHUNK];
 	char *bp;
 	int prefix_len;
 	void (*flush)(struct simple_buf *b);
@@ -28,7 +27,7 @@ static void sbuf_log_init(struct simple_buf *b)
 	 *
 	 * pie: pid: string-itself
 	 */
-	b->prefix_len = vprint_num(pid_buf, sizeof(pid_buf), sys_gettid(), &s);
+	b->prefix_len = std_vprint_num(pid_buf, sizeof(pid_buf), sys_gettid(), &s);
 	b->buf[0] = 'p';
 	b->buf[1] = 'i';
 	b->buf[2] = 'e';
@@ -57,12 +56,12 @@ static void sbuf_log_flush(struct simple_buf *b)
 static void sbuf_putc(struct simple_buf *b, char c)
 {
 	/* TODO: maybe some warning or error here? */
-	if (b->bp - b->buf >= LOG_SIMPLE_CHUNK)
+	if (b->bp - b->buf >= STD_LOG_SIMPLE_CHUNK)
 		return;
 
 	*b->bp = c;
 	b->bp++;
-	if (b->bp - b->buf >= LOG_SIMPLE_CHUNK - 2) {
+	if (b->bp - b->buf >= STD_LOG_SIMPLE_CHUNK - 2) {
 		b->bp[0] = '>';
 		b->bp[1] = '\n';
 		b->bp += 2;
@@ -71,13 +70,13 @@ static void sbuf_putc(struct simple_buf *b, char c)
 	}
 }
 
-void log_set_fd(int fd)
+void std_log_set_fd(int fd)
 {
 	sys_close(logfd);
 	logfd = fd;
 }
 
-void log_set_loglevel(unsigned int level)
+void std_log_set_loglevel(unsigned int level)
 {
 	cur_loglevel = level;
 }
@@ -90,7 +89,7 @@ static void print_string(const char *msg, struct simple_buf *b)
 	}
 }
 
-int vprint_num(char *buf, int blen, int num, char **ps)
+int std_vprint_num(char *buf, int blen, int num, char **ps)
 {
 	int neg = 0;
 	char *s;
@@ -127,7 +126,7 @@ static void print_num(int num, struct simple_buf *b)
 	char buf[12], *s;
 
 	buf[11] = '\0';
-	vprint_num(buf, sizeof(buf) - 1, num, &s);
+	std_vprint_num(buf, sizeof(buf) - 1, num, &s);
 	print_string(s, b);
 }
 
@@ -293,7 +292,7 @@ void print_on_level(unsigned int loglevel, const char *format, ...)
 	sbuf_log_flush(&b);
 }
 
-void simple_sprintf(char output[LOG_SIMPLE_CHUNK], const char *format, ...)
+void std_sprintf(char output[STD_LOG_SIMPLE_CHUNK], const char *format, ...)
 {
 	va_list args;
 	struct simple_buf b;
diff --git a/criu/pie/restorer.c b/criu/pie/restorer.c
index 80c36f3f6d97..272276414d09 100644
--- a/criu/pie/restorer.c
+++ b/criu/pie/restorer.c
@@ -24,6 +24,7 @@
 #include "common/compiler.h"
 #include "string.h"
 #include <compel/plugins/std/syscall.h>
+#include <compel/plugins/std/log.h>
 #include <compel/ksigset.h>
 #include "signal.h"
 #include "config.h"
@@ -106,14 +107,14 @@ static void sigchld_handler(int signal, siginfo_t *siginfo, void *data)
 static int lsm_set_label(char *label, int procfd)
 {
 	int ret = -1, len, lsmfd;
-	char path[LOG_SIMPLE_CHUNK];
+	char path[STD_LOG_SIMPLE_CHUNK];
 
 	if (!label)
 		return 0;
 
 	pr_info("restoring lsm profile %s\n", label);
 
-	simple_sprintf(path, "self/task/%ld/attr/current", sys_gettid());
+	std_sprintf(path, "self/task/%ld/attr/current", sys_gettid());
 
 	lsmfd = sys_openat(procfd, path, O_WRONLY, 0);
 	if (lsmfd < 0) {
@@ -1143,8 +1144,8 @@ long __export_restore_task(struct task_restore_args *args)
 	ksigaddset(&to_block, SIGCHLD);
 	ret = sys_sigprocmask(SIG_UNBLOCK, &to_block, NULL, sizeof(k_rtsigset_t));
 
-	log_set_fd(args->logfd);
-	log_set_loglevel(args->loglevel);
+	std_log_set_fd(args->logfd);
+	std_log_set_loglevel(args->loglevel);
 
 	pr_info("Switched to the restorer %d\n", my_pid);
 
@@ -1424,7 +1425,7 @@ skip_vdso:
 				continue;
 
 			new_sp = restorer_stack(thread_args[i].mz);
-			last_pid_len = vprint_num(last_pid_buf, sizeof(last_pid_buf), thread_args[i].pid - 1, &s);
+			last_pid_len = std_vprint_num(last_pid_buf, sizeof(last_pid_buf), thread_args[i].pid - 1, &s);
 			sys_lseek(fd, 0, SEEK_SET);
 			ret = sys_write(fd, s, last_pid_len);
 			if (ret < 0) {
@@ -1544,7 +1545,7 @@ skip_vdso:
 	futex_wait_while_gt(&thread_inprogress, 1);
 
 	sys_close(args->proc_fd);
-	log_set_fd(-1);
+	std_log_set_fd(-1);
 
 	/*
 	 * The code that prepared the itimers makes shure the
-- 
2.7.4



More information about the CRIU mailing list