[CRIU] [PATCH 2/2] criu: print criu and kernel versions from log_init()

Andrei Vagin avagin at virtuozzo.com
Fri Apr 6 10:49:09 MSK 2018


log_init() opens a log file. We want to have criu and kernel versions in
each log file, so it looks reasonable to print them from log_init().

Without this patch, versions are not printed, if criu is called in the
swrk mode.

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/cr-service.c   |  2 --
 criu/crtools.c      |  2 --
 criu/include/util.h |  2 --
 criu/log.c          | 21 +++++++++++++++++++++
 criu/util.c         | 17 -----------------
 5 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/criu/cr-service.c b/criu/cr-service.c
index 30d537a01..274ff218b 100644
--- a/criu/cr-service.c
+++ b/criu/cr-service.c
@@ -307,8 +307,6 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
 		goto err;
 	}
 
-	print_versions();
-
 	/* checking flags from client */
 	if (req->has_leave_running && req->leave_running)
 		opts.final_state = TASK_ALIVE;
diff --git a/criu/crtools.c b/criu/crtools.c
index 01da7c9b5..62adeec35 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -940,8 +940,6 @@ int main(int argc, char *argv[], char *envp[])
 	if (log_init(opts.output))
 		return 1;
 
-	print_versions();
-
 	if (opts.deprecated_ok)
 		pr_debug("DEPRECATED ON\n");
 
diff --git a/criu/include/util.h b/criu/include/util.h
index 377ef20f3..8a1718c1e 100644
--- a/criu/include/util.h
+++ b/criu/include/util.h
@@ -380,6 +380,4 @@ static inline void print_stack_trace(pid_t pid) {}
 		___ret;									\
 	})
 
-extern void print_versions(void);
-
 #endif /* __CR_UTIL_H__ */
diff --git a/criu/log.c b/criu/log.c
index 22c6f2950..6a13266eb 100644
--- a/criu/log.c
+++ b/criu/log.c
@@ -9,6 +9,7 @@
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/resource.h>
+#include <sys/utsname.h>
 
 #include <fcntl.h>
 
@@ -20,6 +21,8 @@
 #include "rst-malloc.h"
 #include "common/lock.h"
 #include "string.h"
+#include "version.h"
+
 #include "../soccr/soccr.h"
 #include "compel/log.h"
 
@@ -135,6 +138,22 @@ char *log_first_err(void)
 	return first_err->s;
 }
 
+static void print_versions(void)
+{
+	struct utsname buf;
+
+	pr_info("Version: %s (gitid %s)\n", CRIU_VERSION, CRIU_GITID);
+
+	if (uname(&buf) < 0) {
+		pr_perror("Reading kernel version failed!");
+		/* This pretty unlikely, just keep on running. */
+		return;
+	}
+
+	pr_info("Running on %s %s %s %s %s\n", buf.nodename, buf.sysname,
+		buf.release, buf.version, buf.machine);
+}
+
 int log_init(const char *output)
 {
 	int new_logfd, fd;
@@ -167,6 +186,8 @@ int log_init(const char *output)
 	if (fd < 0)
 		goto err;
 
+	print_versions();
+
 	return 0;
 
 err:
diff --git a/criu/util.c b/criu/util.c
index 1605e1162..bc3d350bf 100644
--- a/criu/util.c
+++ b/criu/util.c
@@ -34,7 +34,6 @@
 #include <netinet/tcp.h>
 #include <sched.h>
 #include <ctype.h>
-#include <sys/utsname.h>
 
 #include "bitops.h"
 #include "page.h"
@@ -1625,19 +1624,3 @@ pid_t fork()
 {
 	return sys_clone_unified(SIGCHLD, 0, NULL, NULL, 0);
 }
-
-void print_versions(void)
-{
-	struct utsname buf;
-
-	pr_info("Version: %s (gitid %s)\n", CRIU_VERSION, CRIU_GITID);
-
-	if (uname(&buf) < 0) {
-		pr_perror("Reading kernel version failed!");
-		/* This pretty unlikely, just keep on running. */
-		return;
-	}
-
-	pr_info("Running on %s %s %s %s %s\n", buf.nodename, buf.sysname,
-		buf.release, buf.version, buf.machine);
-}
-- 
2.14.3



More information about the CRIU mailing list