[CRIU] [PATCH 1/2] service: Factor out err setting

Pavel Emelyanov xemul at virtuozzo.com
Wed Aug 24 11:11:45 PDT 2016


Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/cr-service.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/criu/cr-service.c b/criu/cr-service.c
index fdd37d9..a2b4027 100644
--- a/criu/cr-service.c
+++ b/criu/cr-service.c
@@ -110,6 +110,17 @@ err:
 	return -1;
 }
 
+static void set_resp_err(CriuResp *resp)
+{
+	int errn;
+
+	errn = get_cr_errno();
+	if (errn) {
+		resp->has_cr_errno = true;
+		resp->cr_errno = errn;
+	}
+}
+
 static void send_criu_err(int sk, char *msg)
 {
 	CriuResp resp = CRIU_RESP__INIT;
@@ -118,10 +129,7 @@ static void send_criu_err(int sk, char *msg)
 
 	resp.type = CRIU_REQ_TYPE__EMPTY;
 	resp.success = false;
-	if (get_cr_errno()) {
-		resp.has_cr_errno = true;
-		resp.cr_errno = get_cr_errno();
-	}
+	set_resp_err(&resp);
 
 	send_criu_msg(sk, &resp);
 }
@@ -133,10 +141,7 @@ int send_criu_dump_resp(int socket_fd, bool success, bool restored)
 
 	msg.type = CRIU_REQ_TYPE__DUMP;
 	msg.success = success;
-	if (get_cr_errno()) {
-		msg.has_cr_errno = true;
-		msg.cr_errno = get_cr_errno();
-	}
+	set_resp_err(&msg);
 	msg.dump = &resp;
 
 	resp.has_restored = true;
@@ -151,10 +156,7 @@ static int send_criu_pre_dump_resp(int socket_fd, bool success)
 
 	msg.type = CRIU_REQ_TYPE__PRE_DUMP;
 	msg.success = success;
-	if (get_cr_errno()) {
-		msg.has_cr_errno = true;
-		msg.cr_errno = get_cr_errno();
-	}
+	set_resp_err(&msg);
 
 	return send_criu_msg(socket_fd, &msg);
 }
@@ -166,10 +168,7 @@ int send_criu_restore_resp(int socket_fd, bool success, int pid)
 
 	msg.type = CRIU_REQ_TYPE__RESTORE;
 	msg.success = success;
-	if (get_cr_errno()) {
-		msg.has_cr_errno = true;
-		msg.cr_errno = get_cr_errno();
-	}
+	set_resp_err(&msg);
 	msg.restore = &resp;
 
 	resp.pid = pid;
-- 
2.5.0



More information about the CRIU mailing list