[CRIU] [PATCH]v2 rpc: change some "required" fields to "optional"

Ruslan Kuprieiev kupruser at gmail.com
Sun Sep 15 16:52:29 EDT 2013


The most of fields are to be changed to "optional", because they are
optional in fact.

Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
-------------- next part --------------
diff --git a/cr-service.c b/cr-service.c
index 79ba032..b1f4bdf 100644
--- a/cr-service.c
+++ b/cr-service.c
@@ -86,9 +86,6 @@ static int setup_dump_from_req(CriuDumpReq *req)
 	cr_service_client->pid = ids.pid;
 	cr_service_client->uid = ids.uid;
 
-	if (req->pid == 0)
-		req->pid = ids.pid;
-
 	if (fstat(cr_service_client->sk_fd, &st)) {
 		pr_perror("Can't get socket stat");
 		return -1;
@@ -120,14 +117,28 @@ static int setup_dump_from_req(CriuDumpReq *req)
 	}
 
 	/* checking dump flags from client */
-	if (req->leave_running)
+	if (req->has_leave_running && req->leave_running)
 		opts.final_state = TASK_ALIVE;
 
-	opts.ext_unix_sk	= req->ext_unix_sk;
-	opts.tcp_established_ok	= req->tcp_established;
-	opts.evasive_devices	= req->evasive_devices;
-	opts.shell_job		= req->shell_job;
-	opts.handle_file_locks	= req->file_locks;
+	if (!req->has_pid) {
+		req->has_pid = true;
+		req->pid = ids.pid;
+	}
+
+	if (req->has_ext_unix_sk)
+		opts.ext_unix_sk = req->ext_unix_sk;
+
+	if (req->has_tcp_established)
+		opts.tcp_established_ok = req->tcp_established;
+
+	if (req->has_evasive_devices)
+		opts.evasive_devices = req->evasive_devices;
+
+	if (req->has_shell_job)
+		opts.shell_job = req->shell_job;
+
+	if (req->has_file_locks)
+		opts.handle_file_locks = req->file_locks;
 
 	return 0;
 }
@@ -149,7 +160,7 @@ static int dump_using_req(CriuDumpReq *req)
 	resp.success = true;
 
 exit:
-	if (req->leave_running) {
+	if (req->has_leave_running && req->leave_running) {
 		if (send_criu_dump_resp(cr_service_client->sk_fd,
 							&resp) == -1) {
 			pr_perror("Can't send response");
diff --git a/protobuf/rpc.proto b/protobuf/rpc.proto
index 864e008..66966a3 100644
--- a/protobuf/rpc.proto
+++ b/protobuf/rpc.proto
@@ -1,18 +1,18 @@
 message criu_dump_req {
-	required int32 pid		= 1; //if not set, will dump requesting process
-	required bool leave_running	= 2;
-	required bool ext_unix_sk	= 3;
-	required bool tcp_established	= 4;
-	required bool evasive_devices	= 5;
-	required bool shell_job		= 6;
-	required bool file_locks	= 7;
+	optional int32 pid		= 1; //if not set, will dump requesting process
+	optional bool leave_running	= 2;
+	optional bool ext_unix_sk	= 3;
+	optional bool tcp_established	= 4;
+	optional bool evasive_devices	= 5;
+	optional bool shell_job		= 6;
+	optional bool file_locks	= 7;
 	required int32 images_dir_fd	= 8;
-	required int32 log_level	= 9 [default = 2];
+	optional int32 log_level	= 9 [default = 2];
 }
 
 message criu_dump_resp {
 	required bool success		= 1;
-	required bool restored		= 2;
+	optional bool restored		= 2;
 }
 
 message criu_msg {
diff --git a/sk-unix.c b/sk-unix.c
index 268e574..2213417 100644
--- a/sk-unix.c
+++ b/sk-unix.c
@@ -753,8 +753,9 @@ static int open_unixsk_standalone(struct unix_sk_info *ui)
 		int sks[2];
 		CriuDumpResp resp = CRIU_DUMP_RESP__INIT;
 
-		resp.success = true;
-		resp.restored = true;
+		resp.success		= true;
+		resp.has_restored	= true;
+		resp.restored		= true;
 
 		if (socketpair(PF_UNIX, ui->ue->type, 0, sks)) {
 			pr_perror("Can't create socketpair");


More information about the CRIU mailing list