syslog: A trailing newline is added if none is present.

refs:
https://www.manpagez.com/man/3/syslog/

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1
2022-12-29 21:56:27 +08:00
committed by Xiang Xiao
parent d549333511
commit 8f05661a53
2 changed files with 14 additions and 11 deletions
+13 -7
View File
@@ -111,16 +111,17 @@ static void syslogstream_addchar(FAR struct lib_syslogstream_s *stream,
static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch)
{
FAR struct lib_syslogstream_s *stream =
(FAR struct lib_syslogstream_s *)this;
DEBUGASSERT(stream != NULL);
stream->last_ch = ch;
/* Discard carriage returns */
if (ch != '\r')
{
#ifdef CONFIG_SYSLOG_BUFFER
FAR struct lib_syslogstream_s *stream =
(FAR struct lib_syslogstream_s *)this;
DEBUGASSERT(stream != NULL);
/* Do we have an IO buffer? */
if (stream->iob != NULL)
@@ -213,11 +214,16 @@ void lib_syslogstream_open(FAR struct lib_syslogstream_s *stream)
*
****************************************************************************/
#ifdef CONFIG_SYSLOG_BUFFER
void lib_syslogstream_close(FAR struct lib_syslogstream_s *stream)
{
DEBUGASSERT(stream != NULL);
if (stream->last_ch != '\n')
{
syslogstream_putc(&stream->public, '\n');
}
#ifdef CONFIG_SYSLOG_BUFFER
/* Verify that there is an IOB attached (there should be) */
if (stream->iob != NULL)
@@ -231,5 +237,5 @@ void lib_syslogstream_close(FAR struct lib_syslogstream_s *stream)
iob_free(stream->iob);
stream->iob = NULL;
}
}
#endif
}