From 6869a053683c8d6e72c737239a5f7df94ed9210a Mon Sep 17 00:00:00 2001 From: yuanyongjian Date: Tue, 12 Mar 2024 17:55:52 +0800 Subject: [PATCH] syslog/syslog_rpmsg.c: the last log may be lost when it crashes At line 236, we may set the null terminate to the priv->buffer, when flushing the priv->buffer, we should use up_putc() instead up_nputs() to ensure all the data has been output, because up_nputs() will check the null terminate but up_putc() not. Signed-off-by: yuanyongjian --- drivers/syslog/syslog_rpmsg.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/syslog/syslog_rpmsg.c b/drivers/syslog/syslog_rpmsg.c index 63b58a27b9..d7b7ceeba9 100644 --- a/drivers/syslog/syslog_rpmsg.c +++ b/drivers/syslog/syslog_rpmsg.c @@ -242,7 +242,6 @@ static void syslog_rpmsg_addbuf(FAR struct syslog_rpmsg_s *priv, #if defined(CONFIG_ARCH_LOWPUTC) up_nputs(buffer, len); #endif - priv->flush += len; return; } @@ -389,13 +388,12 @@ int syslog_rpmsg_flush(FAR syslog_channel_t *channel) priv->flush = priv->tail; } - if (priv->flush < priv->head) + while (priv->flush < priv->head) { - size_t len = priv->head - priv->flush; #if defined(CONFIG_ARCH_LOWPUTC) - up_nputs(&priv->buffer[SYSLOG_RPMSG_FLUSHOFF(priv)], len); + up_putc(priv->buffer[SYSLOG_RPMSG_FLUSHOFF(priv)]); #endif - priv->flush += len; + priv->flush++; } leave_critical_section(flags);