[CRIU] [PATCH] seize: don't use wait4() to check whether or not a task is traced

Andrey Vagin avagin at openvz.org
Wed Nov 25 22:16:08 PST 2015


From: Andrew Vagin <avagin at virtuozzo.com>

If a task is stopped, waitpid() will return its status, but
wait4() in seize_wait_task will hang forever, because a stopped
state is reported only once.

v2: don't like a file object

Reported-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
Cc: Andrey Ryabinin <aryabinin at virtuozzo.com>
Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 seize.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/seize.c b/seize.c
index 11b5ad8..7ef2048 100644
--- a/seize.c
+++ b/seize.c
@@ -102,14 +102,15 @@ static int seize_cgroup_tree(char *root_path, const char *state)
 
 		pid = atoi(path);
 
-		/*
-		 * Here we are going to skip tasks which are already traced.
-		 * Ptraced tasks looks like children for us, so if
-		 * a task isn't ptraced yet, waitpid() will return a error.
-		 */
-		ret = wait4(pid, NULL, __WALL | WNOHANG, NULL);
+		/* Here we are going to skip tasks which are already traced. */
+		ret = ptrace(PTRACE_INTERRUPT, pid, NULL, NULL);
 		if (ret == 0)
 			continue;
+		if (errno != ESRCH) {
+			pr_perror("Unexpected error");
+			fclose(f);
+			return -1;
+		}
 
 		if (seize_catch_task(pid) && state == frozen) {
 			char buf[] = "/proc/XXXXXXXXXX/exe";
-- 
2.4.3



More information about the CRIU mailing list