[CRIU] [PATCH 03/78] seize: Split proc_status_creds into pieces

Cyrill Gorcunov gorcunov at openvz.org
Mon Nov 7 08:35:48 PST 2016


From: Pavel Emelyanov <xemul at virtuozzo.com>

There's a subset of this structure is required by seize_catch_task(),
which in turn will go to compel library. So prepare for that.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/cr-dump.c            |  8 ++++----
 criu/cr-exec.c            |  2 +-
 criu/include/proc_parse.h |  9 +++------
 criu/include/ptrace.h     | 11 ++++++++++-
 criu/proc_parse.c         | 14 +++++++-------
 criu/ptrace.c             | 14 +++++++-------
 criu/seccomp.c            |  2 +-
 criu/seize.c              | 12 ++++++------
 8 files changed, 39 insertions(+), 33 deletions(-)

diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index f0f74c3f44ec..af3d8917369d 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -724,12 +724,12 @@ static int dump_task_core_all(struct parasite_ctl *ctl,
 		goto err;
 
 	creds = dmpi(item)->pi_creds;
-	if (creds->seccomp_mode != SECCOMP_MODE_DISABLED) {
-		pr_info("got seccomp mode %d for %d\n", creds->seccomp_mode, item->pid.virt);
+	if (creds->s.seccomp_mode != SECCOMP_MODE_DISABLED) {
+		pr_info("got seccomp mode %d for %d\n", creds->s.seccomp_mode, item->pid.virt);
 		core->tc->has_seccomp_mode = true;
-		core->tc->seccomp_mode = creds->seccomp_mode;
+		core->tc->seccomp_mode = creds->s.seccomp_mode;
 
-		if (creds->seccomp_mode == SECCOMP_MODE_FILTER) {
+		if (creds->s.seccomp_mode == SECCOMP_MODE_FILTER) {
 			core->tc->has_seccomp_filter = true;
 			core->tc->seccomp_filter = creds->last_filter;
 		}
diff --git a/criu/cr-exec.c b/criu/cr-exec.c
index 0136d82de500..e2f2ed4ef662 100644
--- a/criu/cr-exec.c
+++ b/criu/cr-exec.c
@@ -2,7 +2,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include "crtools.h"
-#include "ptrace.h"
+#include "proc_parse.h"
 #include "pstree.h"
 #include "parasite-syscall.h"
 #include "vma.h"
diff --git a/criu/include/proc_parse.h b/criu/include/proc_parse.h
index d1eed10ea84d..ce444e5d9817 100644
--- a/criu/include/proc_parse.h
+++ b/criu/include/proc_parse.h
@@ -3,6 +3,7 @@
 
 #include <sys/types.h>
 
+#include "ptrace.h"
 #include "images/seccomp.pb-c.h"
 
 #define PROC_TASK_COMM_LEN	32
@@ -72,15 +73,11 @@ struct seccomp_info {
 #define PROC_CAP_SIZE	2
 
 struct proc_status_creds {
+	struct seize_task_status s;
+
 	unsigned int uids[4];
 	unsigned int gids[4];
 
-	char			state;
-	int			ppid;
-	unsigned long long	sigpnd;
-	unsigned long long	shdpnd;
-
-	int			seccomp_mode;
 	u32			last_filter;
 
 	/*
diff --git a/criu/include/ptrace.h b/criu/include/ptrace.h
index 72da972b36c5..924c16329061 100644
--- a/criu/include/ptrace.h
+++ b/criu/include/ptrace.h
@@ -5,7 +5,6 @@
 #include <sys/ptrace.h>
 
 #include "config.h"
-#include "proc_parse.h"
 
 /* some constants for ptrace */
 #ifndef PTRACE_SEIZE
@@ -73,6 +72,16 @@ struct ptrace_peeksiginfo_args {
 
 #define SI_EVENT(_si_code)	(((_si_code) & 0xFFFF) >> 8)
 
+struct seize_task_status {
+	char			state;
+	int			ppid;
+	unsigned long long	sigpnd;
+	unsigned long long	shdpnd;
+	int			seccomp_mode;
+};
+
+struct proc_status_creds;
+
 extern int seize_catch_task(pid_t pid);
 extern int seize_wait_task(pid_t pid, pid_t ppid, struct proc_status_creds *creds);
 extern int suspend_seccomp(pid_t pid);
diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index 0a0de7dbedb1..ceb6c3915ae6 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -993,8 +993,8 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
 		return -1;
 	}
 
-	cr->sigpnd = 0;
-	cr->shdpnd = 0;
+	cr->s.sigpnd = 0;
+	cr->s.shdpnd = 0;
 
 	if (bfdopenr(&f))
 		return -1;
@@ -1007,13 +1007,13 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
 			goto err_parse;
 
 		if (!strncmp(str, "State:", 6)) {
-			cr->state = str[7];
+			cr->s.state = str[7];
 			done++;
 			continue;
 		}
 
 		if (!strncmp(str, "PPid:", 5)) {
-			if (sscanf(str, "PPid:\t%d", &cr->ppid) != 1) {
+			if (sscanf(str, "PPid:\t%d", &cr->s.ppid) != 1) {
 				pr_err("Unable to parse: %s\n", str);
 				goto err_parse;
 			}
@@ -1070,7 +1070,7 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
 		}
 
 		if (!strncmp(str, "Seccomp:", 8)) {
-			if (sscanf(str + 9, "%d", &cr->seccomp_mode) != 1) {
+			if (sscanf(str + 9, "%d", &cr->s.seccomp_mode) != 1) {
 				goto err_parse;
 			}
 
@@ -1084,7 +1084,7 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
 
 			if (sscanf(str + 7, "%llx", &sigpnd) != 1)
 				goto err_parse;
-			cr->shdpnd |= sigpnd;
+			cr->s.shdpnd |= sigpnd;
 
 			done++;
 			continue;
@@ -1094,7 +1094,7 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
 
 			if (sscanf(str + 7, "%llx", &sigpnd) != 1)
 				goto err_parse;
-			cr->sigpnd |= sigpnd;
+			cr->s.sigpnd |= sigpnd;
 
 			done++;
 			continue;
diff --git a/criu/ptrace.c b/criu/ptrace.c
index 09f7cd9ead8a..4dd774c63944 100644
--- a/criu/ptrace.c
+++ b/criu/ptrace.c
@@ -180,12 +180,12 @@ try_again:
 		goto err;
 
 	if (ret < 0 || WIFEXITED(status) || WIFSIGNALED(status)) {
-		if (creds->state != 'Z') {
+		if (creds->s.state != 'Z') {
 			if (pid == getpid())
 				pr_err("The criu itself is within dumped tree.\n");
 			else
 				pr_err("Unseizable non-zombie %d found, state %c, err %d/%d\n",
-						pid, creds->state, ret, wait_errno);
+						pid, creds->s.state, ret, wait_errno);
 			return -1;
 		}
 
@@ -195,9 +195,9 @@ try_again:
 			return TASK_DEAD;
 	}
 
-	if ((ppid != -1) && (creds->ppid != ppid)) {
+	if ((ppid != -1) && (creds->s.ppid != ppid)) {
 		pr_err("Task pid reused while suspending (%d: %d -> %d)\n",
-				pid, ppid, creds->ppid);
+				pid, ppid, creds->s.ppid);
 		goto err;
 	}
 
@@ -229,13 +229,13 @@ try_again:
 		goto try_again;
 	}
 
-	if (creds->seccomp_mode != SECCOMP_MODE_DISABLED && suspend_seccomp(pid) < 0)
+	if (creds->s.seccomp_mode != SECCOMP_MODE_DISABLED && suspend_seccomp(pid) < 0)
 		goto err;
 
 	nr_sigstop = 0;
-	if (creds->sigpnd & (1 << (SIGSTOP - 1)))
+	if (creds->s.sigpnd & (1 << (SIGSTOP - 1)))
 		nr_sigstop++;
-	if (creds->shdpnd & (1 << (SIGSTOP - 1)))
+	if (creds->s.shdpnd & (1 << (SIGSTOP - 1)))
 		nr_sigstop++;
 	if (si.si_signo == SIGSTOP)
 		nr_sigstop++;
diff --git a/criu/seccomp.c b/criu/seccomp.c
index 185823370a73..c569e7c1a036 100644
--- a/criu/seccomp.c
+++ b/criu/seccomp.c
@@ -50,7 +50,7 @@ static int collect_filter_for_pstree(struct pstree_item *item)
 	void *m;
 
 	if (item->pid.state == TASK_DEAD ||
-	    dmpi(item)->pi_creds->seccomp_mode != SECCOMP_MODE_FILTER)
+	    dmpi(item)->pi_creds->s.seccomp_mode != SECCOMP_MODE_FILTER)
 		return 0;
 
 	for (i = 0; true; i++) {
diff --git a/criu/seize.c b/criu/seize.c
index 5a6cef4d52fe..251be7921234 100644
--- a/criu/seize.c
+++ b/criu/seize.c
@@ -15,7 +15,7 @@
 #include "cr-errno.h"
 #include "pstree.h"
 #include "criu-log.h"
-#include "ptrace.h"
+#include "proc_parse.h"
 #include "seize.h"
 #include "stats.h"
 #include "xmalloc.h"
@@ -660,11 +660,11 @@ static bool creds_dumpable(struct proc_status_creds *parent,
 				 parent->gids[1], child->gids[1],
 				 parent->gids[2], child->gids[2],
 				 parent->gids[3], child->gids[3],
-				 parent->state, child->state,
-				 parent->ppid, child->ppid,
-				 parent->sigpnd, child->sigpnd,
-				 parent->shdpnd, child->shdpnd,
-				 parent->seccomp_mode, child->seccomp_mode,
+				 parent->s.state, child->s.state,
+				 parent->s.ppid, child->s.ppid,
+				 parent->s.sigpnd, child->s.sigpnd,
+				 parent->s.shdpnd, child->s.shdpnd,
+				 parent->s.seccomp_mode, child->s.seccomp_mode,
 				 parent->last_filter, child->last_filter);
 		}
 		return false;
-- 
2.7.4



More information about the CRIU mailing list