[CRIU] [PATCH 06/17] proc: parse state and ppid from /proc/pid/status

Andrey Vagin avagin at openvz.org
Fri Oct 31 02:14:24 PDT 2014


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 include/proc_parse.h |  3 +++
 proc_parse.c         | 17 +++++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/include/proc_parse.h b/include/proc_parse.h
index ab02f33..a0424bb 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -90,6 +90,9 @@ struct proc_status_creds {
 	u32 cap_prm[PROC_CAP_SIZE];
 	u32 cap_eff[PROC_CAP_SIZE];
 	u32 cap_bnd[PROC_CAP_SIZE];
+
+	char			state;
+	int			ppid;
 };
 
 struct mount_info;
diff --git a/proc_parse.c b/proc_parse.c
index a53408c..f9f1a88 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -745,7 +745,20 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
 		return -1;
 	}
 
-	while (done < 6 && fgets(str, sizeof(str), f)) {
+	while (done < 8 && fgets(str, sizeof(str), f)) {
+		if (!strncmp(str, "State:", 6)) {
+			cr->state = str[7];
+			done++;
+		}
+
+		if (!strncmp(str, "PPid:", 5)) {
+			if (sscanf(str, "PPid:\t%d", &cr->ppid) != 1) {
+				pr_err("Unable to parse: %s", str);
+				return -1;
+			}
+			done++;
+		}
+
 		if (!strncmp(str, "Uid:", 4)) {
 			if (ids_parse(str + 5, cr->uids))
 				goto err_parse;
@@ -789,7 +802,7 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
 		}
 	}
 
-	if (done != 6) {
+	if (done != 8) {
 err_parse:
 		pr_err("Error parsing proc status file\n");
 		fclose(f);
-- 
1.9.3



More information about the CRIU mailing list