Commit 17e80025 authored by Andrei Vagin's avatar Andrei Vagin

fs: take into account that cr_system overrides standard descriptors

(00.027596) mnt: Dumping mountpoints
(00.027600) mnt: 	90: 2f:/ @ ./dev/pts
(00.027614) mnt: 	130: 2e:/ @ ./run
tar: /proc/self/fd/1: Cannot open: Not a directory
tar: Error is not recoverable: exiting now
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent c7684913
...@@ -384,15 +384,27 @@ static int tmpfs_dump(struct mount_info *pm) ...@@ -384,15 +384,27 @@ static int tmpfs_dump(struct mount_info *pm)
int ret = -1, fd = -1, userns_pid = -1; int ret = -1, fd = -1, userns_pid = -1;
char tmpfs_path[PSFDS]; char tmpfs_path[PSFDS];
struct cr_img *img; struct cr_img *img;
int tmp_fds[3], ntmp_fds = 0, i;
fd = open_mountpoint(pm); fd = open_mountpoint(pm);
if (fd < 0) if (fd < 0)
return MNT_UNREACHABLE; return MNT_UNREACHABLE;
/* if fd happens to be 0 here, we need to move it to something /*
* non-zero, because cr_system_userns closes STDIN_FILENO as we are not * fd should not be one of standard descriptors, because
* interested in passing stdin to tar. * cr_system_userns will override them.
*/ */
for (i = 0; i < 3; i++) {
if (fd > 2)
break;
tmp_fds[ntmp_fds++] = fd;
fd = dup(fd);
if (fd < 0) {
pr_perror("Unable to duplicate a file descriptor");
goto out;
}
}
if (move_fd_from(&fd, STDIN_FILENO) < 0) if (move_fd_from(&fd, STDIN_FILENO) < 0)
goto out; goto out;
...@@ -427,6 +439,8 @@ static int tmpfs_dump(struct mount_info *pm) ...@@ -427,6 +439,8 @@ static int tmpfs_dump(struct mount_info *pm)
close_image(img); close_image(img);
out: out:
for (i = 0; i < ntmp_fds; i++)
close(tmp_fds[i]);
close_safe(&fd); close_safe(&fd);
return ret; return ret;
} }
......
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