[CRIU] [PATCHv2 1/5] service: move worker's code in a separate function
Ruslan Kuprieiev
kupruser at gmail.com
Fri Sep 20 18:19:06 EDT 2013
On 09/19/2013 02:37 PM, Andrey Vagin wrote:
> I think it's more readable
>
> Cc: Ruslan Kuprieiev<kupruser at gmail.com>
> Signed-off-by: Andrey Vagin<avagin at openvz.org>
Original-patch-by: Andrey Vagin <avagin at openvz.org>
Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
-------------- next part --------------
diff --git a/cr-service.c b/cr-service.c
index 99b3cfd..8e2fc1b 100644
--- a/cr-service.c
+++ b/cr-service.c
@@ -176,6 +176,34 @@ exit:
return success ? 0 : 1;
}
+static int cr_service_work(void)
+{
+ CriuReq *msg = 0;
+
+ if (recv_criu_msg(cr_service_client->sk_fd,
+ &msg) == -1) {
+ pr_perror("Can't recv request");
+ goto err;
+ }
+
+ switch (msg->type) {
+ case CRIU_REQ_TYPE__DUMP:
+ exit(dump_using_req(msg->dump));
+
+ default:
+ pr_perror("Invalid request");
+ goto err;
+ }
+
+err:
+ /*
+ * FIXME -- add generic error report
+ */
+
+ close(cr_service_client->sk_fd);
+ return -1;
+}
+
int cr_service(bool daemon_mode)
{
int server_fd;
@@ -187,8 +215,6 @@ int cr_service(bool daemon_mode)
socklen_t server_addr_len;
socklen_t client_addr_len;
- CriuReq *msg = 0;
-
cr_service_client = malloc(sizeof(struct _cr_service_client));
server_fd = socket(AF_LOCAL, SOCK_SEQPACKET, 0);
@@ -267,29 +293,7 @@ int cr_service(bool daemon_mode)
continue;
case 0:
- if (recv_criu_msg(cr_service_client->sk_fd,
- &msg) == -1) {
- pr_perror("Can't recv request");
- goto err;
- }
-
- switch (msg->type) {
- case CRIU_REQ_TYPE__DUMP:
- exit(dump_using_req(msg->dump));
-
- default:
- pr_perror("Invalid request");
- goto err;
- }
-
-err:
- /*
- * FIXME -- add generic error report
- */
-
- close(cr_service_client->sk_fd);
- exit(-1);
-
+ exit(cr_service_work());
default:
close(cr_service_client->sk_fd);
}
More information about the CRIU
mailing list