From 466d672afad6a81fddfd499cc70b22f24db068a4 Mon Sep 17 00:00:00 2001 From: chao an Date: Thu, 26 Sep 2024 10:16:21 +0800 Subject: [PATCH] syslog/channel: move syslog channel map into rodata add SYSLOG_REGISTER to support disable syslog channel register Signed-off-by: chao an --- arch/arm/Kconfig | 1 + drivers/syslog/Kconfig | 8 ++++++++ drivers/syslog/syslog.h | 6 +++++- drivers/syslog/syslog_channel.c | 9 +++++++-- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 846ce91063e0a..24d5999fe8d3a 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1374,6 +1374,7 @@ config DEBUG_SECUREFAULT config ARM_SEMIHOSTING_SYSLOG bool "Semihosting SYSLOG support" select ARCH_SYSLOG + select SYSLOG_REGISTER ---help--- Enable hooks to support semihosting syslog output. diff --git a/drivers/syslog/Kconfig b/drivers/syslog/Kconfig index 9753aa4417ea4..372f5b68b717d 100644 --- a/drivers/syslog/Kconfig +++ b/drivers/syslog/Kconfig @@ -196,6 +196,7 @@ if !ARCH_SYSLOG config SYSLOG_CHAR bool "Log to a character device" default n + select SYSLOG_REGISTER ---help--- Enable the generic character device for the SYSLOG. The full path to the SYSLOG device is provided by SYSLOG_DEVPATH. A valid character device (or @@ -231,6 +232,7 @@ config SYSLOG_CONSOLE bool "Log to /dev/console" default !ARCH_LOWPUTC && !SYSLOG_CHAR && !RAMLOG_SYSLOG && !SYSLOG_RPMSG && !SYSLOG_RTT depends on DEV_CONSOLE + select SYSLOG_REGISTER ---help--- Use the system console as a SYSLOG output device. @@ -291,6 +293,7 @@ config SYSLOG_RPMSG_SERVER_CHARDEV menuconfig SYSLOG_FILE bool "Syslog file output" default n + select SYSLOG_REGISTER ---help--- Build in support to use a file to collect SYSLOG output. File SYSLOG channels differ from other SYSLOG channels in that they cannot be @@ -375,4 +378,9 @@ config SYSLOG_IOCTL commands are SYSLOGIOC_SETFILTER/SYSLOGIOC_GETCHANNELS, which can be used to set the enable status of different channels +config SYSLOG_REGISTER + bool "Register syslog channel support" + ---help--- + This option will support register the syslog channel dynamically. + endmenu # System logging diff --git a/drivers/syslog/syslog.h b/drivers/syslog/syslog.h index b66212fbc8c7e..e86210353a684 100644 --- a/drivers/syslog/syslog.h +++ b/drivers/syslog/syslog.h @@ -47,7 +47,11 @@ extern "C" * g_default_channel. */ -EXTERN FAR syslog_channel_t *g_syslog_channel[CONFIG_SYSLOG_MAX_CHANNELS]; +EXTERN FAR syslog_channel_t * +#ifndef CONFIG_SYSLOG_REGISTER +const +#endif +g_syslog_channel[CONFIG_SYSLOG_MAX_CHANNELS]; /**************************************************************************** * Public Function Prototypes diff --git a/drivers/syslog/syslog_channel.c b/drivers/syslog/syslog_channel.c index c370fd37ecbfd..fc8465cdcfaca 100644 --- a/drivers/syslog/syslog_channel.c +++ b/drivers/syslog/syslog_channel.c @@ -191,8 +191,11 @@ static syslog_channel_t g_default_channel = /* This is the current syslog channel in use */ -FAR syslog_channel_t -*g_syslog_channel[CONFIG_SYSLOG_MAX_CHANNELS] = +FAR syslog_channel_t * +#ifndef CONFIG_SYSLOG_REGISTER +const +#endif +g_syslog_channel[CONFIG_SYSLOG_MAX_CHANNELS] = { #if defined(CONFIG_SYSLOG_DEFAULT) &g_default_channel, @@ -272,6 +275,7 @@ static ssize_t syslog_default_write(FAR syslog_channel_t *channel, * ****************************************************************************/ +#ifdef CONFIG_SYSLOG_REGISTER int syslog_channel_register(FAR syslog_channel_t *channel) { #if (CONFIG_SYSLOG_MAX_CHANNELS != 1) @@ -369,3 +373,4 @@ int syslog_channel_unregister(FAR syslog_channel_t *channel) return -EINVAL; } +#endif