[CRIU] [PATCH 4/5] service: add support for session-mode
Ruslan Kuprieiev
kupruser at gmail.com
Tue Dec 3 08:20:38 PST 2013
Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
cr-service.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 67 insertions(+), 10 deletions(-)
diff --git a/cr-service.c b/cr-service.c
index 11d272e..ce9b7b5 100644
--- a/cr-service.c
+++ b/cr-service.c
@@ -233,17 +233,32 @@ static int check(int sk)
return send_criu_msg(sk, &resp);
}
-static int cr_service_work(int sk)
+static int set_session_using_req(int sk, CriuCtrl *ctrl, bool *session)
{
- CriuReq *msg = 0;
+ bool success = true;
+ CriuResp resp = CRIU_RESP__INIT;
- init_opts();
+ resp.type = CRIU_REQ_TYPE__CTRL;
- if (recv_criu_msg(sk, &msg) == -1) {
- pr_perror("Can't recv request");
- goto err;
+ *session = ctrl->session;
+
+ if (ctrl->session_log) {
+ opts.output = ctrl->session_log;
+
+ log_set_loglevel(4);
+ if (log_init(opts.output) == -1)
+ success = false;
}
+ resp.success = success;
+ if (send_criu_msg(sk, &resp) == -1)
+ success = false;
+
+ return success ? 0 : 1;
+}
+
+static int process_requests(int sk, CriuReq *msg)
+{
switch (msg->type) {
case CRIU_REQ_TYPE__DUMP:
return dump_using_req(sk, msg->opts);
@@ -262,12 +277,9 @@ static int cr_service_work(int sk)
pr_perror("Invalid request");
send_criu_msg(sk, &resp);
- goto err;
+ return -1;
}
}
-
-err:
- return -1;
}
static void reap_worker(int signo)
@@ -333,6 +345,51 @@ static int restore_sigchld_handler()
return 0;
}
+static int cr_service_work(int sk)
+{
+ CriuReq *msg = 0;
+ int ret;
+ bool session = false;
+
+ init_opts();
+
+ do {
+ ret = recv_criu_msg(sk, &msg);
+ if (ret <= 0)
+ break;
+
+ if (msg->type == CRIU_REQ_TYPE__CTRL) {
+ ret = set_session_using_req(sk, msg->ctrl, &session);
+ if (!ret)
+ continue;
+ else
+ break;
+ }
+
+ if (session) {
+ setup_sigchld_handler();
+
+ ret = fork();
+
+ if (ret > 0)
+ continue;
+
+ if (ret < 0)
+ break;
+
+ restore_sigchld_handler();
+ }
+
+ session = false;
+ ret = process_requests(sk, msg);
+
+ } while (session);
+
+ wait(0);
+ return ret;
+}
+
+
int cr_service(bool daemon_mode)
{
int server_fd = -1;
--
1.8.1.2
More information about the CRIU
mailing list