diff --git a/criu/cr-check.c b/criu/cr-check.c index 7eb5ccc31..4f6156a0b 100644 --- a/criu/cr-check.c +++ b/criu/cr-check.c @@ -344,17 +344,11 @@ static int check_fdinfo_signalfd(void) return 0; } -static int check_one_epoll(union fdinfo_entries *e, void *arg) -{ - *(int *)arg = e->epl.e.tfd; - free_event_poll_entry(e); - return 0; -} - static int check_fdinfo_eventpoll(void) { - int efd, pfd[2], proc_fd = 0, ret = -1; + int efd, pfd[2], ret = -1; struct epoll_event ev; + EventpollFileEntry efe = EVENTPOLL_FILE_ENTRY__INIT; if (pipe(pfd)) { pr_perror("Can't make pipe to watch"); @@ -375,20 +369,19 @@ static int check_fdinfo_eventpoll(void) goto epoll_err; } - ret = parse_fdinfo(efd, FD_TYPES__EVENTPOLL, check_one_epoll, &proc_fd); + ret = parse_fdinfo(efd, FD_TYPES__EVENTPOLL, NULL, &efe); if (ret) { pr_err("Error parsing proc fdinfo\n"); goto epoll_err; } - if (pfd[0] != proc_fd) { - pr_err("TFD mismatch (or not met) %d want %d\n", - proc_fd, pfd[0]); + if (efe.n_tfd != 1 || efe.tfd[0]->tfd != pfd[0]) { + pr_err("TFD mismatch (or not met)\n"); ret = -1; goto epoll_err; } - pr_info("Epoll fdinfo works OK (%d vs %d)\n", pfd[0], proc_fd); + pr_info("Epoll fdinfo works OK\n"); epoll_err: close(efd); diff --git a/criu/eventpoll.c b/criu/eventpoll.c index 1253f23b8..87e2457d5 100644 --- a/criu/eventpoll.c +++ b/criu/eventpoll.c @@ -51,53 +51,28 @@ static void pr_info_eventpoll(char *action, EventpollFileEntry *e) pr_info("%seventpoll: id %#08x flags %#04x\n", action, e->id, e->flags); } -struct eventpoll_list { - struct list_head list; - int n; -}; - -static int dump_eventpoll_entry(union fdinfo_entries *e, void *arg) -{ - struct eventpoll_list *ep_list = (struct eventpoll_list *) arg; - EventpollTfdEntry *efd = &e->epl.e; - - pr_info_eventpoll_tfd("Dumping: ", efd); - - list_add_tail(&e->epl.node, &ep_list->list); - ep_list->n++; - - return 0; -} - static int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p) { EventpollFileEntry e = EVENTPOLL_FILE_ENTRY__INIT; - struct eventpoll_list ep_list = {LIST_HEAD_INIT(ep_list.list), 0}; - union fdinfo_entries *te, *tmp; int i, ret = -1; e.id = id; e.flags = p->flags; e.fown = (FownEntry *)&p->fown; - if (parse_fdinfo(lfd, FD_TYPES__EVENTPOLL, dump_eventpoll_entry, &ep_list)) + if (parse_fdinfo(lfd, FD_TYPES__EVENTPOLL, NULL, &e)) goto out; - e.tfd = xmalloc(sizeof(struct EventpollTfdEntry *) * ep_list.n); - if (!e.tfd) - goto out; - - i = 0; - list_for_each_entry(te, &ep_list.list, epl.node) - e.tfd[i++] = &te->epl.e; - e.n_tfd = ep_list.n; - pr_info_eventpoll("Dumping ", &e); ret = pb_write_one(img_from_set(glob_imgset, CR_FD_EVENTPOLL_FILE), &e, PB_EVENTPOLL_FILE); out: - list_for_each_entry_safe(te, tmp, &ep_list.list, epl.node) - free_event_poll_entry(te); + for (i = 0; i < e.n_tfd; i++) { + if (!ret) + pr_info_eventpoll_tfd("Dumping: ", e.tfd[i]); + eventpoll_tfd_entry__free_unpacked(e.tfd[i], NULL); + } + xfree(e.tfd); return ret; } diff --git a/criu/include/fdinfo.h b/criu/include/fdinfo.h index 18e85ede2..45f5746ab 100644 --- a/criu/include/fdinfo.h +++ b/criu/include/fdinfo.h @@ -25,21 +25,14 @@ struct fanotify_mark_entry { }; }; -struct eventpoll_tfd_entry { - EventpollTfdEntry e; - struct list_head node; -}; - union fdinfo_entries { struct inotify_wd_entry ify; struct fanotify_mark_entry ffy; - struct eventpoll_tfd_entry epl; TimerfdEntry tfy; }; extern void free_inotify_wd_entry(union fdinfo_entries *e); extern void free_fanotify_mark_entry(union fdinfo_entries *e); -extern void free_event_poll_entry(union fdinfo_entries *e); struct fdinfo_common { off64_t pos; diff --git a/criu/proc_parse.c b/criu/proc_parse.c index 674088356..4f9f2d7a2 100644 --- a/criu/proc_parse.c +++ b/criu/proc_parse.c @@ -1547,11 +1547,6 @@ void free_fanotify_mark_entry(union fdinfo_entries *e) xfree(e); } -void free_event_poll_entry(union fdinfo_entries *e) -{ - xfree(e); -} - static void parse_fhandle_encoded(char *tok, FhEntry *fh) { char *d = (char *)fh->handle; @@ -1743,27 +1738,31 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type, continue; } if (fdinfo_field(str, "tfd")) { - union fdinfo_entries *e; + EventpollFileEntry *epfe = arg; + EventpollTfdEntry *e; + int i; if (type != FD_TYPES__EVENTPOLL) goto parse_err; - e = xmalloc(sizeof(union fdinfo_entries)); + e = xmalloc(sizeof(EventpollTfdEntry)); if (!e) goto out; - eventpoll_tfd_entry__init(&e->epl.e); + eventpoll_tfd_entry__init(e); ret = sscanf(str, "tfd: %d events: %x data: %"PRIx64, - &e->epl.e.tfd, &e->epl.e.events, &e->epl.e.data); + &e->tfd, &e->events, &e->data); if (ret != 3) { - free_event_poll_entry(e); + eventpoll_tfd_entry__free_unpacked(e, NULL); goto parse_err; } - ret = cb(e, arg); - if (ret) + + i = epfe->n_tfd++; + if (xrealloc_safe(&epfe->tfd, epfe->n_tfd * sizeof(EventpollTfdEntry *))) goto out; + epfe->tfd[i] = e; entry_met = true; continue; }