[v5,15/19] epoll: Exit with error if tfd is missing

Submitted by Cyrill Gorcunov on July 4, 2018, 3:51 p.m.

Details

Message ID 20180704155147.29114-16-gorcunov@gmail.com
State Accepted
Series "epoll: Add support for duped targets"
Commit d7d6973706605950bb1c1e3b9fbdad86405162ed
Headers show

Commit Message

Cyrill Gorcunov July 4, 2018, 3:51 p.m.
If we can't find target file descriptor we should
exit on dump with error instead of skipping it.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 criu/eventpoll.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/eventpoll.c b/criu/eventpoll.c
index 6247b955eabf..3dcc731ba86a 100644
--- a/criu/eventpoll.c
+++ b/criu/eventpoll.c
@@ -129,9 +129,8 @@  static int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p)
 {
 	FileEntry fe = FILE_ENTRY__INIT;
 	EventpollFileEntry e = EVENTPOLL_FILE_ENTRY__INIT;
-	EventpollTfdEntry **tfd_cpy = NULL;
-	ssize_t i, j, n_tfd_cpy;
 	uint32_t *toff = NULL;
+	ssize_t i, j;
 	int ret = -1;
 
 	e.id = id;
@@ -145,11 +144,6 @@  static int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p)
 	fe.id = e.id;
 	fe.epfd = &e;
 
-	n_tfd_cpy = e.n_tfd;
-	tfd_cpy = xmemdup(e.tfd, sizeof(e.tfd[0]) * e.n_tfd);
-	if (!tfd_cpy)
-		goto out;
-
 	/*
 	 * In regular case there is no so many dup'ed
 	 * descriptors so instead of complex mappings
@@ -178,17 +172,16 @@  static int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p)
 	 * pid's file set.
 	 */
 	if (p->dfds) {
-		for (i = j = 0; i < e.n_tfd; i++) {
+		for (i = 0; i < e.n_tfd; i++) {
 			int tfd = find_tfd(p->pid, p->fd, p->dfds->fds,
 					   p->dfds->nr_fds, e.tfd[i]->tfd, toff[i]);
 			if (tfd == -1) {
-				pr_warn("Escaped/closed fd descriptor %d on pid %d, ignoring\n",
+				pr_err("Escaped/closed fd descriptor %d on pid %d\n",
 					e.tfd[i]->tfd, p->pid);
-				continue;
+				goto out;
 			}
-			e.tfd[j++]->tfd = tfd;
+			e.tfd[i]->tfd = tfd;
 		}
-		e.n_tfd = j; /* New amount of "valid" fds */
 	} else
 		pr_warn_once("Unix SCM files are not verified\n");
 
@@ -199,13 +192,9 @@  static int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p)
 			pr_info_eventpoll_tfd("Dumping: ", e.id, e.tfd[i]);
 	}
 
-	/* Restore former values to free resources */
-	memcpy(e.tfd, tfd_cpy, sizeof(e.tfd[0]) * n_tfd_cpy);
-	e.n_tfd = n_tfd_cpy;
 out:
 	for (i = 0; i < e.n_tfd; i++)
 		eventpoll_tfd_entry__free_unpacked(e.tfd[i], NULL);
-	xfree(tfd_cpy);
 	xfree(e.tfd);
 	xfree(toff);