Commit 05943959 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

proc: parse state and ppid from /proc/pid/status (v2)

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: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 2cb6f2b6
...@@ -90,6 +90,9 @@ struct proc_status_creds { ...@@ -90,6 +90,9 @@ struct proc_status_creds {
u32 cap_prm[PROC_CAP_SIZE]; u32 cap_prm[PROC_CAP_SIZE];
u32 cap_eff[PROC_CAP_SIZE]; u32 cap_eff[PROC_CAP_SIZE];
u32 cap_bnd[PROC_CAP_SIZE]; u32 cap_bnd[PROC_CAP_SIZE];
char state;
int ppid;
}; };
struct mount_info; struct mount_info;
......
...@@ -745,7 +745,20 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr) ...@@ -745,7 +745,20 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
return -1; 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 (!strncmp(str, "Uid:", 4)) {
if (ids_parse(str + 5, cr->uids)) if (ids_parse(str + 5, cr->uids))
goto err_parse; goto err_parse;
...@@ -789,7 +802,7 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr) ...@@ -789,7 +802,7 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
} }
} }
if (done != 6) { if (done != 8) {
err_parse: err_parse:
pr_err("Error parsing proc status file\n"); pr_err("Error parsing proc status file\n");
fclose(f); fclose(f);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment