[CRIU] [PATCH 08/15] proc: allow parse_thread to use an existent buffer

Andrey Vagin avagin at openvz.org
Mon Sep 23 06:33:31 EDT 2013


parse_thread allocated a buffer for threads and then it initialized read
pid for each thread.

Now we want to use it on restore and in this moment we already have
a buffer with initialized virt pid-s, so we need to initialize read
pid-s only.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-dump.c    |  2 +-
 proc_parse.c | 24 ++++++++++++++++--------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 247cc26..ad9a5c8 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -682,7 +682,7 @@ static int get_threads(struct pstree_item *item)
 
 static int check_threads(const struct pstree_item *item)
 {
-	struct pid *t;
+	struct pid *t = NULL;
 	int nr, ret;
 
 	ret = parse_threads(item->pid.real, &t, &nr);
diff --git a/proc_parse.c b/proc_parse.c
index dd56ed1..1afa29c 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -1246,6 +1246,9 @@ int parse_threads(int pid, struct pid **_t, int *_n)
 	struct pid *t = NULL;
 	int nr = 1;
 
+	if (*_t)
+		t = *_t;
+
 	dir = opendir_proc(pid, "task");
 	if (!dir)
 		return -1;
@@ -1257,21 +1260,26 @@ int parse_threads(int pid, struct pid **_t, int *_n)
 		if (de->d_name[0] == '.')
 			continue;
 
-		tmp = xrealloc(t, nr * sizeof(struct pid));
-		if (!tmp) {
-			xfree(t);
-			return -1;
+		if (*_t == NULL) {
+			tmp = xrealloc(t, nr * sizeof(struct pid));
+			if (!tmp) {
+				xfree(t);
+				return -1;
+			}
+			t = tmp;
+			t[nr - 1].virt = -1;
 		}
-		t = tmp;
 		t[nr - 1].real = atoi(de->d_name);
-		t[nr - 1].virt = -1;
 		nr++;
 	}
 
 	closedir(dir);
 
-	*_t = t;
-	*_n = nr - 1;
+	if (*_t == NULL) {
+		*_t = t;
+		*_n = nr - 1;
+	} else
+		BUG_ON(nr - 1 != *_n);
 
 	return 0;
 }
-- 
1.8.3.1



More information about the CRIU mailing list