libdlogutil: support timeout param (nominally) 85/229385/2
authorMichal Bloch <m.bloch@samsung.com>
Fri, 27 Mar 2020 19:29:54 +0000 (20:29 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Thu, 2 Apr 2020 12:50:06 +0000 (14:50 +0200)
Change-Id: I405093fb559b4f1935e404aa8ae3f597fcdf6cb0
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/libdlogutil/logretrieve.c

index eb5d4ec..2646a3d 100644 (file)
 // C
 #include <limits.h>
 
+
+/* 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;