libdlogutil: simplify -t mode sorting 86/229386/3
authorMichal Bloch <m.bloch@samsung.com>
Tue, 31 Mar 2020 16:29:18 +0000 (18:29 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Thu, 2 Apr 2020 13:46:21 +0000 (15:46 +0200)
Change-Id: I709b29b2b510d49410b790c648fa9eabe8802c18
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/libdlogutil/logretrieve.c

index 18928fe..bd0f386 100644 (file)
@@ -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)