Commit 88031bf8 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

proc_parse: Convert parse_pid_status to BFD engine

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 8f937e04
...@@ -665,7 +665,7 @@ static int ids_parse(char *str, unsigned int *arr) ...@@ -665,7 +665,7 @@ static int ids_parse(char *str, unsigned int *arr)
arr[1] = strtol(end + 1, &end, 10); arr[1] = strtol(end + 1, &end, 10);
arr[2] = strtol(end + 1, &end, 10); arr[2] = strtol(end + 1, &end, 10);
arr[3] = strtol(end + 1, &end, 10); arr[3] = strtol(end + 1, &end, 10);
if (*end != '\n') if (*end)
return -1; return -1;
else else
return 0; return 0;
...@@ -687,17 +687,22 @@ static int cap_parse(char *str, unsigned int *res) ...@@ -687,17 +687,22 @@ static int cap_parse(char *str, unsigned int *res)
int parse_pid_status(pid_t pid, struct proc_status_creds *cr) int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
{ {
struct bfd f;
int done = 0; int done = 0;
FILE *f; int ret = -1;
char str[64]; char *str;
f = fopen_proc(pid, "status"); f.fd = open_proc(pid, "status");
if (f == NULL) { if (f.fd < 0) {
pr_perror("Can't open proc status"); pr_perror("Can't open proc status");
return -1; return -1;
} }
while (done < 8 && fgets(str, sizeof(str), f)) { if (bfdopen(&f, O_RDONLY))
return -1;
while (done < 8 && (str = breadline(&f))) {
pr_debug("str: `%s'\n", str);
if (!strncmp(str, "State:", 6)) { if (!strncmp(str, "State:", 6)) {
cr->state = str[7]; cr->state = str[7];
done++; done++;
...@@ -754,15 +759,14 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr) ...@@ -754,15 +759,14 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
} }
} }
if (done != 8) { if (done == 8)
ret = 0;
err_parse: err_parse:
if (ret)
pr_err("Error parsing proc status file\n"); pr_err("Error parsing proc status file\n");
fclose(f); bclose(&f);
return -1; return ret;
}
fclose(f);
return 0;
} }
struct opt2flag { struct opt2flag {
......
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