forking: Always close pid proc before child creation

Child does not know about parent's pid proc fd,
and it can't close it by fd. Next patch will do
close_old_files() optional, and it will base on
the fact there is no leftover fds. So, close pid
proc directly.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
Kirill Tkhai 2017-06-28 18:54:33 +03:00 committed by Andrei Vagin
parent 0382311056
commit 0d52c7e9e2

View file

@ -1379,9 +1379,7 @@ static int call_clone_fn(void *arg)
}
close(fd);
if (ca->clone_flags & CLONE_FILES)
close_pid_proc();
close_pid_proc();
pid = clone_noasan(restore_task_with_children, ca->clone_flags | CLONE_PARENT | SIGCHLD, ca);
return pid > 0 ? 0 : -1;
}
@ -1398,8 +1396,7 @@ static int do_fork_with_pid(struct pstree_item *item, struct ns_id *pid_ns, stru
pr_err("Can't set next pid\n");
return -1;
}
if (ca->clone_flags & CLONE_FILES)
close_pid_proc();
close_pid_proc();
pid = clone_noasan(restore_task_with_children, ca->clone_flags | SIGCHLD, ca);
if (item == root_item) {
/* We want to use it before it's set in restore_task_with_children() */
@ -1430,9 +1427,6 @@ static int do_fork_with_pid(struct pstree_item *item, struct ns_id *pid_ns, stru
return -1;
}
if (ca->clone_flags & CLONE_FILES)
close_pid_proc();
if (block_sigmask(&sig_mask, SIGCHLD) < 0)
return -1;