forked from nuttx/nuttx-update
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:
parent
19b4911d7f
commit
238cddde3a
8 changed files with 13 additions and 243 deletions
|
@ -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.
|
||||
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue