[CRIU] [PATCH 6/7] restore: Use vpid in log_init_by_pid() instead of getpid()

Kirill Tkhai ktkhai at virtuozzo.com
Wed Jun 28 18:54:42 MSK 2017


When task is in pid namespace, getpid() can't be used
to identify it. So, use vpid instead of that.

Also, move log_init_by_pid() above pid check.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/cr-restore.c       |    8 ++++----
 criu/include/criu-log.h |    2 +-
 criu/log.c              |    6 +++---
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 527606d9f..8d6b95c50 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1701,6 +1701,10 @@ static int restore_task_with_children(void *_arg)
 	if (ret)
 		goto err;
 
+	ret = log_init_by_pid(vpid(current));
+	if (ret < 0)
+		goto err;
+
 	pid = getpid();
 	if (last_level_pid(current->pid) != pid) {
 		pr_err("Pid %d do not match expected %d (task %d)\n",
@@ -1709,10 +1713,6 @@ static int restore_task_with_children(void *_arg)
 		goto err;
 	}
 
-	ret = log_init_by_pid();
-	if (ret < 0)
-		goto err;
-
 	if (!(ca->clone_flags & CLONE_FILES)) {
 		ret = close_old_fds();
 		if (ret)
diff --git a/criu/include/criu-log.h b/criu/include/criu-log.h
index 37bc1ad71..d51185da2 100644
--- a/criu/include/criu-log.h
+++ b/criu/include/criu-log.h
@@ -26,7 +26,7 @@ struct timeval;
 
 extern int log_init(const char *output);
 extern void log_fini(void);
-extern int log_init_by_pid(void);
+extern int log_init_by_pid(pid_t pid);
 extern void log_closedir(void);
 extern int log_keep_err(void);
 extern char *log_first_err(void);
diff --git a/criu/log.c b/criu/log.c
index a2beabdb0..100ddc796 100644
--- a/criu/log.c
+++ b/criu/log.c
@@ -171,7 +171,7 @@ int log_init(const char *output)
 	return -1;
 }
 
-int log_init_by_pid(void)
+int log_init_by_pid(pid_t pid)
 {
 	char path[PATH_MAX];
 
@@ -182,14 +182,14 @@ int log_init_by_pid(void)
 	reset_buf_off();
 
 	if (!opts.log_file_per_pid) {
-		buf_off += snprintf(buffer + buf_off, sizeof buffer - buf_off, "%6d: ", getpid());
+		buf_off += snprintf(buffer + buf_off, sizeof buffer - buf_off, "%6d: ", pid);
 		return 0;
 	}
 
 	if (!opts.output)
 		return 0;
 
-	snprintf(path, PATH_MAX, "%s.%d", opts.output, getpid());
+	snprintf(path, PATH_MAX, "%s.%d", opts.output, pid);
 
 	return log_init(path);
 }



More information about the CRIU mailing list