From 0c41611429d85fa348442eb74bbea72ff77d9437 Mon Sep 17 00:00:00 2001 From: Fotis Panagiotopoulos Date: Thu, 13 Jan 2022 14:45:44 +0200 Subject: [PATCH] syslog: Fix in file channel initialization. --- drivers/syslog/syslog_consolechannel.c | 24 ++++++++------------- drivers/syslog/syslog_devchannel.c | 24 ++++++++------------- drivers/syslog/syslog_filechannel.c | 30 +++++++------------------- 3 files changed, 26 insertions(+), 52 deletions(-) diff --git a/drivers/syslog/syslog_consolechannel.c b/drivers/syslog/syslog_consolechannel.c index 9fcd426f7b..463634632e 100644 --- a/drivers/syslog/syslog_consolechannel.c +++ b/drivers/syslog/syslog_consolechannel.c @@ -41,14 +41,6 @@ #define OPEN_FLAGS (O_WRONLY) #define OPEN_MODE (S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR) -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Handle to the SYSLOG channel */ - -FAR static struct syslog_channel_s *g_syslog_console_channel; - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -81,24 +73,26 @@ FAR static struct syslog_channel_s *g_syslog_console_channel; FAR struct syslog_channel_s *syslog_console_channel(void) { + FAR struct syslog_channel_s *console_channel; + /* Initialize the character driver interface */ - g_syslog_console_channel = syslog_dev_initialize("/dev/console", - OPEN_FLAGS, OPEN_MODE); - if (g_syslog_console_channel == NULL) + console_channel = syslog_dev_initialize("/dev/console", + OPEN_FLAGS, OPEN_MODE); + if (console_channel == NULL) { return NULL; } /* Use the character driver as the SYSLOG channel */ - if (syslog_channel(g_syslog_console_channel) != OK) + if (syslog_channel(console_channel) != OK) { - syslog_dev_uninitialize(g_syslog_console_channel); - g_syslog_console_channel = NULL; + syslog_dev_uninitialize(console_channel); + console_channel = NULL; } - return g_syslog_console_channel; + return console_channel; } #endif /* CONFIG_SYSLOG_CONSOLE */ diff --git a/drivers/syslog/syslog_devchannel.c b/drivers/syslog/syslog_devchannel.c index 00b534dbc5..b0f1626602 100644 --- a/drivers/syslog/syslog_devchannel.c +++ b/drivers/syslog/syslog_devchannel.c @@ -41,14 +41,6 @@ #define OPEN_FLAGS (O_WRONLY) #define OPEN_MODE (S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR) -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Handle to the SYSLOG channel */ - -FAR static struct syslog_channel_s *g_syslog_dev_channel; - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -78,24 +70,26 @@ FAR static struct syslog_channel_s *g_syslog_dev_channel; FAR struct syslog_channel_s *syslog_dev_channel(void) { + FAR struct syslog_channel_s *dev_channel; + /* Initialize the character driver interface */ - g_syslog_dev_channel = syslog_dev_initialize(CONFIG_SYSLOG_DEVPATH, - OPEN_FLAGS, OPEN_MODE); - if (g_syslog_dev_channel == NULL) + dev_channel = syslog_dev_initialize(CONFIG_SYSLOG_DEVPATH, + OPEN_FLAGS, OPEN_MODE); + if (dev_channel == NULL) { return NULL; } /* Use the character driver as the SYSLOG channel */ - if (syslog_channel(g_syslog_dev_channel) != OK) + if (syslog_channel(dev_channel) != OK) { - syslog_dev_uninitialize(g_syslog_dev_channel); - g_syslog_dev_channel = NULL; + syslog_dev_uninitialize(dev_channel); + dev_channel = NULL; } - return g_syslog_dev_channel; + return dev_channel; } #endif /* CONFIG_SYSLOG_CHAR */ diff --git a/drivers/syslog/syslog_filechannel.c b/drivers/syslog/syslog_filechannel.c index ddc27aa0fd..a5cd35fbe5 100644 --- a/drivers/syslog/syslog_filechannel.c +++ b/drivers/syslog/syslog_filechannel.c @@ -49,14 +49,6 @@ #define OPEN_FLAGS (O_WRONLY | O_CREAT | O_APPEND) #define OPEN_MODE (S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR) -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Handle to the SYSLOG channel */ - -FAR static struct syslog_channel_s *g_syslog_file_channel; - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -175,6 +167,8 @@ end: FAR struct syslog_channel_s *syslog_file_channel(FAR const char *devpath) { + FAR struct syslog_channel_s *file_channel; + /* Reset the default SYSLOG channel so that we can safely modify the * SYSLOG device. This is an atomic operation and we should be safe * after the default channel has been selected. @@ -185,13 +179,6 @@ FAR struct syslog_channel_s *syslog_file_channel(FAR const char *devpath) sched_lock(); - /* Uninitialize any driver interface that may have been in place */ - - if (g_syslog_file_channel != NULL) - { - syslog_dev_uninitialize(g_syslog_file_channel); - } - /* Rotate the log file, if needed. */ #if CONFIG_SYSLOG_FILE_ROTATIONS > 0 @@ -206,9 +193,8 @@ FAR struct syslog_channel_s *syslog_file_channel(FAR const char *devpath) /* Then initialize the file interface */ - g_syslog_file_channel = syslog_dev_initialize(devpath, OPEN_FLAGS, - OPEN_MODE); - if (g_syslog_file_channel == NULL) + file_channel = syslog_dev_initialize(devpath, OPEN_FLAGS, OPEN_MODE); + if (file_channel == NULL) { goto errout_with_lock; } @@ -217,15 +203,15 @@ FAR struct syslog_channel_s *syslog_file_channel(FAR const char *devpath) * screwed. */ - if (syslog_channel(g_syslog_file_channel) != OK) + if (syslog_channel(file_channel) != OK) { - syslog_dev_uninitialize(g_syslog_file_channel); - g_syslog_file_channel = NULL; + syslog_dev_uninitialize(file_channel); + file_channel = NULL; } errout_with_lock: sched_unlock(); - return g_syslog_file_channel; + return file_channel; } #endif /* CONFIG_SYSLOG_FILE */