[CRIU] [PATCH 16/78] infect: Move seize_catch_task -> compel_stop_task

Cyrill Gorcunov gorcunov at openvz.org
Mon Nov 7 08:36:01 PST 2016


From: Pavel Emelyanov <xemul at virtuozzo.com>

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/cr-exec.c        |  3 ++-
 criu/include/infect.h |  1 +
 criu/include/ptrace.h |  1 -
 criu/infect.c         | 39 +++++++++++++++++++++++++++++++++++++++
 criu/ptrace.c         | 34 ----------------------------------
 criu/seize.c          |  9 +++++----
 6 files changed, 47 insertions(+), 40 deletions(-)

diff --git a/criu/cr-exec.c b/criu/cr-exec.c
index fc279f70d499..8901750dbe2b 100644
--- a/criu/cr-exec.c
+++ b/criu/cr-exec.c
@@ -9,6 +9,7 @@
 #include "log.h"
 #include "util.h"
 #include "kerndat.h"
+#include "infect.h"
 
 struct syscall_exec_desc {
 	char *name;
@@ -133,7 +134,7 @@ int cr_exec(int pid, char **opt)
 		goto out;
 	}
 
-	if (seize_catch_task(pid))
+	if (compel_stop_task(pid))
 		goto out;
 
 	/*
diff --git a/criu/include/infect.h b/criu/include/infect.h
index 1d2bdf532ecc..d148a78e3574 100644
--- a/criu/include/infect.h
+++ b/criu/include/infect.h
@@ -1,3 +1,4 @@
 #ifndef __COMPEL_INFECT_H__
 #define __COMPEL_INFECT_H__
+extern int compel_stop_task(int pid);
 #endif
diff --git a/criu/include/ptrace.h b/criu/include/ptrace.h
index 020b36eedfcf..29f27d5b517b 100644
--- a/criu/include/ptrace.h
+++ b/criu/include/ptrace.h
@@ -80,7 +80,6 @@ struct seize_task_status {
 	int			seccomp_mode;
 };
 
-extern int seize_catch_task(pid_t pid);
 extern int seize_wait_task(pid_t pid, pid_t ppid,
 		int (*get_status)(int pid, struct seize_task_status *),
 		struct seize_task_status *st);
diff --git a/criu/infect.c b/criu/infect.c
index ac3897c3ed94..0a625b4d1932 100644
--- a/criu/infect.c
+++ b/criu/infect.c
@@ -1 +1,40 @@
+#include <sys/ptrace.h>
+#include <errno.h>
+
+#include "log.h"
 #include "infect.h"
+
+int compel_stop_task(int pid)
+{
+	int ret;
+
+	ret = ptrace(PTRACE_SEIZE, pid, NULL, 0);
+	if (ret) {
+		/*
+		 * ptrace API doesn't allow to distinguish
+		 * attaching to zombie from other errors.
+		 * All errors will be handled in seize_wait_task().
+		 */
+		pr_warn("Unable to interrupt task: %d (%s)\n", pid, strerror(errno));
+		return ret;
+	}
+
+	/*
+	 * If we SEIZE-d the task stop it before going
+	 * and reading its stat from proc. Otherwise task
+	 * may die _while_ we're doing it and we'll have
+	 * inconsistent seize/state pair.
+	 *
+	 * If task dies after we seize it but before we
+	 * do this interrupt, we'll notice it via proc.
+	 */
+	ret = ptrace(PTRACE_INTERRUPT, pid, NULL, NULL);
+	if (ret < 0) {
+		pr_warn("SEIZE %d: can't interrupt task: %s", pid, strerror(errno));
+		if (ptrace(PTRACE_DETACH, pid, NULL, NULL))
+			pr_perror("Unable to detach from %d", pid);
+	}
+
+	return ret;
+}
+
diff --git a/criu/ptrace.c b/criu/ptrace.c
index 0d96eea50ad5..2bbf67ade74d 100644
--- a/criu/ptrace.c
+++ b/criu/ptrace.c
@@ -68,40 +68,6 @@ int suspend_seccomp(pid_t pid)
 	return 0;
 }
 
-int seize_catch_task(pid_t pid)
-{
-	int ret;
-
-	ret = ptrace(PTRACE_SEIZE, pid, NULL, 0);
-	if (ret) {
-		/*
-		 * ptrace API doesn't allow to distinguish
-		 * attaching to zombie from other errors.
-		 * All errors will be handled in seize_wait_task().
-		 */
-		pr_warn("Unable to interrupt task: %d (%s)\n", pid, strerror(errno));
-		return ret;
-	}
-
-	/*
-	 * If we SEIZE-d the task stop it before going
-	 * and reading its stat from proc. Otherwise task
-	 * may die _while_ we're doing it and we'll have
-	 * inconsistent seize/state pair.
-	 *
-	 * If task dies after we seize it but before we
-	 * do this interrupt, we'll notice it via proc.
-	 */
-	ret = ptrace(PTRACE_INTERRUPT, pid, NULL, NULL);
-	if (ret < 0) {
-		pr_warn("SEIZE %d: can't interrupt task: %s", pid, strerror(errno));
-		if (ptrace(PTRACE_DETACH, pid, NULL, NULL))
-			pr_perror("Unable to detach from %d", pid);
-	}
-
-	return ret;
-}
-
 static int skip_sigstop(int pid, int nr_signals)
 {
 	int i, status, ret;
diff --git a/criu/seize.c b/criu/seize.c
index a2de761822ec..8afcae7bdaa1 100644
--- a/criu/seize.c
+++ b/criu/seize.c
@@ -20,6 +20,7 @@
 #include "stats.h"
 #include "xmalloc.h"
 #include "util.h"
+#include "infect.h"
 
 #define NR_ATTEMPTS 5
 
@@ -128,7 +129,7 @@ static int seize_cgroup_tree(char *root_path, const char *state)
 			return -1;
 		}
 
-		if (!seize_catch_task(pid)) {
+		if (!compel_stop_task(pid)) {
 			pr_debug("SEIZE %d: success\n", pid);
 			processes_to_wait++;
 		} else if (state == frozen) {
@@ -480,7 +481,7 @@ static int collect_children(struct pstree_item *item)
 
 		if (!opts.freeze_cgroup)
 			/* fails when meets a zombie */
-			seize_catch_task(pid);
+			compel_stop_task(pid);
 
 		creds = xzalloc(sizeof(*creds));
 		if (!creds) {
@@ -710,7 +711,7 @@ static int collect_threads(struct pstree_item *item)
 		pr_info("\tSeizing %d's %d thread\n",
 				item->pid.real, pid);
 
-		if (!opts.freeze_cgroup && seize_catch_task(pid))
+		if (!opts.freeze_cgroup && compel_stop_task(pid))
 			continue;
 
 		ret = seize_wait_task(pid, item_ppid(item), parse_pid_status, &t_creds.s);
@@ -842,7 +843,7 @@ int collect_pstree(void)
 	if (opts.freeze_cgroup && freeze_processes())
 		goto err;
 
-	if (!opts.freeze_cgroup && seize_catch_task(pid)) {
+	if (!opts.freeze_cgroup && compel_stop_task(pid)) {
 		set_cr_errno(ESRCH);
 		goto err;
 	}
-- 
2.7.4



More information about the CRIU mailing list