[CRIU] [PATCH 07/15] parse_proc: move parse_threads from cr-dump.c

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


It will be used in cr-restore.c for stopping threads on the exit from
sigreturn.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-dump.c            | 41 ++---------------------------------------
 include/proc_parse.h |  3 +++
 proc_parse.c         | 37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 39 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index ba7a7cc..247cc26 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -675,46 +675,9 @@ err:
 	return ret;
 }
 
-static int parse_threads(const struct pstree_item *item, struct pid **_t, int *_n)
-{
-	struct dirent *de;
-	DIR *dir;
-	struct pid *t = NULL;
-	int nr = 1;
-
-	dir = opendir_proc(item->pid.real, "task");
-	if (!dir)
-		return -1;
-
-	while ((de = readdir(dir))) {
-		struct pid *tmp;
-
-		/* We expect numbers only here */
-		if (de->d_name[0] == '.')
-			continue;
-
-		tmp = xrealloc(t, nr * sizeof(struct pid));
-		if (!tmp) {
-			xfree(t);
-			return -1;
-		}
-		t = tmp;
-		t[nr - 1].real = atoi(de->d_name);
-		t[nr - 1].virt = -1;
-		nr++;
-	}
-
-	closedir(dir);
-
-	*_t = t;
-	*_n = nr - 1;
-
-	return 0;
-}
-
 static int get_threads(struct pstree_item *item)
 {
-	return parse_threads(item, &item->threads, &item->nr_threads);
+	return parse_threads(item->pid.real, &item->threads, &item->nr_threads);
 }
 
 static int check_threads(const struct pstree_item *item)
@@ -722,7 +685,7 @@ static int check_threads(const struct pstree_item *item)
 	struct pid *t;
 	int nr, ret;
 
-	ret = parse_threads(item, &t, &nr);
+	ret = parse_threads(item->pid.real, &t, &nr);
 	if (ret)
 		return ret;
 
diff --git a/include/proc_parse.h b/include/proc_parse.h
index a1245cb..71bf00b 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -164,4 +164,7 @@ extern int parse_file_locks(void);
 
 extern int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat * args);
 
+struct pid;
+extern int parse_threads(int pid, struct pid **_t, int *_n);
+
 #endif /* __CR_PROC_PARSE_H__ */
diff --git a/proc_parse.c b/proc_parse.c
index 3409a85..dd56ed1 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -1238,3 +1238,40 @@ out:
 	fclose(file);
 	return ret;
 }
+
+int parse_threads(int pid, struct pid **_t, int *_n)
+{
+	struct dirent *de;
+	DIR *dir;
+	struct pid *t = NULL;
+	int nr = 1;
+
+	dir = opendir_proc(pid, "task");
+	if (!dir)
+		return -1;
+
+	while ((de = readdir(dir))) {
+		struct pid *tmp;
+
+		/* We expect numbers only here */
+		if (de->d_name[0] == '.')
+			continue;
+
+		tmp = xrealloc(t, nr * sizeof(struct pid));
+		if (!tmp) {
+			xfree(t);
+			return -1;
+		}
+		t = tmp;
+		t[nr - 1].real = atoi(de->d_name);
+		t[nr - 1].virt = -1;
+		nr++;
+	}
+
+	closedir(dir);
+
+	*_t = t;
+	*_n = nr - 1;
+
+	return 0;
+}
-- 
1.8.3.1



More information about the CRIU mailing list