Commit 43f62f42 authored by Pavel Emelyanov's avatar Pavel Emelyanov

rst: Close standard descriptors before fds restore

Strictly speaking we have to close all fds before reopening them from the
image. This can be done using not yet merged nextfd syscall, but it's not
yet merged :( By now just close std and 255 (bash's) descriptors. This is
ugly, but I prefer to wait for the nextfd syscall.

But skip the init tasks' stds becase the existing zdtm implementation
uses system() in such tasks which doesn't work when all fds are closed.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent a03323e1
...@@ -433,12 +433,33 @@ static int open_fdinfo(int pid, struct fdinfo_list_entry *fle, int state) ...@@ -433,12 +433,33 @@ static int open_fdinfo(int pid, struct fdinfo_list_entry *fle, int state)
return ret; return ret;
} }
static int close_old_fds(struct pstree_item *me)
{
/*
* FIXME -- The existing test_init implementation uses system()
* which in turn doesn't work when all fds are closed
*/
if (me->pid.virt == 1)
return 0;
/* FIXME -- wait for nextfd syscall (or read proc) */
close(0);
close(1);
close(2);
close(255); /* bash */
return 0;
}
int prepare_fds(struct pstree_item *me) int prepare_fds(struct pstree_item *me)
{ {
u32 ret; u32 ret;
int state; int state;
struct fdinfo_list_entry *fle; struct fdinfo_list_entry *fle;
ret = close_old_fds(me);
if (ret)
return ret;
pr_info("Opening fdinfo-s\n"); pr_info("Opening fdinfo-s\n");
for (state = 0; state < FD_STATE_MAX; state++) { for (state = 0; state < FD_STATE_MAX; state++) {
......
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