[CRIU] [PATCH v2 2/5] seize: Reorder struct proc_status_creds

Kirill Tkhai ktkhai at virtuozzo.com
Tue Apr 18 08:56:39 PDT 2017


Time goes, and new fields are being implemented
in /proc/[pid]/status file. Some of them may be
variable len, e.g. NSpid and friends.

Next patches will allow struct seize_task_status
be extensible to confirm the time challenges. So,
in this case simple comparation in creds_dumpable()
won't work, as we're interested in currently known
fields there.

The patch reorders struct proc_status_creds and
places proc_status_creds::s before uncompared fields.
This will allow to continue use memcpy() to compare
the data from beginning of struct proc_status_creds
to proc_status_creds::s::shdpnd.

v2: Remove not shared thread signals from comparation.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 compel/include/uapi/infect.h |    4 ++--
 criu/include/proc_parse.h    |    7 +++----
 criu/seize.c                 |    6 +++---
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/compel/include/uapi/infect.h b/compel/include/uapi/infect.h
index da0ca3a69..cb90958a9 100644
--- a/compel/include/uapi/infect.h
+++ b/compel/include/uapi/infect.h
@@ -18,9 +18,9 @@ extern int compel_interrupt_task(int pid);
 struct seize_task_status {
 	char			state;
 	int			ppid;
-	unsigned long long	sigpnd;
-	unsigned long long	shdpnd;
 	int			seccomp_mode;
+	unsigned long long	shdpnd;
+	unsigned long long	sigpnd;
 };
 
 extern int compel_wait_task(int pid, int ppid,
diff --git a/criu/include/proc_parse.h b/criu/include/proc_parse.h
index d67ac5e56..91f2adb51 100644
--- a/criu/include/proc_parse.h
+++ b/criu/include/proc_parse.h
@@ -73,17 +73,16 @@ 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];
 
 	u32			last_filter;
 
 	/*
-	 * Keep them at the end of structure
-	 * for fast comparison reason.
+	 * Keep them at the end of structure for fast comparison
+	 * reason (see creds_dumpable()); and place s before caps.
 	 */
+	struct seize_task_status s;
 	u32			cap_inh[PROC_CAP_SIZE];
 	u32			cap_prm[PROC_CAP_SIZE];
 	u32			cap_eff[PROC_CAP_SIZE];
diff --git a/criu/seize.c b/criu/seize.c
index eda4e8a27..d83bcddb8 100644
--- a/criu/seize.c
+++ b/criu/seize.c
@@ -629,7 +629,9 @@ static inline bool thread_collected(struct pstree_item *i, pid_t tid)
 static bool creds_dumpable(struct proc_status_creds *parent,
 				struct proc_status_creds *child)
 {
-	const size_t size = offsetof(struct proc_status_creds, cap_inh);
+	/* From beginning of struct to proc_status_creds::s::shdpnd */
+	const size_t size = ((unsigned long)&parent->s.shdpnd) -
+			    ((unsigned long)parent) + sizeof(parent->s.shdpnd);
 
 	/*
 	 * The comparison rules are the following
@@ -649,7 +651,6 @@ static bool creds_dumpable(struct proc_status_creds *parent,
 				 "  gids:               %d:%d %d:%d %d:%d %d:%d\n"
 				 "  state:              %d:%d"
 				 "  ppid:               %d:%d\n"
-				 "  sigpnd:             %llu:%llu\n"
 				 "  shdpnd:             %llu:%llu\n"
 				 "  seccomp_mode:       %d:%d\n"
 				 "  last_filter:        %u:%u\n",
@@ -663,7 +664,6 @@ static bool creds_dumpable(struct proc_status_creds *parent,
 				 parent->gids[3], child->gids[3],
 				 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);



More information about the CRIU mailing list