From caced82ea7e51fc393e379b8645b9b419d063a78 Mon Sep 17 00:00:00 2001 From: Radim Vansa Date: Thu, 19 Oct 2023 16:53:27 +0200 Subject: [PATCH 1/2] Fix inheriting standard descriptors --- criu/files.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/criu/files.c b/criu/files.c index 1845bae7f..dbee5b268 100644 --- a/criu/files.c +++ b/criu/files.c @@ -855,6 +855,7 @@ int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info, bool fake) if (!collect_fd_to(pid, e, rst_info, fdesc, fake, false)) return -1; + snprintf(inh_id, sizeof(inh_id), "fd[%d]", e->fd); if (inherit_fd_lookup_id(inh_id) < 0) { fdesc->fds_inherited = FDIH_UNINHERITED; } else if (fdesc->fds_inherited == FDIH_UNKNOWN) { @@ -1116,7 +1117,7 @@ int setup_and_serve_out(struct fdinfo_list_entry *fle, int new_fd) struct file_desc *d = fle->desc; pid_t pid = fle->pid; - if (reopen_fd_as(fle->fe->fd, new_fd)) + if (reopen_fd_as_nocheck(fle->fe->fd, new_fd)) return -1; if (fcntl(fle->fe->fd, F_SETFD, fle->fe->flags) == -1) { From 05fb26b084b2911236b7885d4dc4613a359543cf Mon Sep 17 00:00:00 2001 From: Radim Vansa Date: Thu, 7 Dec 2023 10:40:06 +0100 Subject: [PATCH 2/2] Create a pipe by first non-inherited FD --- criu/pipes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/criu/pipes.c b/criu/pipes.c index 43ff06e3d..ea9ec6f34 100644 --- a/criu/pipes.c +++ b/criu/pipes.c @@ -110,7 +110,8 @@ static int mark_pipe_master_cb(struct pprep_head *ph) list_move(&pic->list, &head); f = file_master(&pic->d); - if (fdinfo_rst_prio(f, fle)) { + /* Pipe that is going to inherit can't be a master */ + if (fdinfo_rst_prio(f, fle) || p->d.fds_inherited >= FDIH_FROM_0) { p = pic; fle = f; }