Commit d30521a3 authored by Pavel Emelyanov's avatar Pavel Emelyanov

crtools: Add internal "swrk" action

To help restoring tasks from images as kids to the caller, we can
do the trick.

1. Caller sets himself as child reaper with PR_SET_CHILD_SUBREAPER prctl
2. Caller makes sure criu binary is suid-ed and owned by root
3. Caller forks and calls execv() on criu asking it to restore
4. Criu finishes restore and exits. All its kids get reparented to the
   criu's parent, i.e. -- to the library caller.
5. Caller stops being subreaper

In order to make the execv() and arguments passing simpler I propose
to execv() the service worker function, that accepts options via socket.

This is good for two reasons.

1. We don't have to construct CLI options in libcriu
2. We reuse other service's facilities, such as security checks,
   ability to dump, pre-dump and other stuff
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 8f05162b
...@@ -493,12 +493,10 @@ out: ...@@ -493,12 +493,10 @@ out:
return send_criu_msg(sk, &resp); return send_criu_msg(sk, &resp);
} }
static int cr_service_work(int sk) int cr_service_work(int sk)
{ {
CriuReq *msg = 0; CriuReq *msg = 0;
init_opts();
if (recv_criu_msg(sk, &msg) == -1) { if (recv_criu_msg(sk, &msg) == -1) {
pr_perror("Can't recv request"); pr_perror("Can't recv request");
goto err; goto err;
...@@ -684,6 +682,7 @@ int cr_service(bool daemon_mode) ...@@ -684,6 +682,7 @@ int cr_service(bool daemon_mode)
exit(1); exit(1);
close(server_fd); close(server_fd);
init_opts();
ret = cr_service_work(sk); ret = cr_service_work(sk);
close(sk); close(sk);
exit(ret != 0); exit(ret != 0);
......
...@@ -183,6 +183,15 @@ int main(int argc, char *argv[]) ...@@ -183,6 +183,15 @@ int main(int argc, char *argv[])
if (init_service_fd()) if (init_service_fd())
return 1; return 1;
if (!strcmp(argv[1], "swrk"))
/*
* This is to start criu service worker from libcriu calls.
* The usage is "criu swrk <fd>" and is not for CLI/scripts.
* The arguments semantics can change at any tyme with the
* corresponding lib call change.
*/
return cr_service_work(atoi(argv[2]));
while (1) { while (1) {
idx = -1; idx = -1;
opt = getopt_long(argc, argv, short_opts, long_opts, &idx); opt = getopt_long(argc, argv, short_opts, long_opts, &idx);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "protobuf/rpc.pb-c.h" #include "protobuf/rpc.pb-c.h"
extern int cr_service(bool deamon_mode); extern int cr_service(bool deamon_mode);
int cr_service_work(int sk);
extern int send_criu_dump_resp(int socket_fd, bool success, bool restored); extern int send_criu_dump_resp(int socket_fd, bool success, bool restored);
extern int send_criu_rpc_script(char *name, int arg); extern int send_criu_rpc_script(char *name, int arg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment