util: handle epoll fd correctly 04/171204/1
authorMichal Bloch <m.bloch@samsung.com>
Tue, 27 Feb 2018 11:19:04 +0000 (12:19 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Tue, 27 Feb 2018 11:19:09 +0000 (12:19 +0100)
Handle creation failure and close after use.

Change-Id: Iafaf888e18183f09ea9990c535cdec1ff9fd4f50
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/logutil/logutil.c

index b4a3962..3e05c02 100755 (executable)
@@ -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)