From 9a456eef2faf5d2021e52ad20571ccc53ec024ae Mon Sep 17 00:00:00 2001 From: Michal Bloch Date: Tue, 31 Mar 2020 18:29:18 +0200 Subject: [PATCH] libdlogutil: simplify -t mode sorting Change-Id: I709b29b2b510d49410b790c648fa9eabe8802c18 Signed-off-by: Michal Bloch --- src/libdlogutil/logretrieve.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/libdlogutil/logretrieve.c b/src/libdlogutil/logretrieve.c index 18928fe..bd0f386 100644 --- a/src/libdlogutil/logretrieve.c +++ b/src/libdlogutil/logretrieve.c @@ -155,8 +155,13 @@ int put_logs_into_vector(struct fd_info **data_fds, int fd_count, struct sort_ve int r = fdi_push_log(best_fdi, logs, entry_out, filter); if (r) return r; - if (*entry_out) - return best_fdi->ops->has_log(best_fdi) ? 0 : BUFFER_NEWLY_DRAINED; + if (*entry_out) { + if (!is_limited_dumping(logs)) + return best_fdi->ops->has_log(best_fdi) ? 0 : BUFFER_NEWLY_DRAINED; + + free(*entry_out); + *entry_out = NULL; + } } while (best_fdi->ops->has_log(best_fdi)); // if a buffer got drained, break to give them all a chance to refill return BUFFER_NEWLY_DRAINED; @@ -286,12 +291,8 @@ int do_print_once(dlogutil_state_s *state, int timeout, dlogutil_entry_s **out) } } - if (*out) { - if (!is_limited_dumping(&state->logs)) - return 0; - free(*out); - *out = NULL; - } + if (*out) + return 0; /* The oldest log can be so fresh as to be from the future * (i.e. has a negative age). This can happen when somebody @@ -325,20 +326,14 @@ int do_print_once(dlogutil_state_s *state, int timeout, dlogutil_entry_s **out) } } - while (true) { - int r = put_logs_into_vector(state->data_fds, state->fd_count, &state->logs, state->filter_object, out); - if (r == 1) - break; - if (r < 0) - return r; - if (!*out) - break; - - if (!is_limited_dumping(&state->logs)) - return 0; - free(*out); - *out = NULL; - } + int r; + do + r = put_logs_into_vector(state->data_fds, state->fd_count, &state->logs, state->filter_object, out); + while (r == BUFFER_NEWLY_DRAINED && !*out); + if (r < 0) + return r; + if (*out) + return 0; if (is_limited_dumping(&state->logs)) while (sort_vector_used_size(&state->logs) > state->logs.dump) -- 2.7.4