drivers/syslog: remove implement of syslog_putc()

syslog_putc() have a lot of duplicate logic with syslog_write().
remove syslog_putc() and reuse syslog_write() to simplify syslog printing.

Signed-off-by: chao an <anchao@lixiang.com>
This commit is contained in:
chao an
2024-11-15 17:19:53 +08:00
committed by Xiang Xiao
parent 19b4911d7f
commit 238cddde3a
8 changed files with 13 additions and 243 deletions
+2 -2
View File
@@ -42,7 +42,7 @@ The RAMLOG device is a special character device that can really be used for
most any purpose. However, the RAMLOG device has some special attributes most any purpose. However, the RAMLOG device has some special attributes
that make it ideal for use as a syslogging device. that make it ideal for use as a syslogging device.
* It supports the ``syslog_putc`` interface needed for system logging * It supports the ``syslog_write`` interface needed for system logging
* It behaves much like a pipe: It implements a queue. Writing to the RAMLOG * It behaves much like a pipe: It implements a queue. Writing to the RAMLOG
device adds data to the head of the queue; reading from the RAMLOG device device adds data to the head of the queue; reading from the RAMLOG device
removes data from the tail of the queue. removes data from the tail of the queue.
@@ -91,7 +91,7 @@ These enables the RAMLOG and configure it for use as the syslog device
CONFIG_RAMLOG_CONSOLE_BUFSIZE=8192 CONFIG_RAMLOG_CONSOLE_BUFSIZE=8192
CONFIG_RAMLOG_NONBLOCKING=y CONFIG_RAMLOG_NONBLOCKING=y
CONFIG_RAMLOG_SYSLOG=y CONFIG_RAMLOG_SYSLOG=y
#CONFIG_SYSLOG_CHAR undefined, else duplicate output with syslog_putc() #CONFIG_SYSLOG_CHAR undefined, else duplicate output with syslog_write()
Now when I run NuttX, I get output like this. The ``dmesg`` command now appears Now when I run NuttX, I get output like this. The ``dmesg`` command now appears
as an NSH command: as an NSH command:
+1 -1
View File
@@ -84,7 +84,7 @@ const uintptr_t g_idle_topstack = HEAP_BASE;
#ifdef CONFIG_DEBUG_FEATURES #ifdef CONFIG_DEBUG_FEATURES
# if defined(CONFIG_ARMV7M_ITMSYSLOG) # if defined(CONFIG_ARMV7M_ITMSYSLOG)
# define showprogress(c) syslog_putc(c) # define showprogress(c) up_putc(c)
# elif defined(HAVE_UART_CONSOLE) || defined(HAVE_LEUART_CONSOLE) # elif defined(HAVE_UART_CONSOLE) || defined(HAVE_LEUART_CONSOLE)
# define showprogress(c) efm32_lowputc(c) # define showprogress(c) efm32_lowputc(c)
# else # else
+1 -8
View File
@@ -25,14 +25,7 @@
set(SRCS) set(SRCS)
if(CONFIG_SYSLOG) if(CONFIG_SYSLOG)
list( list(APPEND SRCS vsyslog.c syslog_channel.c syslog_write.c syslog_flush.c)
APPEND
SRCS
vsyslog.c
syslog_channel.c
syslog_putc.c
syslog_write.c
syslog_flush.c)
endif() endif()
if(CONFIG_SYSLOG_INTBUFFER) if(CONFIG_SYSLOG_INTBUFFER)
+1 -1
View File
@@ -389,7 +389,7 @@ config CONSOLE_SYSLOG
---help--- ---help---
Use the syslog logging device as a system console. If this feature is Use the syslog logging device as a system console. If this feature is
enabled (along with DEV_CONSOLE), then all console output will be enabled (along with DEV_CONSOLE), then all console output will be
re-directed to syslog output (syslog_putc). This is useful, for re-directed to syslog output (syslog_write). This is useful, for
example, if the only console is a Telnet console. Then in that case, example, if the only console is a Telnet console. Then in that case,
console output from non-Telnet threads will go to the syslog output. console output from non-Telnet threads will go to the syslog output.
+1 -1
View File
@@ -24,7 +24,7 @@
# Include SYSLOG Infrastructure # Include SYSLOG Infrastructure
ifeq ($(CONFIG_SYSLOG),y) ifeq ($(CONFIG_SYSLOG),y)
CSRCS += vsyslog.c syslog_channel.c syslog_putc.c CSRCS += vsyslog.c syslog_channel.c
CSRCS += syslog_write.c syslog_flush.c CSRCS += syslog_write.c syslog_flush.c
endif endif
-208
View File
@@ -1,208 +0,0 @@
/****************************************************************************
* drivers/syslog/syslog_putc.c
*
* SPDX-License-Identifier: Apache-2.0
*
* 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/types.h>
#include <assert.h>
#include <errno.h>
#include <nuttx/arch.h>
#include <nuttx/sched.h>
#include <nuttx/syslog/syslog.h>
#include "syslog.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: syslog_putc
*
* Description:
* This is the low-level system logging interface.
*
* Input Parameters:
* 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.
*
****************************************************************************/
int syslog_putc(int ch)
{
/* Is this an attempt to do SYSLOG output from an interrupt handler? */
if (up_interrupt_context() || sched_idletask())
{
#ifdef CONFIG_SYSLOG_INTBUFFER
if (up_interrupt_context())
{
/* Buffer the character in the interrupt buffer.
* The interrupt buffer will be flushed before the next
* normal,non-interrupt SYSLOG output.
*/
return syslog_add_intbuffer(ch);
}
else
#endif
{
int i;
/* Force the character to the SYSLOG device immediately
* (if possible).
* This means that the interrupt data may not be in
* synchronization with output data that may have been
* buffered by sc_putc().
*/
for (i = 0; i < CONFIG_SYSLOG_MAX_CHANNELS; i++)
{
FAR syslog_channel_t *channel = g_syslog_channel[i];
if (channel == NULL)
{
break;
}
#ifdef CONFIG_SYSLOG_IOCTL
if (channel->sc_state & SYSLOG_CHANNEL_DISABLE)
{
continue;
}
#endif
if (channel->sc_ops->sc_force != NULL)
{
#ifdef CONFIG_SYSLOG_CRLF
/* Check for LF */
if (ch == '\n' &&
!(channel->sc_state & SYSLOG_CHANNEL_DISABLE_CRLF))
{
/* Add CR */
channel->sc_ops->sc_force(channel, '\r');
}
#endif
channel->sc_ops->sc_force(channel, ch);
}
else
{
char tmp = ch;
DEBUGASSERT(channel->sc_ops->sc_write_force != NULL);
#ifdef CONFIG_SYSLOG_CRLF
/* Check for LF */
if (tmp == '\n' &&
!(channel->sc_state & SYSLOG_CHANNEL_DISABLE_CRLF))
{
/* Add CR */
channel->sc_ops->sc_write_force(channel, "\r", 1);
}
#endif
channel->sc_ops->sc_write_force(channel, &tmp, 1);
}
}
}
}
else
{
int i;
#ifdef CONFIG_SYSLOG_INTBUFFER
/* Flush any characters that may have been added to the interrupt
* buffer.
*/
syslog_flush_intbuffer(false);
#endif
for (i = 0; i < CONFIG_SYSLOG_MAX_CHANNELS; i++)
{
FAR syslog_channel_t *channel = g_syslog_channel[i];
if (channel == NULL)
{
break;
}
#ifdef CONFIG_SYSLOG_IOCTL
if (channel->sc_state & SYSLOG_CHANNEL_DISABLE)
{
continue;
}
#endif
if (channel->sc_ops->sc_putc != NULL)
{
#ifdef CONFIG_SYSLOG_CRLF
/* Check for LF */
if (ch == '\n' &&
!(channel->sc_state & SYSLOG_CHANNEL_DISABLE_CRLF))
{
/* Add CR */
channel->sc_ops->sc_putc(channel, '\r');
}
#endif
channel->sc_ops->sc_putc(channel, ch);
}
else
{
char tmp = ch;
DEBUGASSERT(channel->sc_ops->sc_write != NULL);
#ifdef CONFIG_SYSLOG_CRLF
/* Check for LF */
if (tmp == '\n' &&
!(channel->sc_state & SYSLOG_CHANNEL_DISABLE_CRLF))
{
/* Add CR */
channel->sc_ops->sc_write(channel, "\r", 1);
}
#endif
channel->sc_ops->sc_write(channel, &tmp, 1);
}
}
}
return ch;
}
-17
View File
@@ -310,23 +310,6 @@ FAR syslog_channel_t *
syslog_stream_channel(FAR struct lib_outstream_s *stream); syslog_stream_channel(FAR struct lib_outstream_s *stream);
#endif #endif
/****************************************************************************
* Name: syslog_putc
*
* Description:
* This is the low-level, single character, system logging interface.
*
* Input Parameters:
* 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.
*
****************************************************************************/
int syslog_putc(int ch);
/**************************************************************************** /****************************************************************************
* Name: syslog_write * Name: syslog_write
* *
+6 -4
View File
@@ -162,18 +162,20 @@ static void syslograwstream_putc(FAR struct lib_outstream_s *self, int ch)
do do
{ {
char c = ch;
/* Write the character to the supported logging device. On /* Write the character to the supported logging device. On
* failure, syslog_putc returns a negated errno value. * failure, syslog_write returns a negated errno value.
*/ */
ret = syslog_putc(ch); ret = syslog_write(&c, 1);
if (ret >= 0) if (ret >= 0)
{ {
self->nput++; self->nput++;
return; return;
} }
/* The special return value -EINTR means that syslog_putc() was /* The special return value -EINTR means that syslog_write() was
* awakened by a signal. This is not a real error and must be * awakened by a signal. This is not a real error and must be
* ignored in this context. * ignored in this context.
*/ */
@@ -221,7 +223,7 @@ static ssize_t syslograwstream_puts(FAR struct lib_outstream_s *self,
return ret; return ret;
} }
/* The special return value -EINTR means that syslog_putc() was /* The special return value -EINTR means that syslog_write() was
* awakened by a signal. This is not a real error and must be * awakened by a signal. This is not a real error and must be
* ignored in this context. * ignored in this context.
*/ */