Commit 1ebd56b0 authored by Pavel Emelyanov's avatar Pavel Emelyanov

proc: Don't use FILE * to reach children

The same reasoning as for personality file -- switch to
plan open + read + close.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent f3bee6d5
...@@ -749,10 +749,8 @@ err: ...@@ -749,10 +749,8 @@ err:
static int parse_children(pid_t pid, pid_t **_c, int *_n) static int parse_children(pid_t pid, pid_t **_c, int *_n)
{ {
FILE *file;
char *tok;
pid_t *ch = NULL; pid_t *ch = NULL;
int nr = 1; int nr = 0;
DIR *dir; DIR *dir;
struct dirent *de; struct dirent *de;
...@@ -761,33 +759,45 @@ static int parse_children(pid_t pid, pid_t **_c, int *_n) ...@@ -761,33 +759,45 @@ static int parse_children(pid_t pid, pid_t **_c, int *_n)
return -1; return -1;
while ((de = readdir(dir))) { while ((de = readdir(dir))) {
int fd, len;
char *pos;
if (dir_dots(de)) if (dir_dots(de))
continue; continue;
file = fopen_proc(pid, "task/%s/children", de->d_name); fd = open_proc(pid, "task/%s/children", de->d_name);
if (!file) if (fd < 0)
goto err; goto err;
if (!(fgets(loc_buf, sizeof(loc_buf), file))) len = read(fd, loc_buf, sizeof(loc_buf));
loc_buf[0] = 0; close(fd);
if (len < 0)
goto err;
fclose(file); loc_buf[len] = '\0';
pos = loc_buf;
while (1) {
pid_t val, *tmp;
tok = strtok(loc_buf, " \n"); val = strtol(pos, &pos, 0);
while (tok) { if (!val) {
pid_t *tmp = xrealloc(ch, nr * sizeof(pid_t)); BUG_ON(*pos != '\0');
break;
}
tmp = xrealloc(ch, (nr + 1) * sizeof(pid_t));
if (!tmp) if (!tmp)
goto err; goto err;
ch = tmp; ch = tmp;
ch[nr - 1] = atoi(tok); ch[nr] = val;
nr++; nr++;
tok = strtok(NULL, " \n"); pos++; /* space goes after each pid */
} }
} }
*_c = ch; *_c = ch;
*_n = nr - 1; *_n = nr;
closedir(dir); closedir(dir);
return 0; return 0;
......
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