From: Michal Bloch Date: Thu, 16 Apr 2020 11:35:28 +0000 (+0200) Subject: libdlogutil: put epoll check in the state (nominally) X-Git-Tag: accepted/tizen/5.5/unified/20200428.222959~8^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cefc24bacdd02365f86defbeff85c5a703913278;p=platform%2Fcore%2Fsystem%2Fdlog.git libdlogutil: put epoll check in the state (nominally) It's not really stateful yet, just the refactors needed to make it so. Change-Id: Ief2d8cc6a9e89911eb775fea3e838e8fd8997990 Signed-off-by: Michal Bloch --- diff --git a/include/logretrieve.h b/include/logretrieve.h index 8a94f15..f7e3a8c 100644 --- a/include/logretrieve.h +++ b/include/logretrieve.h @@ -31,6 +31,7 @@ typedef struct { unsigned int logs_dump; unsigned int logs_size; bool monitor; + bool need_epoll; dlogutil_filter_options_s *filter_object; long flush_target; } dlogutil_state_s; diff --git a/src/libdlogutil/logretrieve.c b/src/libdlogutil/logretrieve.c index 1ea38ec..379cb2c 100644 --- a/src/libdlogutil/logretrieve.c +++ b/src/libdlogutil/logretrieve.c @@ -134,11 +134,7 @@ struct fd_info *find_earliest_log(struct fd_info **data_fds, int fd_count, dlogu return best_fdi; } -enum { - ALL_BUFFERS_EMPTY = 1, - BUFFER_NEWLY_DRAINED = 2, -}; -int put_logs_into_vector(struct fd_info **data_fds, int fd_count, struct sort_vector *logs, dlogutil_filter_options_s *filter, dlogutil_entry_s **entry_out) +int put_logs_into_vector(struct fd_info **data_fds, int fd_count, struct sort_vector *logs, dlogutil_filter_options_s *filter, bool *at_least_one_buffer_drained, bool *all_buffers_empty, dlogutil_entry_s **entry_out) { assert(data_fds); assert(logs); @@ -149,22 +145,29 @@ int put_logs_into_vector(struct fd_info **data_fds, int fd_count, struct sort_ve struct fd_info *best_fdi; do { best_fdi = find_earliest_log(data_fds, fd_count, logs->sort_by); - if (!best_fdi) - return ALL_BUFFERS_EMPTY; + if (!best_fdi) { + *all_buffers_empty = true; + *at_least_one_buffer_drained = true; + return 0; + } int r = fdi_push_log(best_fdi, logs, entry_out, filter); if (r) return r; if (*entry_out) { - if (!is_limited_dumping(logs)) - return best_fdi->ops->has_log(best_fdi) ? 0 : BUFFER_NEWLY_DRAINED; + if (!is_limited_dumping(logs)) { + if (!best_fdi->ops->has_log(best_fdi)) + *at_least_one_buffer_drained = true; + return 0; + } 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; + *at_least_one_buffer_drained = true; + return 0; } int dlogutil_state_init(dlogutil_state_s *state, struct fd_info ***data_fds_ptr, int fd_count, unsigned int mode, bool monitor, @@ -182,6 +185,7 @@ int dlogutil_state_init(dlogutil_state_s *state, struct fd_info ***data_fds_ptr, state->fd_count = fd_count; state->data_fds = data_fds; state->monitor = monitor; + state->need_epoll = true; *data_fds_ptr = NULL; sort_vector_init(&state->logs); state->filter_object = filter ? log_filter_from_filter(filter) : dlogutil_filter_options_create(); @@ -361,13 +365,14 @@ int do_print_once(dlogutil_state_s *state, int timeout, dlogutil_entry_s **out) if (handle_flush(state, out)) return 0; - int r = put_logs_into_vector(state->data_fds, state->fd_count, &state->logs, state->filter_object, out); + bool all_buffers_empty = false; + state->need_epoll = false; + int r = put_logs_into_vector(state->data_fds, state->fd_count, &state->logs, state->filter_object, &state->need_epoll, &all_buffers_empty, out); if (r < 0) return r; int refill_err = 0; - if (r == BUFFER_NEWLY_DRAINED - || r == ALL_BUFFERS_EMPTY) + if (state->need_epoll) refill_err = refill_fdi_buffers(state, timeout); if (*out) @@ -377,14 +382,16 @@ int do_print_once(dlogutil_state_s *state, int timeout, dlogutil_entry_s **out) if (refill_err) return refill_err; - set_flush_target(state, r == ALL_BUFFERS_EMPTY); + set_flush_target(state, all_buffers_empty); remove_drained_buffers(state); } 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); + bool all_buffers_empty; + do { + all_buffers_empty = false; + r = put_logs_into_vector(state->data_fds, state->fd_count, &state->logs, state->filter_object, &state->need_epoll, &all_buffers_empty, out); + } while (r == 0 && !all_buffers_empty && !*out); if (r < 0) return r; if (*out) diff --git a/src/tests/logutil.c b/src/tests/logutil.c index 17c7b4a..927202d 100644 --- a/src/tests/logutil.c +++ b/src/tests/logutil.c @@ -8,7 +8,7 @@ bool process_log(const dlogutil_entry_s *e, struct timespec reference_ts, dlogutil_sorting_order_e stamp_type, long timeout, int *callback_ret); struct fd_info *find_earliest_log(struct fd_info **data_fds, int fd_count, dlogutil_sorting_order_e sort_by); -int put_logs_into_vector(struct fd_info **data_fds, int fd_count, struct sort_vector *logs, dlogutil_filter_options_s *filter, dlogutil_entry_s **entry_out); +int put_logs_into_vector(struct fd_info **data_fds, int fd_count, struct sort_vector *logs, dlogutil_filter_options_s *filter, bool *need_epoll, bool *any_drained, dlogutil_entry_s **entry_out); int __wrap_clock_gettime(clockid_t clk_id, struct timespec *tp) { @@ -144,17 +144,24 @@ int main() sort_vector_pop(&sv); dlogutil_entry_s *vector_overflown = NULL; - assert(put_logs_into_vector(fds, 0, &sv, (dlogutil_filter_options_s *)0xEEE, &vector_overflown) == 1); + bool need_epoll = false, all_drained = false; + assert(put_logs_into_vector(fds, 0, &sv, (dlogutil_filter_options_s *)0xEEE, &need_epoll, &all_drained, &vector_overflown) == 0); assert(!vector_overflown); + assert(all_drained); + assert(need_epoll); fdi_push_log_ret = -EIO; - assert(put_logs_into_vector(fds, 10, &sv, (dlogutil_filter_options_s *)0xEEE, &vector_overflown) == -EIO); + assert(put_logs_into_vector(fds, 10, &sv, (dlogutil_filter_options_s *)0xEEE, &need_epoll, &all_drained, &vector_overflown) == -EIO); assert(!vector_overflown); fdi_push_log_ret = 0; - assert(put_logs_into_vector(fds, 10, &sv, (dlogutil_filter_options_s *)0xEEE, &vector_overflown) == 2); + all_drained = false; + need_epoll = false; + assert(put_logs_into_vector(fds, 10, &sv, (dlogutil_filter_options_s *)0xEEE, &need_epoll, &all_drained, &vector_overflown) == 0); assert(!vector_overflown); assert(sort_vector_used_size(&sv) == 1); + assert(!all_drained); + assert(need_epoll); sort_vector_free(&sv); }