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

View File

@ -230,6 +230,7 @@ struct lib_syslogstream_s
#ifdef CONFIG_SYSLOG_BUFFER
FAR struct iob_s *iob;
#endif
int last_ch;
};
/* LZF compressed stream pipeline */
@ -455,11 +456,7 @@ void lib_syslogstream_open(FAR struct lib_syslogstream_s *stream);
*
****************************************************************************/
#ifdef CONFIG_SYSLOG_BUFFER
void lib_syslogstream_close(FAR struct lib_syslogstream_s *stream);
#else
# define lib_syslogstream_close(s)
#endif
/****************************************************************************
* Name: lib_lzfoutstream

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
}