mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-18 00:58:31 +00:00
service-fd: close a source file descriptor in install_service_fd()
Currently, install_service_fd() always creates a new file descriptor, but it is going to be reworked to reuse a file descriptor when it is possible. Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
parent
19d3da0d9b
commit
9c40efdd19
12 changed files with 7 additions and 19 deletions
|
|
@ -164,7 +164,7 @@ int add_rpc_notify(int sk)
|
|||
BUG_ON(scripts_mode == SCRIPTS_SHELL);
|
||||
scripts_mode = SCRIPTS_RPC;
|
||||
|
||||
if (install_service_fd(RPC_SK_OFF, sk) < 0)
|
||||
if (install_service_fd(RPC_SK_OFF, dup(sk)) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1671,7 +1671,6 @@ static int prepare_cgroup_sfd(CgroupEntry *ce)
|
|||
}
|
||||
|
||||
ret = install_service_fd(CGROUP_YARD, i);
|
||||
close(i);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
|
|
|
|||
|
|
@ -1297,8 +1297,6 @@ static int dump_one_task(struct pstree_item *item, InventoryEntry *parent_ie)
|
|||
|
||||
if (install_service_fd(CR_PROC_FD_OFF, pfd) < 0)
|
||||
goto err_cure_imgset;
|
||||
|
||||
close(pfd);
|
||||
}
|
||||
|
||||
ret = parasite_fixup_vdso(parasite_ctl, pid, &vmas);
|
||||
|
|
|
|||
|
|
@ -2051,7 +2051,6 @@ static int restore_root_task(struct pstree_item *init)
|
|||
}
|
||||
|
||||
ret = install_service_fd(CR_PROC_FD_OFF, fd);
|
||||
close(fd);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
|
|
|
|||
|
|
@ -78,7 +78,6 @@ int fdstore_init(void)
|
|||
}
|
||||
|
||||
ret = install_service_fd(FDSTORE_SK_OFF, sk);
|
||||
close(sk);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
|
|
|
|||
|
|
@ -1764,11 +1764,8 @@ int open_transport_socket(void)
|
|||
goto out;
|
||||
}
|
||||
|
||||
if (install_service_fd(TRANSPORT_FD_OFF, sock) < 0) {
|
||||
close(sock);
|
||||
if (install_service_fd(TRANSPORT_FD_OFF, sock) < 0)
|
||||
goto out;
|
||||
}
|
||||
close(sock);
|
||||
ret = 0;
|
||||
out:
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -472,7 +472,8 @@ int open_image_dir(char *dir)
|
|||
}
|
||||
|
||||
ret = install_service_fd(IMG_FD_OFF, fd);
|
||||
close(fd);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
fd = ret;
|
||||
|
||||
if (opts.img_parent) {
|
||||
|
|
|
|||
|
|
@ -183,7 +183,6 @@ int log_init(const char *output)
|
|||
}
|
||||
|
||||
fd = install_service_fd(LOG_FD_OFF, new_logfd);
|
||||
close(new_logfd);
|
||||
if (fd < 0)
|
||||
goto err;
|
||||
|
||||
|
|
|
|||
|
|
@ -3398,7 +3398,6 @@ static int mntns_set_root_fd(pid_t pid, int fd)
|
|||
ret = install_service_fd(ROOT_FD_OFF, fd);
|
||||
if (ret >= 0)
|
||||
mntns_root_pid = pid;
|
||||
close(fd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1427,11 +1427,9 @@ static int start_usernsd(void)
|
|||
if (install_service_fd(USERNSD_SK, sk[0]) < 0) {
|
||||
kill(usernsd_pid, SIGKILL);
|
||||
waitpid(usernsd_pid, NULL, 0);
|
||||
close(sk[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(sk[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2549,7 +2549,6 @@ int netns_keep_nsfd(void)
|
|||
pr_err("Can't install ns net reference\n");
|
||||
else
|
||||
pr_info("Saved netns fd for links restore\n");
|
||||
close(ns_fd);
|
||||
|
||||
return ret >= 0 ? 0 : -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -314,7 +314,6 @@ static inline int set_proc_pid_fd(int pid, int fd)
|
|||
|
||||
open_proc_pid = pid;
|
||||
ret = install_service_fd(PROC_PID_FD_OFF, fd);
|
||||
close(fd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -348,7 +347,7 @@ void close_proc()
|
|||
|
||||
int set_proc_fd(int fd)
|
||||
{
|
||||
if (install_service_fd(PROC_FD_OFF, fd) < 0)
|
||||
if (install_service_fd(PROC_FD_OFF, dup(fd)) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -365,7 +364,6 @@ static int open_proc_sfd(char *path)
|
|||
}
|
||||
|
||||
ret = install_service_fd(PROC_FD_OFF, fd);
|
||||
close(fd);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
|
|
@ -502,10 +500,12 @@ int install_service_fd(enum sfd_type type, int fd)
|
|||
|
||||
if (dup3(fd, sfd, O_CLOEXEC) != sfd) {
|
||||
pr_perror("Dup %d -> %d failed", fd, sfd);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
set_bit(type, sfd_map);
|
||||
close(fd);
|
||||
return sfd;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue