Commit be0f234f authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

proc: read all data from /proc/pid/task/tid/children (v2)

Currently we read only 4096 bytes (the size of buf).

v2: use the bfd engine
Signed-off-by: 's avatarAndrew Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 1d8fcb6b
...@@ -2139,47 +2139,50 @@ int parse_children(pid_t pid, pid_t **_c, int *_n) ...@@ -2139,47 +2139,50 @@ int parse_children(pid_t pid, pid_t **_c, int *_n)
int nr = 0; int nr = 0;
DIR *dir; DIR *dir;
struct dirent *de; struct dirent *de;
struct bfd f;
dir = opendir_proc(pid, "task"); dir = opendir_proc(pid, "task");
if (dir == NULL) if (dir == NULL)
return -1; return -1;
while ((de = readdir(dir))) { while ((de = readdir(dir))) {
int fd, len; char *pos, *end;
char *pos;
if (dir_dots(de)) if (dir_dots(de))
continue; continue;
fd = open_proc(pid, "task/%s/children", de->d_name); f.fd = open_proc(pid, "task/%s/children", de->d_name);
if (fd < 0) if (f.fd < 0)
goto err; goto err;
len = read(fd, buf, BUF_SIZE); if (bfdopenr(&f))
close(fd);
if (len < 0)
goto err; goto err;
buf[len] = '\0';
pos = buf;
while (1) { while (1) {
pid_t val, *tmp; pid_t val, *tmp;
val = strtol(pos, &pos, 0); pos = breadchr(&f, ' ');
if (!val) { if (IS_ERR(pos))
BUG_ON(*pos != '\0'); goto err_close;
if (pos == NULL)
break; break;
val = strtol(pos, &end, 0);
if (*end != 0 && *end != ' ') {
pr_err("Unable to parse %s\n", end);
goto err_close;
} }
tmp = xrealloc(ch, (nr + 1) * sizeof(pid_t)); tmp = xrealloc(ch, (nr + 1) * sizeof(pid_t));
if (!tmp) if (!tmp)
goto err; goto err_close;
ch = tmp; ch = tmp;
ch[nr] = val; ch[nr] = val;
nr++; nr++;
pos++; /* space goes after each pid */
} }
bclose(&f);
} }
*_c = ch; *_c = ch;
...@@ -2187,6 +2190,8 @@ int parse_children(pid_t pid, pid_t **_c, int *_n) ...@@ -2187,6 +2190,8 @@ int parse_children(pid_t pid, pid_t **_c, int *_n)
closedir(dir); closedir(dir);
return 0; return 0;
err_close:
bclose(&f);
err: err:
closedir(dir); closedir(dir);
xfree(ch); xfree(ch);
......
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