Skip to content

Commit

Permalink
drivers/syslog: remove implement of syslog_putc()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
anchao authored and xiaoxiang781216 committed Nov 15, 2024
1 parent 19b4911 commit 238cddd
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 243 deletions.
6 changes: 3 additions & 3 deletions Documentation/guides/logging_rambuffer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
device adds data to the head of the queue; reading from the RAMLOG device
removes data from the tail of the queue.
Expand Down Expand Up @@ -91,7 +91,7 @@ These enables the RAMLOG and configure it for use as the syslog device
CONFIG_RAMLOG_CONSOLE_BUFSIZE=8192
CONFIG_RAMLOG_NONBLOCKING=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
as an NSH command:
Expand Down Expand Up @@ -167,4 +167,4 @@ As a side note, the ``posix_spawn_exec`` error will occur on each command in
this configuration. That is because NSH first tries to execute a command from
a file found in the file system on the ``PATH`` variable. You will not see
this error in your system unless you have ``CONFIG_NSH_FILE_APPS=y``
defined in your configuration.
defined in your configuration.
2 changes: 1 addition & 1 deletion arch/arm/src/efm32/efm32_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const uintptr_t g_idle_topstack = HEAP_BASE;

#ifdef CONFIG_DEBUG_FEATURES
# 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)
# define showprogress(c) efm32_lowputc(c)
# else
Expand Down
9 changes: 1 addition & 8 deletions drivers/syslog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,7 @@
set(SRCS)

if(CONFIG_SYSLOG)
list(
APPEND
SRCS
vsyslog.c
syslog_channel.c
syslog_putc.c
syslog_write.c
syslog_flush.c)
list(APPEND SRCS vsyslog.c syslog_channel.c syslog_write.c syslog_flush.c)
endif()

if(CONFIG_SYSLOG_INTBUFFER)
Expand Down
2 changes: 1 addition & 1 deletion drivers/syslog/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ config CONSOLE_SYSLOG
---help---
Use the syslog logging device as a system console. If this feature is
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,
console output from non-Telnet threads will go to the syslog output.

Expand Down
2 changes: 1 addition & 1 deletion drivers/syslog/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# Include SYSLOG Infrastructure

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
endif

Expand Down
208 changes: 0 additions & 208 deletions drivers/syslog/syslog_putc.c

This file was deleted.

17 changes: 0 additions & 17 deletions include/nuttx/syslog/syslog.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,23 +310,6 @@ FAR syslog_channel_t *
syslog_stream_channel(FAR struct lib_outstream_s *stream);
#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
*
Expand Down
10 changes: 6 additions & 4 deletions libs/libc/stream/lib_syslograwstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,20 @@ static void syslograwstream_putc(FAR struct lib_outstream_s *self, int ch)

do
{
char c = ch;

/* 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)
{
self->nput++;
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
* ignored in this context.
*/
Expand Down Expand Up @@ -221,7 +223,7 @@ static ssize_t syslograwstream_puts(FAR struct lib_outstream_s *self,
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
* ignored in this context.
*/
Expand Down

0 comments on commit 238cddd

Please sign in to comment.