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

Submitted by Andrei Vagin on Oct. 14, 2018, 4:44 p.m.

Details

Message ID 20181014164417.19300-3-avagin@gmail.com
State New
Series "Series without cover letter"
Headers show

Commit Message

Andrei Vagin Oct. 14, 2018, 4:44 p.m.
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@gmail.com>
---
 criu/cr-service.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/cr-service.c b/criu/cr-service.c
index 993837bb6..5a413fab2 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))
+			goto out;
+
+		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);