[CRIU] [PATCH] proc: read all data from /proc/pid/task/tid/children
Andrey Vagin
avagin at openvz.org
Mon Oct 26 06:49:06 PDT 2015
From: Andrew Vagin <avagin at openvz.org>
Currently we read only 4096 bytes (the size of buf).
Signed-off-by: Andrew Vagin <avagin at openvz.org>
---
proc_parse.c | 31 ++++++++++++++-----------------
1 file changed, 14 insertions(+), 17 deletions(-)
diff --git a/proc_parse.c b/proc_parse.c
index 75ca682..bd6f023 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -2145,40 +2145,37 @@ int parse_children(pid_t pid, pid_t **_c, int *_n)
return -1;
while ((de = readdir(dir))) {
- int fd, len;
- char *pos;
+ FILE *f;
if (dir_dots(de))
continue;
- fd = open_proc(pid, "task/%s/children", de->d_name);
- if (fd < 0)
+ f = fopen_proc(pid, "task/%s/children", de->d_name);
+ if (f == NULL)
goto err;
- len = read(fd, buf, BUF_SIZE);
- close(fd);
- if (len < 0)
- goto err;
-
- buf[len] = '\0';
- pos = buf;
while (1) {
pid_t val, *tmp;
- val = strtol(pos, &pos, 0);
- if (!val) {
- BUG_ON(*pos != '\0');
- break;
+ if (fscanf(f, "%u", &val) < 1) {
+ if (feof(f)) {
+ fclose(f);
+ break;
+ }
+ pr_perror("Unable to parse task/%s/children", de->d_name);
+ fclose(f);
+ goto err;
}
tmp = xrealloc(ch, (nr + 1) * sizeof(pid_t));
- if (!tmp)
+ if (!tmp) {
+ fclose(f);
goto err;
+ }
ch = tmp;
ch[nr] = val;
nr++;
- pos++; /* space goes after each pid */
}
}
--
2.4.3
More information about the CRIU
mailing list