This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 8f05661a53 syslog: A trailing newline is added if none is present.
8f05661a53 is described below

commit 8f05661a530ec6884f72318c4a43b8e26c9bfe50
Author: dongjiuzhu1 <[email protected]>
AuthorDate: Thu Dec 29 21:56:27 2022 +0800

    syslog: A trailing newline is added if none is present.
    
    refs:
    https://www.manpagez.com/man/3/syslog/
    
    Signed-off-by: dongjiuzhu1 <[email protected]>
---
 include/nuttx/streams.h             |  5 +----
 libs/libc/stream/lib_syslogstream.c | 20 +++++++++++++-------
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/include/nuttx/streams.h b/include/nuttx/streams.h
index bb7ee561c8..979eedbeab 100644
--- a/include/nuttx/streams.h
+++ b/include/nuttx/streams.h
@@ -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
diff --git a/libs/libc/stream/lib_syslogstream.c 
b/libs/libc/stream/lib_syslogstream.c
index 0ee5f0a9f5..f981d7afbc 100644
--- a/libs/libc/stream/lib_syslogstream.c
+++ b/libs/libc/stream/lib_syslogstream.c
@@ -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
+}

Reply via email to