[CRIU] [PATCH 2/4] lib: Tossing bits around

Pavel Emelyanov xemul at parallels.com
Tue Jun 17 10:09:25 PDT 2014


This is to prepare a send-and-recv routine that works on existing socket.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 lib/criu.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/lib/criu.c b/lib/criu.c
index 1c98f2f..8d06ada 100644
--- a/lib/criu.c
+++ b/lib/criu.c
@@ -219,17 +219,9 @@ static int criu_connect(void)
 	return fd;
 }
 
-static int send_req_and_recv_resp(CriuReq *req, CriuResp **resp)
+static int send_req_and_recv_resp_sk(int fd, CriuReq *req, CriuResp **resp)
 {
-	int fd;
-	int ret	= 0;
-
-	fd = criu_connect();
-	if (fd < 0) {
-		perror("Can't connect to criu");
-		ret = ECONNREFUSED;
-		goto exit;
-	}
+	int ret = 0;
 
 	if (send_req(fd, req) < 0) {
 		ret = ECOMM;
@@ -254,10 +246,24 @@ static int send_req_and_recv_resp(CriuReq *req, CriuResp **resp)
 	}
 
 exit:
-	if (fd >= 0)
+	return -ret;
+}
+
+static int send_req_and_recv_resp(CriuReq *req, CriuResp **resp)
+{
+	int fd;
+	int ret	= 0;
+
+	fd = criu_connect();
+	if (fd < 0) {
+		perror("Can't connect to criu");
+		ret = ECONNREFUSED;
+	} else {
+		ret = send_req_and_recv_resp_sk(fd, req, resp);
 		close(fd);
+	}
 
-	return -ret;
+	return ret;
 }
 
 int criu_check(void)
-- 
1.8.4.2


More information about the CRIU mailing list