Commit bf7a74d4 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Cyrill Gorcunov

Helper for moving image fd

When opening an fd at a position where the current image fd sits
the latter one should be moved.

Introduce a helper for this.

Signed-off-by; Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent 99cc8794
......@@ -506,15 +506,8 @@ static int open_fd(int pid, struct fdinfo_entry *fe, int *cfd)
{
int fd, tmp;
if (*cfd == (int)fe->addr) {
tmp = dup(*cfd);
if (tmp < 0) {
pr_perror("Can't dup file\n");
return -1;
}
*cfd = tmp;
}
if (move_img_fd(cfd, (int)fe->addr))
return -1;
if (fe->addr == ~0L)
return restore_cwd(fe, *cfd);
......@@ -940,15 +933,8 @@ static int reopen_pipe(int src, int *dst, int *other)
int tmp;
if (*dst != -1) {
if (*other == *dst) {
tmp = dup(*other);
if (tmp < 0) {
pr_perror("dup failed\n");
return -1;
}
close_safe(other);
*other = tmp;
}
if (move_img_fd(other, *dst))
return -1;
return reopen_fd_as(*dst, src);
}
......@@ -1107,17 +1093,8 @@ static int open_pipe(int pid, struct pipe_entry *e, int *pipes_fd)
struct pipe_info *pi;
pr_info("\t%d: Opening pipe %x on fd %d\n", pid, e->pipeid, e->fd);
if (e->fd == *pipes_fd) {
int tmp;
tmp = dup(*pipes_fd);
if (tmp < 0) {
pr_perror("%d: Can't dup file\n", pid);
return -1;
}
*pipes_fd = tmp;
}
if (move_img_fd(pipes_fd, e->fd))
return -1;
pi = find_pipe(e->pipeid);
if (!pi) {
......
......@@ -167,6 +167,7 @@ extern void printk_vma(struct vma_area *vma_area);
#define pr_info_siginfo(siginfo) printk_siginfo(siginfo)
extern int reopen_fd_as(int new_fd, int old_fd);
extern int move_img_fd(int *img_fd, int want_fd);
extern int parse_maps(pid_t pid, struct list_head *vma_area_list, bool use_map_files);
extern int close_safe(int *fd);
......
......@@ -144,6 +144,23 @@ int reopen_fd_as(int new_fd, int old_fd)
return 0;
}
int move_img_fd(int *img_fd, int want_fd)
{
if (*img_fd == want_fd) {
int tmp;
tmp = dup(*img_fd);
if (tmp < 0) {
pr_perror("Can't dup file\n");
return -1;
}
*img_fd = tmp;
}
return 0;
}
int parse_maps(pid_t pid, struct list_head *vma_area_list, bool use_map_files)
{
struct vma_area *vma_area = NULL;
......
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