[CRIU] [PATCH 3/3 v2] service: call cr_check() from a child process

Andrei Vagin avagin at gmail.com
Mon Oct 15 07:34:28 MSK 2018


cr_check() initializes root_item and calls collect_pstree_ids. It was
not designed to be called directly from a service process.

Signed-off-by: Andrei Vagin <avagin at gmail.com>
---
v2: exit from a child process if setup_opts_from_req fails

 criu/cr-service.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/criu/cr-service.c b/criu/cr-service.c
index 22ed7b503..ed83fdf32 100644
--- a/criu/cr-service.c
+++ b/criu/cr-service.c
@@ -712,17 +712,36 @@ exit:
 	return success ? 0 : 1;
 }
 
-static int check(int sk)
+static int check(int sk, CriuOpts *req)
 {
+	int pid, status;
 	CriuResp resp = CRIU_RESP__INIT;
 
 	resp.type = CRIU_REQ_TYPE__CHECK;
 
-	setproctitle("check --rpc");
+	pid = fork();
+	if (pid < 0) {
+		pr_perror("Can't fork");
+		goto out;
+	}
+
+	if (pid == 0) {
+		setproctitle("check --rpc");
 
-	if (!cr_check())
-		resp.success = true;
+		if (setup_opts_from_req(sk, req))
+			exit(1);
+
+		exit(!!cr_check());
+	}
+	if (waitpid(pid, &status, 0) != pid) {
+		pr_perror("Unable to wait %d", pid);
+		goto out;
+	}
+	if (status)
+		goto out;
 
+	resp.success = true;
+out:
 	return send_criu_msg(sk, &resp);
 }
 
@@ -1122,7 +1141,7 @@ more:
 		ret = restore_using_req(sk, msg->opts);
 		break;
 	case CRIU_REQ_TYPE__CHECK:
-		ret = check(sk);
+		ret = check(sk, msg->opts);
 		break;
 	case CRIU_REQ_TYPE__PRE_DUMP:
 		ret = pre_dump_loop(sk, msg);
-- 
2.14.4



More information about the CRIU mailing list