There is now one-and-only-one copy of syslog_putc. It is in the SYSLOG channel logic and can redirect syslog output as needed. All former syslog_putc versions were renamed and the corresponding SYSLOG device initializaiton now calls syslog_channel()
This commit is contained in:
parent
d82942cf3b
commit
9434d3e945
@ -2,7 +2,7 @@
|
||||
* arch/arm/src/armv7-m/up_itm_syslog.c
|
||||
*
|
||||
* Copyright (C) 2014 Pierre-noel Bouteville . All rights reserved.
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved.
|
||||
* Authors: Pierre-noel Bouteville <pnb990@gmail.com>
|
||||
* Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
@ -72,6 +72,73 @@
|
||||
# define CONFIG_ARMV7M_ITMSYSLOG_PORT 0
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/* SYSLOG channel methods */
|
||||
|
||||
static int itm_putc(int ch);
|
||||
static int itm_flush(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure describes the ITM SYSLOG channel */
|
||||
|
||||
static const struct syslog_channel_s g_itm_channel =
|
||||
{
|
||||
.sc_putc = itm_putc,
|
||||
.sc_force = itm_putc,
|
||||
.sc_flush = itm_flush,
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: itm_putc
|
||||
*
|
||||
* Description:
|
||||
* This is the low-level system logging interface.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int itm_putc(int ch)
|
||||
{
|
||||
/* ITM enabled */
|
||||
|
||||
if ((getreg32(ITM_TCR) & ITM_TCR_ITMENA_Msk) == 0)
|
||||
{
|
||||
return EOF;
|
||||
}
|
||||
|
||||
/* ITM Port "CONFIG_ARMV7M_ITMSYSLOG_PORT" enabled */
|
||||
|
||||
if (getreg32(ITM_TER) & (1 << CONFIG_ARMV7M_ITMSYSLOG_PORT))
|
||||
{
|
||||
while (getreg32(ITM_PORT(CONFIG_ARMV7M_ITMSYSLOG_PORT)) == 0);
|
||||
putreg8((uint8_t)ch, ITM_PORT(CONFIG_ARMV7M_ITMSYSLOG_PORT));
|
||||
}
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: itm_flush
|
||||
*
|
||||
* Description:
|
||||
* A dummy FLUSH method
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int itm_flush(void)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -116,38 +183,10 @@ void itm_syslog_initialize(void)
|
||||
putreg32(0x0001000d, ITM_TCR);
|
||||
putreg32(0x00000100, TPI_FFCR);
|
||||
putreg32(0xffffffff, ITM_TER); /* Enable 32 Ports */
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: syslog_putc
|
||||
*
|
||||
* Description:
|
||||
* This is the low-level system logging interface. The debugging/syslogging
|
||||
* interfaces are syslog() and lowsyslog(). The difference is that
|
||||
* the syslog() internface writes to fd=1 (stdout) whereas lowsyslog() uses
|
||||
* a lower level interface that works from interrupt handlers. This
|
||||
* function is the low-level interface used to implement lowsyslog().
|
||||
*
|
||||
****************************************************************************/
|
||||
/* Setup the SYSLOG channel */
|
||||
|
||||
int syslog_putc(int ch)
|
||||
{
|
||||
/* ITM enabled */
|
||||
|
||||
if ((getreg32(ITM_TCR) & ITM_TCR_ITMENA_Msk) == 0)
|
||||
{
|
||||
return EOF;
|
||||
}
|
||||
|
||||
/* ITM Port "CONFIG_ARMV7M_ITMSYSLOG_PORT" enabled */
|
||||
|
||||
if (getreg32(ITM_TER) & (1 << CONFIG_ARMV7M_ITMSYSLOG_PORT))
|
||||
{
|
||||
while (getreg32(ITM_PORT(CONFIG_ARMV7M_ITMSYSLOG_PORT)) == 0);
|
||||
putreg8((uint8_t)ch, ITM_PORT(CONFIG_ARMV7M_ITMSYSLOG_PORT));
|
||||
}
|
||||
|
||||
return ch;
|
||||
(void)syslog_channel(&g_itm_channel);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_SYSLOG && CONFIG_ARMV7M_ITMSYSLOG */
|
||||
|
@ -284,6 +284,10 @@ config 16550_UART3_OFLOWCONTROL
|
||||
|
||||
endif # 16550_UART3
|
||||
|
||||
config SERIAL_CONSOLE
|
||||
bool
|
||||
default n
|
||||
|
||||
choice
|
||||
prompt "16550 Serial Console"
|
||||
default 16550_NO_SERIAL_CONSOLE
|
||||
@ -292,18 +296,22 @@ choice
|
||||
config 16550_UART0_SERIAL_CONSOLE
|
||||
bool "16550 UART0 serial console"
|
||||
depends on 16550_UART0
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config 16550_UART1_SERIAL_CONSOLE
|
||||
bool "16550 UART1 serial console"
|
||||
depends on 16550_UART1
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config 16550_UART2_SERIAL_CONSOLE
|
||||
bool "16550 UART2 serial console"
|
||||
depends on 16550_UART2
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config 16550_UART3_SERIAL_CONSOLE
|
||||
bool "16550 UART3 serial console"
|
||||
depends on 16550_UART3
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config 16550_NO_SERIAL_CONSOLE
|
||||
bool "No 16550 serial console"
|
||||
@ -566,89 +574,111 @@ choice
|
||||
config UART_SERIAL_CONSOLE
|
||||
bool "UART"
|
||||
depends on UART_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config UART0_SERIAL_CONSOLE
|
||||
bool "UART0"
|
||||
depends on UART0_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config USART0_SERIAL_CONSOLE
|
||||
bool "USART0"
|
||||
depends on USART0_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config UART1_SERIAL_CONSOLE
|
||||
bool "UART1"
|
||||
depends on UART1_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config USART1_SERIAL_CONSOLE
|
||||
bool "USART1"
|
||||
depends on USART1_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config UART2_SERIAL_CONSOLE
|
||||
bool "UART2"
|
||||
depends on UART2_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config USART2_SERIAL_CONSOLE
|
||||
bool "USART2"
|
||||
depends on USART2_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config UART3_SERIAL_CONSOLE
|
||||
bool "UART3"
|
||||
depends on UART3_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config USART3_SERIAL_CONSOLE
|
||||
bool "USART3"
|
||||
depends on USART3_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config UART4_SERIAL_CONSOLE
|
||||
bool "UART4"
|
||||
depends on UART4_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config USART4_SERIAL_CONSOLE
|
||||
bool "USART4"
|
||||
depends on USART4_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config UART5_SERIAL_CONSOLE
|
||||
bool "UART5"
|
||||
depends on UART5_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config USART5_SERIAL_CONSOLE
|
||||
bool "USART5"
|
||||
depends on USART5_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config UART6_SERIAL_CONSOLE
|
||||
bool "UART6"
|
||||
depends on UART6_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config USART6_SERIAL_CONSOLE
|
||||
bool "USART6"
|
||||
depends on USART6_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config UART7_SERIAL_CONSOLE
|
||||
bool "UART7"
|
||||
depends on UART7_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config USART7_SERIAL_CONSOLE
|
||||
bool "USART7"
|
||||
depends on USART7_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config UART8_SERIAL_CONSOLE
|
||||
bool "UART8"
|
||||
depends on UART8_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config USART8_SERIAL_CONSOLE
|
||||
bool "USART8"
|
||||
depends on USART8_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config SCI0_SERIAL_CONSOLE
|
||||
bool "SCI0"
|
||||
depends on SCI0_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config SCI1_SERIAL_CONSOLE
|
||||
bool "SCI1"
|
||||
depends on SCI1_SERIALDRIVER
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config OTHER_SERIAL_CONSOLE
|
||||
bool "Other serial console"
|
||||
select SERIAL_CONSOLE
|
||||
|
||||
config NO_SERIAL_CONSOLE
|
||||
bool "No serial console"
|
||||
|
@ -68,8 +68,14 @@ ifeq ($(CONFIG_SYSLOG),y)
|
||||
|
||||
# System logging to a character device (or file)
|
||||
|
||||
ifeq ($(CONFIG_SYSLOG_CHAR),y)
|
||||
CSRCS += syslog_device.c
|
||||
|
||||
ifeq ($(CONFIG_SYSLOG_CHAR),y)
|
||||
CSRCS += syslog_devchannel.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_DEV_CONSOLE),y)
|
||||
CSRCS += syslog_consolechannel.c
|
||||
endif
|
||||
|
||||
# (Add other SYSLOG drivers here)
|
||||
|
@ -63,10 +63,6 @@
|
||||
|
||||
#ifdef CONFIG_RAMLOG
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
@ -95,6 +91,27 @@ struct ramlog_dev_s
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_RAMLOG_SYSLOG
|
||||
static int ramlog_flush(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_RAMLOG_SYSLOG
|
||||
static const struct syslog_channel_s g_ramlog_syslog_channel =
|
||||
{
|
||||
ramlog_putc,
|
||||
ramlog_putc,
|
||||
ramlog_flush
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
@ -145,7 +162,7 @@ static const struct file_operations g_ramlogfops =
|
||||
static char g_sysbuffer[CONFIG_RAMLOG_BUFSIZE];
|
||||
|
||||
/* This is the device structure for the console or syslogging function. It
|
||||
* must be statically initialized because the RAMLOG syslog_putc function
|
||||
* must be statically initialized because the RAMLOG ramlog_putc function
|
||||
* could be called before the driver initialization logic executes.
|
||||
*/
|
||||
|
||||
@ -704,7 +721,7 @@ int ramlog_consoleinit(void)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ramlog_syslog_initialize
|
||||
* Name: ramlog_syslog_channel
|
||||
*
|
||||
* Description:
|
||||
* Use a pre-allocated RAM logging device and register it at the path
|
||||
@ -716,16 +733,26 @@ int ramlog_consoleinit(void)
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_RAMLOG_SYSLOG
|
||||
int ramlog_syslog_initialize(void)
|
||||
int ramlog_syslog_channel(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Register the syslog character driver */
|
||||
|
||||
return register_driver(CONFIG_SYSLOG_DEVPATH, &g_ramlogfops, 0666, &g_sysdev);
|
||||
ret = register_driver(CONFIG_SYSLOG_DEVPATH, &g_ramlogfops, 0666, &g_sysdev);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Use the RAMLOG as the SYSLOG channel */
|
||||
|
||||
return syslog_channel(&g_ramlog_syslog_channel);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: syslog_putc
|
||||
* Name: ramlog_putc
|
||||
*
|
||||
* Description:
|
||||
* This is the low-level system logging interface. The debugging/syslogging
|
||||
@ -738,7 +765,7 @@ int ramlog_syslog_initialize(void)
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_RAMLOG_CONSOLE) || defined(CONFIG_RAMLOG_SYSLOG)
|
||||
int syslog_putc(int ch)
|
||||
int ramlog_putc(int ch)
|
||||
{
|
||||
FAR struct ramlog_dev_s *priv = &g_sysdev;
|
||||
int ret;
|
||||
|
@ -87,6 +87,34 @@ extern "C"
|
||||
* SYSLOG device. That would be a good extension.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devpath - The full path to the character device to be used.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned on
|
||||
* any failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
int syslog_dev_initialize(FAR const char *devpath);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: syslog_dev_channel
|
||||
*
|
||||
* Description:
|
||||
* Configure to use the character device (or file) at
|
||||
* CONFIG_SYSLOG_DEVPATH as the SYSLOG channel.
|
||||
*
|
||||
* This tiny function is simply a wrapper around syslog_dev_initialize()
|
||||
* and syslog_channel(). It calls syslog_dev_initialize() to configure
|
||||
* the character device at CONFIG_SYSLOG_DEVPATH then calls
|
||||
* syslog_channel() to use that device as the SYSLOG output channel.
|
||||
*
|
||||
* NOTE interrupt level SYSLOG output will be lost in this case unless
|
||||
* the interrupt buffer is used.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
@ -96,7 +124,38 @@ extern "C"
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SYSLOG_CHAR
|
||||
int syslog_dev_initialize(void);
|
||||
int syslog_dev_channel(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: syslog_console_channel
|
||||
*
|
||||
* Description:
|
||||
* Configure to use the character device (or file) at /dev/console as the
|
||||
* SYSLOG channel.
|
||||
*
|
||||
* This tiny function is simply a wrapper around syslog_dev_initialize()
|
||||
* and syslog_channel(). It calls syslog_dev_initialize() to configure
|
||||
* the character device at /dev/console then calls syslog_channel() to
|
||||
* use that device as the SYSLOG output channel.
|
||||
*
|
||||
* NOTE interrupt level SYSLOG output will be lost in the general case
|
||||
* unless the interrupt buffer is used. As a special case: If the serial
|
||||
* console is used and the architecture provides up_putc(), the interrupt
|
||||
* level output will be directed to up_putc() is the interrupt buffer is
|
||||
* disabled.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned on
|
||||
* any failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_DEV_CONSOLE
|
||||
int syslog_console_channel(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@ -148,6 +207,61 @@ int syslog_flush_intbuffer(FAR const struct syslog_channel_s *channel,
|
||||
bool force);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* 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);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: syslog_dev_putc
|
||||
*
|
||||
* Description:
|
||||
* This is the low-level system logging interface provided for the
|
||||
* character driver 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
int syslog_dev_putc(int ch);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: syslog_dev_flush
|
||||
*
|
||||
* Description:
|
||||
* Flush any buffer data in the file system to media.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value is returned on any failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
int syslog_dev_flush(void);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
@ -53,7 +54,9 @@
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/syslog/syslog.h>
|
||||
|
||||
#if defined(CONFIG_SYSLOG) && defined(CONFIG_SYSLOG_CHAR)
|
||||
#include "syslog.h"
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@ -89,10 +92,11 @@ enum syslog_dev_state
|
||||
|
||||
struct syslog_dev_s
|
||||
{
|
||||
uint8_t sl_state; /* See enum syslog_dev_state */
|
||||
sem_t sl_sem; /* Enforces mutually exclusive access */
|
||||
pid_t sl_holder; /* PID of the thread that holds the semaphore */
|
||||
struct file sl_file; /* The syslog file structure */
|
||||
uint8_t sl_state; /* See enum syslog_dev_state */
|
||||
sem_t sl_sem; /* Enforces mutually exclusive access */
|
||||
pid_t sl_holder; /* PID of the thread that holds the semaphore */
|
||||
struct file sl_file; /* The syslog file structure */
|
||||
FAR const char *sl_devpath; /* Full path to the character device */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
@ -196,31 +200,6 @@ static inline ssize_t syslog_dev_write(FAR const void *buf, size_t nbytes)
|
||||
return inode->u.i_ops->write(&g_syslog_dev.sl_file, buf, nbytes);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: syslog_dev_flush
|
||||
*
|
||||
* Description:
|
||||
* Flush any buffer data in the file system to media.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
static inline void syslog_dev_flush(void)
|
||||
{
|
||||
FAR struct inode *inode = g_syslog_dev.sl_file.f_inode;
|
||||
|
||||
/* Is this a mountpoint? Does it support the sync method? */
|
||||
|
||||
DEBUGASSERT(inode != NULL);
|
||||
if (inode->u.i_mops->sync)
|
||||
{
|
||||
/* Yes... synchronize to the stream */
|
||||
|
||||
(void)inode->u.i_mops->sync(&g_syslog_dev.sl_file);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -242,7 +221,7 @@ static inline void syslog_dev_flush(void)
|
||||
* SYSLOG device. That would be a good extension.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
* devpath - The full path to the character device to be used.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned on
|
||||
@ -250,7 +229,7 @@ static inline void syslog_dev_flush(void)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int syslog_dev_initialize(void)
|
||||
int syslog_dev_initialize(FAR const char *devpath)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
@ -262,11 +241,36 @@ int syslog_dev_initialize(void)
|
||||
DEBUGASSERT(g_syslog_dev.sl_state == SYSLOG_UNINITIALIZED ||
|
||||
g_syslog_dev.sl_state == SYSLOG_REOPEN);
|
||||
|
||||
/* Save the the path to the device in case we have to re-open it.
|
||||
* If we get here and sl_devpath is not equal to NULL, that is a clue
|
||||
* that we will are re-openingthe file.
|
||||
*/
|
||||
|
||||
if (g_syslog_dev.sl_state == SYSLOG_REOPEN)
|
||||
{
|
||||
/* Re-opening: Then we should already have a copy of the path to the
|
||||
* device.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(g_syslog_dev.sl_devpath != NULL &&
|
||||
strcmp(g_syslog_dev.sl_devpath, devpath) == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Initializing. Copy the device path so that we can use it if we
|
||||
* have to re-open the file.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(g_syslog_dev.sl_devpath == NULL);
|
||||
g_syslog_dev.sl_devpath = strdup(devpath);
|
||||
DEBUGASSERT(g_syslog_dev.sl_devpath != NULL);
|
||||
}
|
||||
|
||||
g_syslog_dev.sl_state = SYSLOG_INITIALIZING;
|
||||
|
||||
/* Open the device driver. */
|
||||
|
||||
fd = open(CONFIG_SYSLOG_DEVPATH, O_WRONLY);
|
||||
fd = open(devpath, O_WRONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
int errcode = get_errno();
|
||||
@ -312,19 +316,22 @@ int syslog_dev_initialize(void)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: syslog_putc
|
||||
* Name: syslog_dev_putc
|
||||
*
|
||||
* Description:
|
||||
* This is the low-level system logging interface. The debugging/syslogging
|
||||
* interfaces are syslog() and lowsyslog(). The difference is is that
|
||||
* the syslog() function writes to syslogging device (usually fd=1, stdout)
|
||||
* whereas lowsyslog() uses a lower level interface that works from
|
||||
* interrupt handlers. This function is a a low-level interface used to
|
||||
* implement lowsyslog().
|
||||
* This is the low-level system logging interface provided for the
|
||||
* character driver 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)
|
||||
int syslog_dev_putc(int ch)
|
||||
{
|
||||
ssize_t nbytes;
|
||||
uint8_t uch;
|
||||
@ -340,7 +347,7 @@ int syslog_putc(int ch)
|
||||
* debug output is generated while syslog_dev_initialize() executes
|
||||
* (SYSLOG_INITIALIZING).
|
||||
* (3) While we are generating SYSLOG output. The case could happen if
|
||||
* debug output is generated while syslog_putc() executes
|
||||
* debug output is generated while syslog_dev_putc() executes
|
||||
* (This case is actually handled inside of syslog_semtake()).
|
||||
* (4) Any debug output generated from interrupt handlers. A disadvantage
|
||||
* of using the generic character device for the SYSLOG is that it
|
||||
@ -408,7 +415,8 @@ int syslog_putc(int ch)
|
||||
* an NFS mounted file system that has not yet been mounted).
|
||||
*/
|
||||
|
||||
ret = syslog_dev_initialize();
|
||||
DEBUGASSERT(g_syslog_dev.sl_devpath != NULL);
|
||||
ret = syslog_dev_initialize(g_syslog_dev.sl_devpath);
|
||||
if (ret < 0)
|
||||
{
|
||||
sched_unlock();
|
||||
@ -460,7 +468,7 @@ int syslog_putc(int ch)
|
||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
if (nbytes > 0)
|
||||
{
|
||||
syslog_dev_flush();
|
||||
(void)syslog_dev_flush();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -491,4 +499,43 @@ errout_with_errcode:
|
||||
return EOF;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_SYSLOG && CONFIG_SYSLOG_CHAR */
|
||||
/****************************************************************************
|
||||
* Name: syslog_dev_flush
|
||||
*
|
||||
* Description:
|
||||
* Flush any buffer data in the file system to media.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value is returned on any failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int syslog_dev_flush(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
FAR struct inode *inode = g_syslog_dev.sl_file.f_inode;
|
||||
|
||||
/* Is this a mountpoint? Does it support the sync method? */
|
||||
|
||||
DEBUGASSERT(inode != NULL);
|
||||
if (inode->u.i_mops->sync)
|
||||
{
|
||||
/* Yes... synchronize to the stream */
|
||||
|
||||
ret = inode->u.i_mops->sync(&g_syslog_dev.sl_file);
|
||||
}
|
||||
|
||||
#else
|
||||
ret = 0;
|
||||
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NFILE_DESCRIPTORS > 0 */
|
||||
|
@ -87,12 +87,17 @@ int syslog_initialize(void)
|
||||
#if defined(CONFIG_SYSLOG_CHAR)
|
||||
/* Enable use of a character device as the SYSLOG device */
|
||||
|
||||
ret = syslog_dev_initialize();
|
||||
ret = syslog_dev_channel();
|
||||
|
||||
#elif defined(CONFIG_RAMLOG_SYSLOG)
|
||||
/* Use the RAMLOG as the SYSLOG device */
|
||||
|
||||
ret = ramlog_syslog_initialize();
|
||||
ret = ramlog_syslog_channel();
|
||||
|
||||
#elif defined(CONFIG_DEV_CONSOLE)
|
||||
/* Use the console device as the SYSLOG device */
|
||||
|
||||
ret = syslog_console_channel();
|
||||
|
||||
#else
|
||||
/* Nothing needs to be done */
|
||||
|
@ -47,6 +47,8 @@
|
||||
#include <nuttx/syslog/syslog.h>
|
||||
#include <nuttx/streams.h>
|
||||
|
||||
#include "syslog.h"
|
||||
|
||||
#ifdef CONFIG_SYSLOG
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -183,7 +183,7 @@ int ramlog_consoleinit(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ramlog_syslog_initialize
|
||||
* Name: ramlog_syslog_channel
|
||||
*
|
||||
* Description:
|
||||
* Create the RAM logging device and register it at the specified path.
|
||||
@ -195,7 +195,24 @@ int ramlog_consoleinit(void);
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_RAMLOG_SYSLOG
|
||||
int ramlog_syslog_initialize(void);
|
||||
int ramlog_syslog_channel(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ramlog_putc
|
||||
*
|
||||
* Description:
|
||||
* This is the low-level system logging interface. The debugging/syslogging
|
||||
* interfaces are syslog() and lowsyslog(). The difference is that
|
||||
* the syslog() internface writes to syslog device (usually fd=1, stdout)
|
||||
* whereas lowsyslog() uses a lower level interface that works from
|
||||
* interrupt handlers. This function is a a low-level interface used to
|
||||
* implement lowsyslog() when CONFIG_RAMLOG_SYSLOG=y and CONFIG_SYSLOG=y
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_RAMLOG_CONSOLE) || defined(CONFIG_RAMLOG_SYSLOG)
|
||||
int ramlog_putc(int ch);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
|
@ -56,7 +56,7 @@
|
||||
* CONFIG_SYSLOG_DEVPATH - The full path to the system logging device
|
||||
*
|
||||
* In addition, some SYSLOG device must also be enabled that will provide
|
||||
* the syslog_putc() function. As of this writing, there are two SYSLOG
|
||||
* the syslog output "channel. As of this writing, there are two SYSLOG
|
||||
* devices avaiable:
|
||||
*
|
||||
* 1. A RAM SYSLOGing device that will log data into a circular buffer
|
||||
@ -191,23 +191,6 @@ int syslog_initialize(void);
|
||||
# define syslog_initialize()
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* 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);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: syslog_flush
|
||||
*
|
||||
|
@ -51,10 +51,10 @@
|
||||
/* Configuration ************************************************************/
|
||||
/* CONFIG_SYSLOG_CONSOLE - Use the syslog logging output as a system console.
|
||||
* If this feature is enabled (along with CONFIG_DEV_CONSOLE), then all
|
||||
* console output will be re-directed to a syslog_putc function. This
|
||||
* console output will be re-directed to the SYSLOG output channel. 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_putc output.
|
||||
* SYSLOG output channel.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_DEV_CONSOLE
|
||||
|
@ -47,13 +47,13 @@
|
||||
|
||||
#if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_SYSLOG)
|
||||
/* The low-level SYSLOG functions can be used only if we have access to
|
||||
* either the low-level serial interface, up_putc(), and to syslog_putc()
|
||||
* either the low-level serial interface, up_putc().
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_BUILD_FLAT) || defined (__KERNEL__)
|
||||
/* The low-level serial interface, up_putc(), and syslog_putc() are only
|
||||
* available in the FLAT build or during the kernel pass of the protected or
|
||||
* kernel two pass builds.
|
||||
/* The low-level serial interface, up_putc(), is only available in the FLAT
|
||||
* build or during the kernel pass of the protected or kernel two pass
|
||||
* builds.
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
|
Loading…
Reference in New Issue
Block a user