libdlogutil: extract a common check to a function 80/229680/1
authorMichal Bloch <m.bloch@samsung.com>
Thu, 2 Apr 2020 12:52:26 +0000 (14:52 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Thu, 2 Apr 2020 13:43:34 +0000 (15:43 +0200)
Change-Id: I220e891e97a57bf13f775f1b4a928333b24710d2
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/libdlogutil/logretrieve.c

index 2646a3d..18928fe 100644 (file)
  * some reasonably low value to keep dlogutil responsive. */
 #define DEFAULT_EPOLL_TIMEOUT 100
 
+bool is_limited_dumping(struct sort_vector *logs)
+{
+       return logs->dump != DLOGUTIL_MODE_CONTINUOUS
+           && logs->dump != DLOGUTIL_MAX_DUMP_SIZE;
+}
+
 int create_initial_fdis(struct fd_info ***fdis, int enabled_buffers, bool is_pipe, const struct log_config *conf)
 {
        assert(fdis);
@@ -281,8 +287,7 @@ int do_print_once(dlogutil_state_s *state, int timeout, dlogutil_entry_s **out)
                }
 
                if (*out) {
-                       if (state->logs.dump == DLOGUTIL_MODE_CONTINUOUS
-                       ||  state->logs.dump == DLOGUTIL_MAX_DUMP_SIZE)
+                       if (!is_limited_dumping(&state->logs))
                                return 0;
                        free(*out);
                        *out = NULL;
@@ -329,14 +334,13 @@ int do_print_once(dlogutil_state_s *state, int timeout, dlogutil_entry_s **out)
                if (!*out)
                        break;
 
-               if (state->logs.dump == DLOGUTIL_MODE_CONTINUOUS
-               ||  state->logs.dump == DLOGUTIL_MAX_DUMP_SIZE)
+               if (!is_limited_dumping(&state->logs))
                        return 0;
                free(*out);
                *out = NULL;
        }
 
-       if (state->logs.dump != DLOGUTIL_MODE_CONTINUOUS && state->logs.dump != DLOGUTIL_MAX_DUMP_SIZE)
+       if (is_limited_dumping(&state->logs))
                while (sort_vector_used_size(&state->logs) > state->logs.dump)
                        sort_vector_pop(&state->logs);