diff --git a/criu/cr-restore.c b/criu/cr-restore.c index 5db7cf189..bec321cfb 100644 --- a/criu/cr-restore.c +++ b/criu/cr-restore.c @@ -267,6 +267,10 @@ static int root_prepare_shared(void) if (ret) goto err; + ret = open_transport_socket(); + if (ret) + goto err; + show_saved_files(); err: return ret; @@ -603,6 +607,8 @@ static int restore_one_alive_task(int pid, CoreEntry *core) if (prepare_vmas(current, ta)) return -1; + close_service_fd(TRANSPORT_FD_OFF); + return sigreturn_restore(pid, ta, args_len, core); } diff --git a/criu/files.c b/criu/files.c index a66a1424d..a29d317e6 100644 --- a/criu/files.c +++ b/criu/files.c @@ -1000,11 +1000,7 @@ static int serve_out_fd(int pid, int fd, struct file_desc *d) int sock, ret; struct fdinfo_list_entry *fle; - sock = socket(PF_UNIX, SOCK_DGRAM, 0); - if (sock < 0) { - pr_perror("Can't create socket"); - return -1; - } + sock = get_service_fd(TRANSPORT_FD_OFF); pr_info("\t\tCreate fd for %d\n", fd); @@ -1022,7 +1018,6 @@ static int serve_out_fd(int pid, int fd, struct file_desc *d) ret = 0; out: - close(sock); return ret; } @@ -1672,3 +1667,21 @@ char *external_lookup_by_key(char *key) } return NULL; } + +int open_transport_socket() +{ + int sock; + + sock = socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0); + if (sock < 0) { + pr_perror("Can't create socket"); + return -1; + } + if (install_service_fd(TRANSPORT_FD_OFF, sock) < 0) { + close(sock); + return -1; + } + close(sock); + + return 0; +} diff --git a/criu/include/files.h b/criu/include/files.h index e0b853dc4..7513b2157 100644 --- a/criu/include/files.h +++ b/criu/include/files.h @@ -201,4 +201,6 @@ extern FdinfoEntry *dup_fdinfo(FdinfoEntry *old, int fd, unsigned flags); int dup_fle(struct pstree_item *task, struct fdinfo_list_entry *ple, int fd, unsigned flags); +extern int open_transport_socket(void); + #endif /* __CR_FILES_H__ */ diff --git a/criu/include/servicefd.h b/criu/include/servicefd.h index e133752fc..a35f25aa6 100644 --- a/criu/include/servicefd.h +++ b/criu/include/servicefd.h @@ -19,6 +19,7 @@ enum sfd_type { CGROUP_YARD, USERNSD_SK, /* Socket for usernsd */ NS_FD_OFF, /* Node's net namespace fd */ + TRANSPORT_FD_OFF, /* to transfer file descriptors */ SERVICE_FD_MAX };