This is an automated email from the ASF dual-hosted git repository. vipulrahane pushed a commit to branch vipul/log_register in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 710275443611b9e16e6f40fa51ce5004700b8c5b Author: Vipul Rahane <[email protected]> AuthorDate: Mon Mar 10 20:06:05 2025 -0700 sys/log: Log registeration fix --- sys/log/full/include/log/log.h | 1 + sys/log/full/src/log.c | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/sys/log/full/include/log/log.h b/sys/log/full/include/log/log.h index d04a191eb..5fb2587c2 100644 --- a/sys/log/full/include/log/log.h +++ b/sys/log/full/include/log/log.h @@ -191,6 +191,7 @@ struct log_entry_hdr { STATS_SECT_START(logs) STATS_SECT_ENTRY(writes) STATS_SECT_ENTRY(drops) + STATS_SECT_ENTRY(regerr) STATS_SECT_ENTRY(errs) STATS_SECT_ENTRY(lost) STATS_SECT_ENTRY(too_long) diff --git a/sys/log/full/src/log.c b/sys/log/full/src/log.c index 978924e6b..3afe8c163 100644 --- a/sys/log/full/src/log.c +++ b/sys/log/full/src/log.c @@ -78,6 +78,7 @@ struct shell_cmd g_shell_storage_cmd = { STATS_NAME_START(logs) STATS_NAME(logs, writes) STATS_NAME(logs, drops) + STATS_NAME(logs, regerr) STATS_NAME(logs, errs) STATS_NAME(logs, lost) STATS_NAME(logs, too_long) @@ -382,7 +383,6 @@ log_register(const char *name, struct log *log, const struct log_handler *lh, #endif if (!log_registered(log)) { - STAILQ_INSERT_TAIL(&g_log_list, log, l_next); #if MYNEWT_VAL(LOG_STATS) stats_init(STATS_HDR(log->l_stats), STATS_SIZE_INIT_PARMS(log->l_stats, STATS_SIZE_32), @@ -391,15 +391,6 @@ log_register(const char *name, struct log *log, const struct log_handler *lh, #endif } - /* Call registered handler now - log structure is set and put on list */ - if (log->l_log->log_registered) { - rc = log->l_log->log_registered(log); - if (rc) { - STAILQ_REMOVE(&g_log_list, log, log, l_next); - return rc; - } - } - /* If this is a persisted log, read the index from its most recent entry. * We need to ensure the index of all subseqently written entries is * monotonically increasing. @@ -418,6 +409,21 @@ log_register(const char *name, struct log *log, const struct log_handler *lh, } #endif OS_EXIT_CRITICAL(sr); + } else { + LOG_STATS_INC(log, regerr); + } + } + + if (!log_registered(log)) { + STAILQ_INSERT_TAIL(&g_log_list, log, l_next); + } + + /* Call registered handler now - log structure is set and put on list */ + if (log->l_log->log_registered) { + rc = log->l_log->log_registered(log); + if (rc) { + STAILQ_REMOVE(&g_log_list, log, log, l_next); + return rc; } }
