[CRIU] [PATCH] restore: Don't close pstree_fd several times
Cyrill Gorcunov
gorcunov at openvz.org
Tue Mar 6 09:46:33 EST 2012
There is a scenario when pstree_fd may be tried
to close several times -- if we start crtools
with "detach" option.
So simply make restore_root_task to close opened
file descriptor, this also simplifies the code.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
cr-restore.c | 16 +++++++---------
1 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/cr-restore.c b/cr-restore.c
index cbae24a..f53f5cb 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1394,13 +1394,13 @@ static int restore_root_task(int fd, struct cr_options *opts)
struct sigaction act, old_act;
ret = read(fd, &e, sizeof(e));
+ close(fd);
+
if (ret != sizeof(e)) {
pr_perror("Can't read root pstree entry");
return -1;
}
- close(fd);
-
ret = sigaction(SIGCHLD, NULL, &act);
if (ret < 0) {
perror("sigaction() failed\n");
@@ -1457,19 +1457,17 @@ static int restore_all_tasks(pid_t pid, struct cr_options *opts)
{
int pstree_fd = -1;
u32 type = 0;
- int ret = -1;
pstree_fd = open_image_ro(CR_FD_PSTREE, pstree_pid);
if (pstree_fd < 0)
return -1;
- if (prepare_shared(pstree_fd))
- goto out;
+ if (prepare_shared(pstree_fd)) {
+ close(pstree_fd);
+ return -1;
+ }
- ret = restore_root_task(pstree_fd, opts);
-out:
- close_safe(&pstree_fd);
- return ret;
+ return restore_root_task(pstree_fd, opts);
}
static long restorer_get_vma_hint(pid_t pid, struct list_head *self_vma_list, long vma_len)
--
1.7.7.6
More information about the CRIU
mailing list