int nfds;
int r;
struct fd_info *fdi = NULL;
- int pipes = 0;
+ int epoll_cnt = 0;
int epollfd;
struct epoll_event ev = { .events = EPOLLIN };
ev.data.ptr = data_fds[nfds];
if (fd_set_flags(fd, O_NONBLOCK) < 0)
return;
- if (data_fds[nfds]->ops == &ops_pipe) // HACK
- ++pipes;
if (data_fds[nfds]->ops != &ops_binfile) { // HACK
- epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev);
+ if (data_fds[nfds]->log_len != 0) {
+ /* can't rely on the regular log_len-based removal path
+ as there would potentially be no read to trigger it */
+ epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev);
+ ++epoll_cnt;
+ }
+
struct fd_info *swap_tmp = data_fds[nfds];
data_fds[nfds--] = data_fds[--fd_count];
data_fds[fd_count] = swap_tmp; // swap non-destructively lest memory leak
}
}
- while (true) {
+ while ((epoll_cnt + fd_count) > 0) {
if (!fdi && !dump)
flush_logs(logs, l_file);
fdi = (struct fd_info*) ev.data.ptr;
else if (nfds == 0 && fd_count > 0)
fdi = data_fds[fd_count - 1];
- else if (dump)
- break;
else {
fdi = NULL;
continue;
break;
if (r == 0 || (dump && fdi->log_len <= 0 && fdi->log_len != UNLIMITED_LOG_LEN)) {
- if (fdi->ops != &ops_binfile) // HACK
+ if (fdi->ops != &ops_binfile) { // HACK
epoll_ctl(epollfd, EPOLL_CTL_DEL, fdi->fd, NULL);
-
- if (fdi->ops == &ops_pipe && dump) // HACK
- --pipes;
- else if (--fd_count <= 0)
- break;
+ --epoll_cnt;
+ } else
+ --fd_count;
}
}