You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/11/25 12:53:14 UTC

[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7674: drivers/syslog:support stream as syslog backend.

xiaoxiang781216 commented on code in PR #7674:
URL: https://github.com/apache/nuttx/pull/7674#discussion_r1032421458


##########
include/nuttx/syslog/syslog.h:
##########
@@ -243,6 +244,55 @@ int syslog_initialize(void);
 FAR struct syslog_channel_s *syslog_file_channel(FAR const char *devpath);
 #endif
 
+/****************************************************************************
+ * Name: syslog_stream_init
+ *
+ * Description:
+ *   Initialize to use the device stream as the SYSLOG sink.
+ *
+ *   On power up, the SYSLOG facility is non-existent or limited to very
+ *   low-level output.  This function may be called later in the
+ *   initialization sequence after full driver support has been initialized.
+ *   (via syslog_initialize())  It installs the configured SYSLOG drivers
+ *   and enables full SYSLOGing capability.
+ *
+ * Input Parameters:
+ *   strm - The stream device to be used.
+ *
+ * Returned Value:
+ *   Returns a newly created SYSLOG channel, or NULL in case of any failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SYSLOG_STREAM
+FAR struct syslog_channel_s *syslog_stream_init(FAR struct lib_outstream_s *

Review Comment:
   ```suggestion
   FAR struct syslog_channel_s *
   syslog_stream_init(FAR struct lib_outstream_s *stream);
   ```



##########
drivers/syslog/syslog_stream.c:
##########
@@ -0,0 +1,393 @@
+/****************************************************************************
+ * drivers/syslog/syslog_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sched.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include <nuttx/syslog/syslog.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>

Review Comment:
   remove all unused inclusion



##########
drivers/syslog/syslog_stream.c:
##########
@@ -0,0 +1,393 @@
+/****************************************************************************
+ * drivers/syslog/syslog_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sched.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include <nuttx/syslog/syslog.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/streams.h>
+
+#include "syslog.h"
+
+#ifdef CONFIG_SYSLOG_STREAM
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* This structure contains all SYSLOGing state information */
+
+struct syslog_stream_s
+{
+  struct syslog_channel_s     channel;
+  rmutex_t                    sl_lock; /* Enforces mutually exclusive access */

Review Comment:
   let's use enter_critical_section to allow the interrupt context output log



##########
drivers/syslog/syslog_stream.c:
##########
@@ -0,0 +1,393 @@
+/****************************************************************************
+ * drivers/syslog/syslog_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sched.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include <nuttx/syslog/syslog.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/streams.h>
+
+#include "syslog.h"
+
+#ifdef CONFIG_SYSLOG_STREAM
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* This structure contains all SYSLOGing state information */
+
+struct syslog_stream_s
+{
+  struct syslog_channel_s     channel;
+  rmutex_t                    sl_lock; /* Enforces mutually exclusive access */
+  FAR struct lib_outstream_s *stream;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static ssize_t syslog_stream_write(FAR struct syslog_channel_s *channel,
+                                   FAR const char *buffer, size_t buflen);
+static int syslog_stream_putc(FAR struct syslog_channel_s *channel, int ch);
+static int syslog_stream_force(FAR struct syslog_channel_s *channel, int ch);
+static int syslog_stream_flush(FAR struct syslog_channel_s *channel);
+void syslog_stream_uninit(FAR struct syslog_channel_s *channel);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct syslog_channel_ops_s g_syslog_stream_ops =
+{
+  syslog_stream_putc,
+  syslog_stream_force,
+  syslog_stream_flush,
+  syslog_stream_write,
+  syslog_stream_uninit
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: syslog_stream_lock
+ ****************************************************************************/
+
+static int syslog_stream_lock(FAR struct syslog_stream_s *chan)
+{
+  if (!up_interrupt_context() && !sched_idletask())
+    {
+      /* Does this thread already hold the lock?  That could happen if
+       * we were called recursively, i.e., if the logic kicked off
+       * were to generate more debug output.  Return an
+       * error in that case.
+       */
+
+      if (nxrmutex_is_hold(&chan->sl_lock))
+        {
+          /* Return an error (instead of deadlocking) */
+
+          return -EWOULDBLOCK;
+        }
+
+      /* Either the lock is available or is currently held by another
+       * thread.  Wait for it to become available.
+       */
+
+      return nxrmutex_lock(&chan->sl_lock);
+    }
+  else
+    {
+      return OK;
+    }
+}
+
+/****************************************************************************
+ * Name: syslog_stream_unlock
+ ****************************************************************************/
+
+static void syslog_stream_unlock(FAR struct syslog_stream_s *chan)
+{
+  if (!up_interrupt_context() && !sched_idletask())
+    {
+      nxrmutex_unlock(&chan->sl_lock);
+    }
+}
+
+/****************************************************************************
+ * Name: syslog_stream_write
+ *
+ * Description:
+ *   This is the low-level, multiple byte, system logging interface provided
+ *   for the driver interface.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *   buffer     - The buffer containing the data to be output.
+ *   buflen     - The number of bytes in the buffer.
+ *
+ * Returned Value:
+ *   On success, the number of characters written is returned. A negated
+ *   errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static ssize_t syslog_stream_write(FAR struct syslog_channel_s *channel,
+                                   FAR const char *buffer, size_t buflen)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+  FAR struct lib_outstream_s *stream =
+    (FAR struct lib_outstream_s *)chan->stream;
+  ssize_t nwritten;
+  int ret;
+
+  ret = syslog_stream_lock(chan);
+  if (ret < 0)
+    {
+      /* We probably already hold the mutex and were probably
+       * re-entered by the logic kicked off by file_write().
+       * We might also have been interrupted by a signal.  Either
+       * way, we are outta here.
+       */
+
+      return ret;
+    }
+
+  nwritten = stream->puts(stream, buffer, buflen);
+  syslog_stream_unlock(chan);
+
+  return nwritten;
+}
+
+/****************************************************************************
+ * Name: syslog_stream_putc
+ *
+ * Description:
+ *   This is the low-level, single character, system logging interface
+ *   provided for the driver interface.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *   ch         - The character to add to the SYSLOG (must be positive).
+ *
+ * Returned Value:
+ *   On success, the character is echoed back to the caller. A negated errno
+ *   value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int syslog_stream_putc(FAR struct syslog_channel_s *channel,
+                                   int ch)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+  FAR struct lib_outstream_s *stream =
+    (FAR struct lib_outstream_s *)chan->stream;
+  ssize_t nbytes;
+  uint8_t uch;
+  int ret;
+
+  ret = syslog_stream_lock(chan);
+  if (ret < 0)
+    {
+      /* We probably already hold the lock and were probably
+       * re-entered by the logic kicked off by file_write().
+       * We might also have been interrupted by a signal.  Either
+       * way, we are outta here.
+       */
+
+      return ret;
+    }
+
+  uch = (uint8_t)ch;
+  nbytes = stream->puts(stream, &uch, 1);
+  syslog_stream_unlock(chan);
+
+  /* Check if the write was successful.  If not, nbytes will be
+   * a negated errno value.
+   */
+
+  if (nbytes < 0)
+    {
+      return (int)nbytes;
+    }
+
+  return ch;
+}
+
+/****************************************************************************
+ * Name: syslog_stream_force
+ *
+ * Description:
+ *   Force output in interrupt context.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *   ch         - The character to add to the SYSLOG (must be positive).
+ *
+ * Returned Value:
+ *   On success, the character is echoed back to the caller.  A negated
+ *   errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int syslog_stream_force(FAR struct syslog_channel_s *channel, int ch)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+  FAR struct lib_outstream_s *stream =
+    (FAR struct lib_outstream_s *)chan->stream;
+  ssize_t nbytes;
+  uint8_t uch;
+
+  uch = (uint8_t)ch;
+  nbytes = stream->puts(stream, &uch, 1);
+
+  /* Check if the write was successful.  If not, nbytes will be
+   * a negated errno value.
+   */
+
+  if (nbytes < 0)
+    {
+      return (int)nbytes;
+    }
+
+  return ch;
+}
+
+/****************************************************************************
+ * Name: syslog_stream_flush
+ *
+ * Description:
+ *   Flush any buffer data in the file system to media.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int syslog_stream_flush(FAR struct syslog_channel_s *channel)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+  FAR struct lib_outstream_s *stream =
+    (FAR struct lib_outstream_s *)chan->stream;
+
+  stream->flush(stream);
+
+  return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: syslog_stream_uninit
+ *
+ * Description:
+ *   Disable the channel in preparation to use a different
+ *   SYSLOG device.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
+ *
+ * Assumptions:
+ *   The caller has already switched the SYSLOG source to some safe channel
+ *   (the default channel).
+ *
+ ****************************************************************************/
+
+void syslog_stream_uninit(FAR struct syslog_channel_s *channel)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+
+  /* Uninitializing a SYSLOG device should not take place within
+   * interrupt context.
+   */
+
+  if (up_interrupt_context() || sched_idletask())
+    {
+      DEBUGASSERT(!up_interrupt_context() && !sched_idletask());
+      return;
+    }
+
+  /* Attempt to flush any buffered data. */
+
+  sched_lock();
+  syslog_stream_flush(channel);
+  nxrmutex_destroy(&chan->sl_lock);
+
+  /* Free the channel structure */
+
+  kmm_free(chan);
+  sched_unlock();
+}
+
+/****************************************************************************
+ * Name: syslog_stream_init
+ *
+ * Description:
+ *   Initialize to use the device stream as the SYSLOG sink.
+ *
+ *   On power up, the SYSLOG facility is non-existent or limited to very
+ *   low-level output.  This function may be called later in the
+ *   initialization sequence after full driver support has been initialized.
+ *   (via syslog_initialize())  It installs the configured SYSLOG drivers
+ *   and enables full SYSLOGing capability.
+ *
+ * Input Parameters:
+ *   strm - The stream device to be used.

Review Comment:
   ```suggestion
    *   stream - The stream device to be used.
   ```



##########
drivers/syslog/syslog_stream.c:
##########
@@ -0,0 +1,393 @@
+/****************************************************************************
+ * drivers/syslog/syslog_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sched.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include <nuttx/syslog/syslog.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/streams.h>
+
+#include "syslog.h"
+
+#ifdef CONFIG_SYSLOG_STREAM
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* This structure contains all SYSLOGing state information */
+
+struct syslog_stream_s
+{
+  struct syslog_channel_s     channel;
+  rmutex_t                    sl_lock; /* Enforces mutually exclusive access */
+  FAR struct lib_outstream_s *stream;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static ssize_t syslog_stream_write(FAR struct syslog_channel_s *channel,
+                                   FAR const char *buffer, size_t buflen);
+static int syslog_stream_putc(FAR struct syslog_channel_s *channel, int ch);
+static int syslog_stream_force(FAR struct syslog_channel_s *channel, int ch);
+static int syslog_stream_flush(FAR struct syslog_channel_s *channel);
+void syslog_stream_uninit(FAR struct syslog_channel_s *channel);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct syslog_channel_ops_s g_syslog_stream_ops =
+{
+  syslog_stream_putc,
+  syslog_stream_force,
+  syslog_stream_flush,
+  syslog_stream_write,
+  syslog_stream_uninit
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: syslog_stream_lock
+ ****************************************************************************/
+
+static int syslog_stream_lock(FAR struct syslog_stream_s *chan)
+{
+  if (!up_interrupt_context() && !sched_idletask())
+    {
+      /* Does this thread already hold the lock?  That could happen if
+       * we were called recursively, i.e., if the logic kicked off
+       * were to generate more debug output.  Return an
+       * error in that case.
+       */
+
+      if (nxrmutex_is_hold(&chan->sl_lock))
+        {
+          /* Return an error (instead of deadlocking) */
+
+          return -EWOULDBLOCK;
+        }
+
+      /* Either the lock is available or is currently held by another
+       * thread.  Wait for it to become available.
+       */
+
+      return nxrmutex_lock(&chan->sl_lock);
+    }
+  else
+    {
+      return OK;
+    }
+}
+
+/****************************************************************************
+ * Name: syslog_stream_unlock
+ ****************************************************************************/
+
+static void syslog_stream_unlock(FAR struct syslog_stream_s *chan)
+{
+  if (!up_interrupt_context() && !sched_idletask())
+    {
+      nxrmutex_unlock(&chan->sl_lock);
+    }
+}
+
+/****************************************************************************
+ * Name: syslog_stream_write
+ *
+ * Description:
+ *   This is the low-level, multiple byte, system logging interface provided
+ *   for the driver interface.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *   buffer     - The buffer containing the data to be output.
+ *   buflen     - The number of bytes in the buffer.
+ *
+ * Returned Value:
+ *   On success, the number of characters written is returned. A negated
+ *   errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static ssize_t syslog_stream_write(FAR struct syslog_channel_s *channel,
+                                   FAR const char *buffer, size_t buflen)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+  FAR struct lib_outstream_s *stream =
+    (FAR struct lib_outstream_s *)chan->stream;
+  ssize_t nwritten;
+  int ret;
+
+  ret = syslog_stream_lock(chan);
+  if (ret < 0)
+    {
+      /* We probably already hold the mutex and were probably
+       * re-entered by the logic kicked off by file_write().
+       * We might also have been interrupted by a signal.  Either
+       * way, we are outta here.
+       */
+
+      return ret;
+    }
+
+  nwritten = stream->puts(stream, buffer, buflen);
+  syslog_stream_unlock(chan);
+
+  return nwritten;
+}
+
+/****************************************************************************
+ * Name: syslog_stream_putc
+ *
+ * Description:
+ *   This is the low-level, single character, system logging interface
+ *   provided for the driver interface.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *   ch         - The character to add to the SYSLOG (must be positive).
+ *
+ * Returned Value:
+ *   On success, the character is echoed back to the caller. A negated errno
+ *   value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int syslog_stream_putc(FAR struct syslog_channel_s *channel,
+                                   int ch)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+  FAR struct lib_outstream_s *stream =
+    (FAR struct lib_outstream_s *)chan->stream;
+  ssize_t nbytes;
+  uint8_t uch;
+  int ret;
+
+  ret = syslog_stream_lock(chan);
+  if (ret < 0)
+    {
+      /* We probably already hold the lock and were probably
+       * re-entered by the logic kicked off by file_write().
+       * We might also have been interrupted by a signal.  Either
+       * way, we are outta here.
+       */
+
+      return ret;
+    }
+
+  uch = (uint8_t)ch;
+  nbytes = stream->puts(stream, &uch, 1);
+  syslog_stream_unlock(chan);
+
+  /* Check if the write was successful.  If not, nbytes will be
+   * a negated errno value.
+   */
+
+  if (nbytes < 0)
+    {
+      return (int)nbytes;
+    }
+
+  return ch;
+}
+
+/****************************************************************************
+ * Name: syslog_stream_force
+ *
+ * Description:
+ *   Force output in interrupt context.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *   ch         - The character to add to the SYSLOG (must be positive).
+ *
+ * Returned Value:
+ *   On success, the character is echoed back to the caller.  A negated
+ *   errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int syslog_stream_force(FAR struct syslog_channel_s *channel, int ch)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+  FAR struct lib_outstream_s *stream =
+    (FAR struct lib_outstream_s *)chan->stream;
+  ssize_t nbytes;
+  uint8_t uch;
+
+  uch = (uint8_t)ch;
+  nbytes = stream->puts(stream, &uch, 1);
+
+  /* Check if the write was successful.  If not, nbytes will be
+   * a negated errno value.
+   */
+
+  if (nbytes < 0)
+    {
+      return (int)nbytes;
+    }
+
+  return ch;
+}
+
+/****************************************************************************
+ * Name: syslog_stream_flush
+ *
+ * Description:
+ *   Flush any buffer data in the file system to media.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int syslog_stream_flush(FAR struct syslog_channel_s *channel)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+  FAR struct lib_outstream_s *stream =
+    (FAR struct lib_outstream_s *)chan->stream;
+
+  stream->flush(stream);
+
+  return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: syslog_stream_uninit
+ *
+ * Description:
+ *   Disable the channel in preparation to use a different
+ *   SYSLOG device.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
+ *
+ * Assumptions:
+ *   The caller has already switched the SYSLOG source to some safe channel
+ *   (the default channel).
+ *
+ ****************************************************************************/
+
+void syslog_stream_uninit(FAR struct syslog_channel_s *channel)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+
+  /* Uninitializing a SYSLOG device should not take place within
+   * interrupt context.
+   */
+
+  if (up_interrupt_context() || sched_idletask())
+    {
+      DEBUGASSERT(!up_interrupt_context() && !sched_idletask());
+      return;
+    }
+
+  /* Attempt to flush any buffered data. */
+
+  sched_lock();
+  syslog_stream_flush(channel);
+  nxrmutex_destroy(&chan->sl_lock);
+
+  /* Free the channel structure */
+
+  kmm_free(chan);
+  sched_unlock();
+}
+
+/****************************************************************************
+ * Name: syslog_stream_init
+ *
+ * Description:
+ *   Initialize to use the device stream as the SYSLOG sink.
+ *
+ *   On power up, the SYSLOG facility is non-existent or limited to very
+ *   low-level output.  This function may be called later in the
+ *   initialization sequence after full driver support has been initialized.
+ *   (via syslog_initialize())  It installs the configured SYSLOG drivers
+ *   and enables full SYSLOGing capability.
+ *
+ * Input Parameters:
+ *   strm - The stream device to be used.
+ *
+ * Returned Value:
+ *   Returns a newly created SYSLOG channel, or NULL in case of any failure.
+ *
+ ****************************************************************************/
+
+FAR struct syslog_channel_s *syslog_stream_init(FAR struct lib_outstream_s *

Review Comment:
   ```suggestion
   FAR struct syslog_channel_s *
   syslog_stream_init(FAR struct lib_outstream_s *stream)
   ```



##########
drivers/syslog/syslog_stream.c:
##########
@@ -0,0 +1,393 @@
+/****************************************************************************
+ * drivers/syslog/syslog_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sched.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include <nuttx/syslog/syslog.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/streams.h>
+
+#include "syslog.h"
+
+#ifdef CONFIG_SYSLOG_STREAM
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* This structure contains all SYSLOGing state information */
+
+struct syslog_stream_s
+{
+  struct syslog_channel_s     channel;
+  rmutex_t                    sl_lock; /* Enforces mutually exclusive access */
+  FAR struct lib_outstream_s *stream;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static ssize_t syslog_stream_write(FAR struct syslog_channel_s *channel,
+                                   FAR const char *buffer, size_t buflen);
+static int syslog_stream_putc(FAR struct syslog_channel_s *channel, int ch);
+static int syslog_stream_force(FAR struct syslog_channel_s *channel, int ch);
+static int syslog_stream_flush(FAR struct syslog_channel_s *channel);
+void syslog_stream_uninit(FAR struct syslog_channel_s *channel);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct syslog_channel_ops_s g_syslog_stream_ops =
+{
+  syslog_stream_putc,
+  syslog_stream_force,
+  syslog_stream_flush,
+  syslog_stream_write,
+  syslog_stream_uninit
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: syslog_stream_lock
+ ****************************************************************************/
+
+static int syslog_stream_lock(FAR struct syslog_stream_s *chan)

Review Comment:
   remove call enter_critical_section directly



##########
drivers/syslog/syslog_stream.c:
##########
@@ -0,0 +1,393 @@
+/****************************************************************************
+ * drivers/syslog/syslog_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sched.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include <nuttx/syslog/syslog.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/streams.h>
+
+#include "syslog.h"
+
+#ifdef CONFIG_SYSLOG_STREAM
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* This structure contains all SYSLOGing state information */
+
+struct syslog_stream_s
+{
+  struct syslog_channel_s     channel;
+  rmutex_t                    sl_lock; /* Enforces mutually exclusive access */
+  FAR struct lib_outstream_s *stream;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static ssize_t syslog_stream_write(FAR struct syslog_channel_s *channel,
+                                   FAR const char *buffer, size_t buflen);
+static int syslog_stream_putc(FAR struct syslog_channel_s *channel, int ch);
+static int syslog_stream_force(FAR struct syslog_channel_s *channel, int ch);
+static int syslog_stream_flush(FAR struct syslog_channel_s *channel);
+void syslog_stream_uninit(FAR struct syslog_channel_s *channel);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct syslog_channel_ops_s g_syslog_stream_ops =
+{
+  syslog_stream_putc,
+  syslog_stream_force,
+  syslog_stream_flush,
+  syslog_stream_write,
+  syslog_stream_uninit
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: syslog_stream_lock
+ ****************************************************************************/
+
+static int syslog_stream_lock(FAR struct syslog_stream_s *chan)
+{
+  if (!up_interrupt_context() && !sched_idletask())
+    {
+      /* Does this thread already hold the lock?  That could happen if
+       * we were called recursively, i.e., if the logic kicked off
+       * were to generate more debug output.  Return an
+       * error in that case.
+       */
+
+      if (nxrmutex_is_hold(&chan->sl_lock))
+        {
+          /* Return an error (instead of deadlocking) */
+
+          return -EWOULDBLOCK;
+        }
+
+      /* Either the lock is available or is currently held by another
+       * thread.  Wait for it to become available.
+       */
+
+      return nxrmutex_lock(&chan->sl_lock);
+    }
+  else
+    {
+      return OK;
+    }
+}
+
+/****************************************************************************
+ * Name: syslog_stream_unlock
+ ****************************************************************************/
+
+static void syslog_stream_unlock(FAR struct syslog_stream_s *chan)

Review Comment:
   remove call leave_critical_section directly



##########
drivers/syslog/syslog_stream.c:
##########
@@ -0,0 +1,393 @@
+/****************************************************************************
+ * drivers/syslog/syslog_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sched.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include <nuttx/syslog/syslog.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/streams.h>
+
+#include "syslog.h"
+
+#ifdef CONFIG_SYSLOG_STREAM
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* This structure contains all SYSLOGing state information */
+
+struct syslog_stream_s
+{
+  struct syslog_channel_s     channel;
+  rmutex_t                    sl_lock; /* Enforces mutually exclusive access */
+  FAR struct lib_outstream_s *stream;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static ssize_t syslog_stream_write(FAR struct syslog_channel_s *channel,
+                                   FAR const char *buffer, size_t buflen);
+static int syslog_stream_putc(FAR struct syslog_channel_s *channel, int ch);
+static int syslog_stream_force(FAR struct syslog_channel_s *channel, int ch);
+static int syslog_stream_flush(FAR struct syslog_channel_s *channel);
+void syslog_stream_uninit(FAR struct syslog_channel_s *channel);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct syslog_channel_ops_s g_syslog_stream_ops =
+{
+  syslog_stream_putc,
+  syslog_stream_force,
+  syslog_stream_flush,
+  syslog_stream_write,
+  syslog_stream_uninit
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: syslog_stream_lock
+ ****************************************************************************/
+
+static int syslog_stream_lock(FAR struct syslog_stream_s *chan)
+{
+  if (!up_interrupt_context() && !sched_idletask())
+    {
+      /* Does this thread already hold the lock?  That could happen if
+       * we were called recursively, i.e., if the logic kicked off
+       * were to generate more debug output.  Return an
+       * error in that case.
+       */
+
+      if (nxrmutex_is_hold(&chan->sl_lock))
+        {
+          /* Return an error (instead of deadlocking) */
+
+          return -EWOULDBLOCK;
+        }
+
+      /* Either the lock is available or is currently held by another
+       * thread.  Wait for it to become available.
+       */
+
+      return nxrmutex_lock(&chan->sl_lock);
+    }
+  else
+    {
+      return OK;
+    }
+}
+
+/****************************************************************************
+ * Name: syslog_stream_unlock
+ ****************************************************************************/
+
+static void syslog_stream_unlock(FAR struct syslog_stream_s *chan)
+{
+  if (!up_interrupt_context() && !sched_idletask())
+    {
+      nxrmutex_unlock(&chan->sl_lock);
+    }
+}
+
+/****************************************************************************
+ * Name: syslog_stream_write
+ *
+ * Description:
+ *   This is the low-level, multiple byte, system logging interface provided
+ *   for the driver interface.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *   buffer     - The buffer containing the data to be output.
+ *   buflen     - The number of bytes in the buffer.
+ *
+ * Returned Value:
+ *   On success, the number of characters written is returned. A negated
+ *   errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static ssize_t syslog_stream_write(FAR struct syslog_channel_s *channel,
+                                   FAR const char *buffer, size_t buflen)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+  FAR struct lib_outstream_s *stream =
+    (FAR struct lib_outstream_s *)chan->stream;
+  ssize_t nwritten;
+  int ret;
+
+  ret = syslog_stream_lock(chan);
+  if (ret < 0)
+    {
+      /* We probably already hold the mutex and were probably
+       * re-entered by the logic kicked off by file_write().
+       * We might also have been interrupted by a signal.  Either
+       * way, we are outta here.
+       */
+
+      return ret;
+    }
+
+  nwritten = stream->puts(stream, buffer, buflen);
+  syslog_stream_unlock(chan);
+
+  return nwritten;
+}
+
+/****************************************************************************
+ * Name: syslog_stream_putc
+ *
+ * Description:
+ *   This is the low-level, single character, system logging interface
+ *   provided for the driver interface.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *   ch         - The character to add to the SYSLOG (must be positive).
+ *
+ * Returned Value:
+ *   On success, the character is echoed back to the caller. A negated errno
+ *   value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int syslog_stream_putc(FAR struct syslog_channel_s *channel,
+                                   int ch)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+  FAR struct lib_outstream_s *stream =
+    (FAR struct lib_outstream_s *)chan->stream;
+  ssize_t nbytes;
+  uint8_t uch;
+  int ret;
+
+  ret = syslog_stream_lock(chan);
+  if (ret < 0)
+    {
+      /* We probably already hold the lock and were probably
+       * re-entered by the logic kicked off by file_write().
+       * We might also have been interrupted by a signal.  Either
+       * way, we are outta here.
+       */
+
+      return ret;
+    }
+
+  uch = (uint8_t)ch;
+  nbytes = stream->puts(stream, &uch, 1);
+  syslog_stream_unlock(chan);
+
+  /* Check if the write was successful.  If not, nbytes will be
+   * a negated errno value.
+   */
+
+  if (nbytes < 0)
+    {
+      return (int)nbytes;
+    }
+
+  return ch;
+}
+
+/****************************************************************************
+ * Name: syslog_stream_force
+ *
+ * Description:
+ *   Force output in interrupt context.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *   ch         - The character to add to the SYSLOG (must be positive).
+ *
+ * Returned Value:
+ *   On success, the character is echoed back to the caller.  A negated
+ *   errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int syslog_stream_force(FAR struct syslog_channel_s *channel, int ch)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+  FAR struct lib_outstream_s *stream =
+    (FAR struct lib_outstream_s *)chan->stream;
+  ssize_t nbytes;
+  uint8_t uch;
+
+  uch = (uint8_t)ch;
+  nbytes = stream->puts(stream, &uch, 1);
+
+  /* Check if the write was successful.  If not, nbytes will be
+   * a negated errno value.
+   */
+
+  if (nbytes < 0)
+    {
+      return (int)nbytes;
+    }
+
+  return ch;
+}
+
+/****************************************************************************
+ * Name: syslog_stream_flush
+ *
+ * Description:
+ *   Flush any buffer data in the file system to media.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int syslog_stream_flush(FAR struct syslog_channel_s *channel)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+  FAR struct lib_outstream_s *stream =
+    (FAR struct lib_outstream_s *)chan->stream;
+
+  stream->flush(stream);

Review Comment:
   need lock too



##########
drivers/syslog/syslog_stream.c:
##########
@@ -0,0 +1,393 @@
+/****************************************************************************
+ * drivers/syslog/syslog_stream.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sched.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include <nuttx/syslog/syslog.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/streams.h>
+
+#include "syslog.h"
+
+#ifdef CONFIG_SYSLOG_STREAM
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* This structure contains all SYSLOGing state information */
+
+struct syslog_stream_s
+{
+  struct syslog_channel_s     channel;
+  rmutex_t                    sl_lock; /* Enforces mutually exclusive access */
+  FAR struct lib_outstream_s *stream;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static ssize_t syslog_stream_write(FAR struct syslog_channel_s *channel,
+                                   FAR const char *buffer, size_t buflen);
+static int syslog_stream_putc(FAR struct syslog_channel_s *channel, int ch);
+static int syslog_stream_force(FAR struct syslog_channel_s *channel, int ch);
+static int syslog_stream_flush(FAR struct syslog_channel_s *channel);
+void syslog_stream_uninit(FAR struct syslog_channel_s *channel);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct syslog_channel_ops_s g_syslog_stream_ops =
+{
+  syslog_stream_putc,
+  syslog_stream_force,
+  syslog_stream_flush,
+  syslog_stream_write,
+  syslog_stream_uninit
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: syslog_stream_lock
+ ****************************************************************************/
+
+static int syslog_stream_lock(FAR struct syslog_stream_s *chan)
+{
+  if (!up_interrupt_context() && !sched_idletask())
+    {
+      /* Does this thread already hold the lock?  That could happen if
+       * we were called recursively, i.e., if the logic kicked off
+       * were to generate more debug output.  Return an
+       * error in that case.
+       */
+
+      if (nxrmutex_is_hold(&chan->sl_lock))
+        {
+          /* Return an error (instead of deadlocking) */
+
+          return -EWOULDBLOCK;
+        }
+
+      /* Either the lock is available or is currently held by another
+       * thread.  Wait for it to become available.
+       */
+
+      return nxrmutex_lock(&chan->sl_lock);
+    }
+  else
+    {
+      return OK;
+    }
+}
+
+/****************************************************************************
+ * Name: syslog_stream_unlock
+ ****************************************************************************/
+
+static void syslog_stream_unlock(FAR struct syslog_stream_s *chan)
+{
+  if (!up_interrupt_context() && !sched_idletask())
+    {
+      nxrmutex_unlock(&chan->sl_lock);
+    }
+}
+
+/****************************************************************************
+ * Name: syslog_stream_write
+ *
+ * Description:
+ *   This is the low-level, multiple byte, system logging interface provided
+ *   for the driver interface.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *   buffer     - The buffer containing the data to be output.
+ *   buflen     - The number of bytes in the buffer.
+ *
+ * Returned Value:
+ *   On success, the number of characters written is returned. A negated
+ *   errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static ssize_t syslog_stream_write(FAR struct syslog_channel_s *channel,
+                                   FAR const char *buffer, size_t buflen)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+  FAR struct lib_outstream_s *stream =
+    (FAR struct lib_outstream_s *)chan->stream;
+  ssize_t nwritten;
+  int ret;
+
+  ret = syslog_stream_lock(chan);
+  if (ret < 0)
+    {
+      /* We probably already hold the mutex and were probably
+       * re-entered by the logic kicked off by file_write().
+       * We might also have been interrupted by a signal.  Either
+       * way, we are outta here.
+       */
+
+      return ret;
+    }
+
+  nwritten = stream->puts(stream, buffer, buflen);
+  syslog_stream_unlock(chan);
+
+  return nwritten;
+}
+
+/****************************************************************************
+ * Name: syslog_stream_putc
+ *
+ * Description:
+ *   This is the low-level, single character, system logging interface
+ *   provided for the driver interface.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *   ch         - The character to add to the SYSLOG (must be positive).
+ *
+ * Returned Value:
+ *   On success, the character is echoed back to the caller. A negated errno
+ *   value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int syslog_stream_putc(FAR struct syslog_channel_s *channel,
+                                   int ch)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+  FAR struct lib_outstream_s *stream =
+    (FAR struct lib_outstream_s *)chan->stream;
+  ssize_t nbytes;
+  uint8_t uch;
+  int ret;
+
+  ret = syslog_stream_lock(chan);
+  if (ret < 0)
+    {
+      /* We probably already hold the lock and were probably
+       * re-entered by the logic kicked off by file_write().
+       * We might also have been interrupted by a signal.  Either
+       * way, we are outta here.
+       */
+
+      return ret;
+    }
+
+  uch = (uint8_t)ch;
+  nbytes = stream->puts(stream, &uch, 1);
+  syslog_stream_unlock(chan);
+
+  /* Check if the write was successful.  If not, nbytes will be
+   * a negated errno value.
+   */
+
+  if (nbytes < 0)
+    {
+      return (int)nbytes;
+    }
+
+  return ch;
+}
+
+/****************************************************************************
+ * Name: syslog_stream_force
+ *
+ * Description:
+ *   Force output in interrupt context.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *   ch         - The character to add to the SYSLOG (must be positive).
+ *
+ * Returned Value:
+ *   On success, the character is echoed back to the caller.  A negated
+ *   errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int syslog_stream_force(FAR struct syslog_channel_s *channel, int ch)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+  FAR struct lib_outstream_s *stream =
+    (FAR struct lib_outstream_s *)chan->stream;
+  ssize_t nbytes;
+  uint8_t uch;
+
+  uch = (uint8_t)ch;
+  nbytes = stream->puts(stream, &uch, 1);
+
+  /* Check if the write was successful.  If not, nbytes will be
+   * a negated errno value.
+   */
+
+  if (nbytes < 0)
+    {
+      return (int)nbytes;
+    }
+
+  return ch;
+}
+
+/****************************************************************************
+ * Name: syslog_stream_flush
+ *
+ * Description:
+ *   Flush any buffer data in the file system to media.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+static int syslog_stream_flush(FAR struct syslog_channel_s *channel)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+  FAR struct lib_outstream_s *stream =
+    (FAR struct lib_outstream_s *)chan->stream;
+
+  stream->flush(stream);
+
+  return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: syslog_stream_uninit
+ *
+ * Description:
+ *   Disable the channel in preparation to use a different
+ *   SYSLOG device.
+ *
+ * Input Parameters:
+ *   channel    - Handle to syslog channel to be used.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
+ *
+ * Assumptions:
+ *   The caller has already switched the SYSLOG source to some safe channel
+ *   (the default channel).
+ *
+ ****************************************************************************/
+
+void syslog_stream_uninit(FAR struct syslog_channel_s *channel)
+{
+  FAR struct syslog_stream_s *chan =
+    (FAR struct syslog_stream_s *)channel;
+
+  /* Uninitializing a SYSLOG device should not take place within
+   * interrupt context.
+   */
+
+  if (up_interrupt_context() || sched_idletask())

Review Comment:
   remove the check



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org