From d9a753742d774ce801aba1e29b61b2164938e14b Mon Sep 17 00:00:00 2001 From: Michal Bloch Date: Fri, 27 Mar 2020 20:29:54 +0100 Subject: [PATCH] libdlogutil: support timeout param (nominally) Change-Id: I405093fb559b4f1935e404aa8ae3f597fcdf6cb0 Signed-off-by: Michal Bloch --- src/libdlogutil/logretrieve.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/libdlogutil/logretrieve.c b/src/libdlogutil/logretrieve.c index eb5d4ec..2646a3d 100644 --- a/src/libdlogutil/logretrieve.c +++ b/src/libdlogutil/logretrieve.c @@ -22,6 +22,12 @@ // C #include + +/* This is the timeout used by the "old" API currently being torn down. + * It cannot be -1 because then logs won't be flushed. It has to be + * some reasonably low value to keep dlogutil responsive. */ +#define DEFAULT_EPOLL_TIMEOUT 100 + int create_initial_fdis(struct fd_info ***fdis, int enabled_buffers, bool is_pipe, const struct log_config *conf) { assert(fdis); @@ -233,7 +239,7 @@ int dlogutil_state_init(dlogutil_state_s *state, struct fd_info ***data_fds_ptr, * @param[in] l_file File output metadata * @return int 0 if successful, a negative value on error, callback's return value if it isn't 0 */ -int do_print_once(dlogutil_state_s *state, dlogutil_entry_s **out) +int do_print_once(dlogutil_state_s *state, int timeout, dlogutil_entry_s **out) { *out = NULL; while (state->epoll_cnt > 0) { @@ -258,7 +264,7 @@ int do_print_once(dlogutil_state_s *state, dlogutil_entry_s **out) if (r == BUFFER_NEWLY_DRAINED || r == ALL_BUFFERS_EMPTY) { - int const nfds = TEMP_FAILURE_RETRY(epoll_wait(state->epollfd, state->evs, state->epoll_cnt, 100)); + int const nfds = epoll_wait(state->epollfd, state->evs, state->epoll_cnt, timeout); if (nfds < 0) return -errno; @@ -346,7 +352,10 @@ int do_print(dlogutil_state_s *state, dlogutil_entry_cb callback, void *userdata { while (true) { dlogutil_entry_s *out; - int r = do_print_once(state, &out); + int r; + do + r = do_print_once(state, DEFAULT_EPOLL_TIMEOUT, &out); + while (r == -EINTR); if (r != 0) return r; -- 2.7.4