[CRIU] [PATCH 06/17] proc: parse state and ppid from /proc/pid/status (v2)
Andrey Vagin
avagin at openvz.org
Fri Oct 31 15:02:23 PDT 2014
v2: don't leak FILE
CID 73423 (#1 of 1): Resource leak (RESOURCE_LEAK)
15. leaked_storage: Variable f going out of scope leaks the storage it points to.
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..5ef7d7a 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);
+ goto err_parse;
+ }
+ 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