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 <yuanyongjian@xiaomi.com>
This commit is contained in:
yuanyongjian 2024-03-12 17:55:52 +08:00 committed by Xiang Xiao
parent 9e1750d22c
commit 6869a05368
1 changed files with 3 additions and 5 deletions

View File

@ -242,7 +242,6 @@ static void syslog_rpmsg_addbuf(FAR struct syslog_rpmsg_s *priv,
#if defined(CONFIG_ARCH_LOWPUTC) #if defined(CONFIG_ARCH_LOWPUTC)
up_nputs(buffer, len); up_nputs(buffer, len);
#endif #endif
priv->flush += len; priv->flush += len;
return; return;
} }
@ -389,13 +388,12 @@ int syslog_rpmsg_flush(FAR syslog_channel_t *channel)
priv->flush = priv->tail; 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) #if defined(CONFIG_ARCH_LOWPUTC)
up_nputs(&priv->buffer[SYSLOG_RPMSG_FLUSHOFF(priv)], len); up_putc(priv->buffer[SYSLOG_RPMSG_FLUSHOFF(priv)]);
#endif #endif
priv->flush += len; priv->flush++;
} }
leave_critical_section(flags); leave_critical_section(flags);