Subreaders: methods now return an error code 05/273705/6
authorMichal Bloch <m.bloch@samsung.com>
Tue, 12 Apr 2022 18:07:20 +0000 (20:07 +0200)
committerMateusz Majewski <m.majewski2@samsung.com>
Thu, 28 Apr 2022 10:40:00 +0000 (12:40 +0200)
Change-Id: I1a474986796a82f721ddcd6550cce88453c2ee45
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/logger/logger.c
src/logger/reader_common.c
src/logger/reader_common.h
src/logger/reader_logger.c
src/logger/reader_pipe.c
src/logger/subreader_file.c
src/logger/subreader_metrics.c

index cefbf26..8b676bc 100644 (file)
@@ -493,7 +493,8 @@ static bool cond_service_reader_common(void *ptr, void *user_data)
                 * like we can do anything about it either */
        }
 
-       reader_flush(reader, now.mono, logger->buf_params.time);
+       // Ditto, can't do much about it
+       (void) reader_flush(reader, now.mono, logger->buf_params.time);
 
        return false;
 }
index 0afefb2..3ca97e4 100644 (file)
@@ -26,7 +26,7 @@ void subreader_free(void *_sub, void *userdata)
        free(sub->sub_userdata);
 }
 
-void subreader_apply_log(void *_sub, void *userdata)
+int subreader_apply_log(void *_sub, void *userdata)
 {
        struct subreader_common *const sub = (struct subreader_common *) _sub;
        assert(sub);
@@ -35,12 +35,12 @@ void subreader_apply_log(void *_sub, void *userdata)
        assert(due);
 
        if (!log_should_print_line(sub->filter, due))
-               return;
+               return 0;
 
-       sub->sub_apply_log(sub, due);
+       return sub->sub_apply_log(sub, due);
 }
 
-void subreader_flush(void *_sub, void *userdata)
+int subreader_flush(void *_sub, void *userdata)
 {
        struct subreader_common *const sub = (struct subreader_common *) _sub;
        assert(sub);
@@ -48,12 +48,12 @@ void subreader_flush(void *_sub, void *userdata)
 
        struct subreader_flush_args *const args = (struct subreader_flush_args *) userdata;
 
-       sub->sub_flush(sub->sub_userdata, args->ts, args->flush_time);
+       return sub->sub_flush(sub->sub_userdata, args->ts, args->flush_time);
 }
 
-void reader_flush(struct reader_common *reader, struct timespec now_mono, int flush)
+int reader_flush(struct reader_common *reader, struct timespec now_mono, int flush)
 {
-       list_foreach(reader->subs, &(struct subreader_flush_args) {
+       return list_foreach_ret(reader->subs, &(struct subreader_flush_args) {
                .ts = now_mono,
                .flush_time = flush,
        }, subreader_flush);
index 2c00199..7a4a455 100644 (file)
@@ -44,8 +44,8 @@ struct reader_common {
 };
 
 struct subreader_common {
-       void (*sub_apply_log)(const struct subreader_common *sub, const struct dlogutil_entry *due);
-       void (*sub_flush)(void *sub_userdata, struct timespec ts, int flush_time);
+       int (*sub_apply_log)(const struct subreader_common *sub, const struct dlogutil_entry *due);
+       int (*sub_flush)(void *sub_userdata, struct timespec ts, int flush_time);
        void (*sub_destroy)(void *sub_userdata);
        void *sub_userdata;
        struct log_filter *filter;
@@ -57,10 +57,10 @@ struct subreader_flush_args {
 };
 
 void reader_deinit_common(struct reader_common *reader);
-void reader_flush(struct reader_common *reader, struct timespec now_mono, int flush);
+int reader_flush(struct reader_common *reader, struct timespec now_mono, int flush);
 void reader_free(struct reader_common *reader);
 void reader_free_ptr(void *reader);
 
 void subreader_free(void *sub, void *userdata);
-void subreader_apply_log(void *sub, void *userdata);
-void subreader_flush(void *sub, void *userdata);
+int subreader_apply_log(void *sub, void *userdata);
+int subreader_flush(void *sub, void *userdata);
index 43320e0..3562f65 100644 (file)
@@ -75,7 +75,8 @@ static int service_reader_logger(struct reader_common *_reader, struct now_t tim
                        // TODO: Consider calling this in a more robust way (and not having pipe in the name)
                        fixup_pipe_msg(&entry, r - sizeof(*ale));
 
-                       list_foreach(reader->common.subs, &entry.header, subreader_apply_log);
+                       // Ignore intermittent write failures. Not a reason to remove the reader.
+                       (void) list_foreach_ret(reader->common.subs, &entry.header, subreader_apply_log);
                }
        }
 
index 8fed1f2..ca862bb 100644 (file)
@@ -133,10 +133,8 @@ int reader_print_out_single_log(struct reader_pipe *reader, const dlogutil_entry
        if (!log_should_print_line(reader->filter, dlogutil_entry))
                return 0;
 
-       if (reader->common.subs != NULL) {
-               list_foreach(reader->common.subs, (dlogutil_entry_s *) dlogutil_entry, subreader_apply_log);
-               return 0;
-       }
+       if (reader->common.subs != NULL)
+               return list_foreach_ret(reader->common.subs, (dlogutil_entry_s *) dlogutil_entry, subreader_apply_log);
 
        const char *tag = dlogutil_entry->msg + 1;
        if (!strlen(tag))
index 5042466..450943a 100644 (file)
@@ -1,7 +1,7 @@
 #include "subreader_file.h"
 #include "logger_internal.h"
 
-static void subreader_file_apply_log(const struct subreader_common *sub, const struct dlogutil_entry *due)
+static int subreader_file_apply_log(const struct subreader_common *sub, const struct dlogutil_entry *due)
 {
        assert(sub);
        assert(due);
@@ -12,6 +12,8 @@ static void subreader_file_apply_log(const struct subreader_common *sub, const s
        if (logfile_write_with_rotation(due, &srf->file, srf->sort_by)) {
                // ignore errors, can't do anything about them
        }
+
+       return 0;
 }
 
 static void subreader_file_free(void *userdata)
@@ -22,12 +24,13 @@ static void subreader_file_free(void *userdata)
        logfile_free(&srf->file);
 }
 
-static void subreader_file_flush(void *userdata, struct timespec ts, int flush_time)
+static int subreader_file_flush(void *userdata, struct timespec ts, int flush_time)
 {
        struct subreader_file *const srf = (struct subreader_file *) userdata;
        assert(srf);
 
        flush_logfile_timely(&srf->file, ts, flush_time);
+       return 0;
 }
 
 int reader_add_subreader_file(struct reader_common *reader, struct log_filter *filter, struct log_file *file, dlogutil_sorting_order_e sort_by)
index d9482ac..10cf22e 100644 (file)
@@ -1,7 +1,7 @@
 #include "subreader_metrics.h"
 #include "qos.h"
 
-static void subreader_metrics_apply_log(const struct subreader_common *sub, const struct dlogutil_entry *due)
+static int subreader_metrics_apply_log(const struct subreader_common *sub, const struct dlogutil_entry *due)
 {
        assert(sub);
        assert(due);
@@ -10,6 +10,8 @@ static void subreader_metrics_apply_log(const struct subreader_common *sub, cons
        assert(srm);
 
        qos_add_log(srm->qos, due);
+
+       return 0;
 }
 
 static void subreader_metrics_free(void *userdata)
@@ -17,9 +19,10 @@ static void subreader_metrics_free(void *userdata)
        // nothing to do; we're just a wrapper over a weak (shared) pointer
 }
 
-static void subreader_metrics_flush(void *userdata, struct timespec ts, int flush_time)
+static int subreader_metrics_flush(void *userdata, struct timespec ts, int flush_time)
 {
        // nothing to do either; no such concept as flushing metrics
+       return 0;
 }