Commit 7952c6a7 authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Andrei Vagin

cr-restore: Open transport socket earlier

I need named socket to communicate with pid_ns helpers
(see next patches) and receive answer from them
(it's impossible to send answer to unnamed socket).
As we already have transport socket, we'll reuse it
for the above goal too.

This patch makes transport sockets be created before
creation of children tasks. Also, now they are created
not only for alive tasks (so we need additional
manipulations for TASK_HELPERS, e.g., to call prepare_fdt()).

v5: Return CLONE_FILES clone() argument during task helpers
creation. Also get rid of fdt_mutex as CLONE_FILES processes
does not close old files after clone, and we don't have
intertersections between them. Also, socket() system call
can't return a fd in service fds range, which was the main
reason to have this mutex.
Signed-off-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 72e50065
......@@ -1064,6 +1064,9 @@ static int restore_one_helper(void)
{
siginfo_t info;
if (prepare_fds(current))
return -1;
if (!child_death_expected()) {
/*
* Restoree has no children that should die, during restore,
......@@ -1108,7 +1111,7 @@ static int restore_one_helper(void)
static int restore_one_task(int pid, CoreEntry *core)
{
int ret;
int i, ret;
/* No more fork()-s => no more per-pid logs */
......@@ -1118,6 +1121,10 @@ static int restore_one_task(int pid, CoreEntry *core)
ret = restore_one_zombie(core);
else if (current->pid->state == TASK_HELPER) {
ret = restore_one_helper();
close_image_dir();
close_proc();
for (i = SERVICE_FD_MIN + 1; i < SERVICE_FD_MAX; i++)
close_service_fd(i);
} else {
pr_err("Unknown state in code %d\n", (int)core->tc->task_state);
ret = -1;
......@@ -1541,11 +1548,9 @@ static int restore_task_with_children(void *_arg)
if ( !(ca->clone_flags & CLONE_FILES))
close_safe(&ca->fd);
if (current->pid->state != TASK_HELPER) {
ret = clone_service_fd(rsti(current)->service_fd_id);
if (ret)
goto err;
}
ret = clone_service_fd(rsti(current)->service_fd_id);
if (ret)
goto err;
pid = getpid();
if (vpid(current) != pid) {
......@@ -1641,6 +1646,9 @@ static int restore_task_with_children(void *_arg)
kill(getpid(), SIGKILL);
}
if (open_transport_socket())
goto err;
timing_start(TIME_FORK);
if (create_children_and_session())
......@@ -1653,9 +1661,6 @@ static int restore_task_with_children(void *_arg)
restore_pgid();
if (open_transport_socket())
return -1;
if (current->parent == NULL) {
/*
* Wait when all tasks passed the CR_STATE_FORKING stage.
......
......@@ -1739,34 +1739,31 @@ int inherit_fd_fini()
int open_transport_socket(void)
{
struct fdt *fdt = rsti(current)->fdt;
pid_t pid = vpid(current);
struct sockaddr_un saddr;
int sock, slen;
if (!task_alive(current) || (fdt && fdt->pid != pid))
return 0;
int sock, slen, ret = -1;
sock = socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (sock < 0) {
pr_perror("Can't create socket");
return -1;
goto out;
}
transport_name_gen(&saddr, &slen, pid);
if (bind(sock, (struct sockaddr *)&saddr, slen) < 0) {
pr_perror("Can't bind transport socket %s", saddr.sun_path + 1);
close(sock);
return -1;
goto out;
}
if (install_service_fd(TRANSPORT_FD_OFF, sock) < 0) {
close(sock);
return -1;
goto out;
}
close(sock);
return 0;
ret = 0;
out:
return ret;
}
static int collect_one_file_entry(FileEntry *fe, u_int32_t id, ProtobufCMessage *base,
......
......@@ -234,6 +234,8 @@ int init_pstree_helper(struct pstree_item *ret)
BUG_ON(!ret->parent);
ret->pid->state = TASK_HELPER;
rsti(ret)->clone_flags = CLONE_FILES | CLONE_FS;
if (shared_fdt_prepare(ret) < 0)
return -1;
task_entries->nr_helpers++;
return 0;
}
......
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