From 06bdc58ec9225f16911b969e0ae4139ba85aee2d Mon Sep 17 00:00:00 2001 From: Michal Bloch Date: Tue, 27 Feb 2018 12:19:04 +0100 Subject: [PATCH] util: handle epoll fd correctly Handle creation failure and close after use. Change-Id: Iafaf888e18183f09ea9990c535cdec1ff9fd4f50 Signed-off-by: Michal Bloch --- src/logutil/logutil.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/logutil/logutil.c b/src/logutil/logutil.c index b4a3962..3e05c02 100755 --- a/src/logutil/logutil.c +++ b/src/logutil/logutil.c @@ -113,12 +113,16 @@ static void do_print(struct fd_info **data_fds, int fd_count, int dump, struct s struct epoll_event ev = { .events = EPOLLIN }; epollfd = epoll_create1(0); + if (epollfd < 0) { + printf("epoll_create failed: %m"); + return; + } for (nfds = 0; nfds < fd_count; ++nfds) { int fd = data_fds[nfds]->fd; ev.data.ptr = data_fds[nfds]; if (fd_set_flags(fd, O_NONBLOCK) < 0) - return; + goto cleanup; if (data_fds[nfds]->ops != &ops_binfile) { // HACK if (data_fds[nfds]->log_len != 0) { /* can't rely on the regular log_len-based removal path @@ -174,6 +178,9 @@ static void do_print(struct fd_info **data_fds, int fd_count, int dump, struct s logs->timeout = 0; flush_logs(logs, l_file); + +cleanup: + close(epollfd); } int parse_options(int argc, char **argv, struct log_file *l_file, struct sort_vector *logs, int *enabled_buffers, list_head *file_input_names, action_e *action, int *dump, list_head *filters) -- 2.7.4