syslog: Fix in file channel initialization.

This commit is contained in:
Fotis Panagiotopoulos 2022-01-13 14:45:44 +02:00 committed by Petro Karashchenko
parent 62e1821ca0
commit 0c41611429
3 changed files with 26 additions and 52 deletions

View File

@ -41,14 +41,6 @@
#define OPEN_FLAGS (O_WRONLY) #define OPEN_FLAGS (O_WRONLY)
#define OPEN_MODE (S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR) #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 * 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 *syslog_console_channel(void)
{ {
FAR struct syslog_channel_s *console_channel;
/* Initialize the character driver interface */ /* Initialize the character driver interface */
g_syslog_console_channel = syslog_dev_initialize("/dev/console", console_channel = syslog_dev_initialize("/dev/console",
OPEN_FLAGS, OPEN_MODE); OPEN_FLAGS, OPEN_MODE);
if (g_syslog_console_channel == NULL) if (console_channel == NULL)
{ {
return NULL; return NULL;
} }
/* Use the character driver as the SYSLOG channel */ /* 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); syslog_dev_uninitialize(console_channel);
g_syslog_console_channel = NULL; console_channel = NULL;
} }
return g_syslog_console_channel; return console_channel;
} }
#endif /* CONFIG_SYSLOG_CONSOLE */ #endif /* CONFIG_SYSLOG_CONSOLE */

View File

@ -41,14 +41,6 @@
#define OPEN_FLAGS (O_WRONLY) #define OPEN_FLAGS (O_WRONLY)
#define OPEN_MODE (S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR) #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 * 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 *syslog_dev_channel(void)
{ {
FAR struct syslog_channel_s *dev_channel;
/* Initialize the character driver interface */ /* Initialize the character driver interface */
g_syslog_dev_channel = syslog_dev_initialize(CONFIG_SYSLOG_DEVPATH, dev_channel = syslog_dev_initialize(CONFIG_SYSLOG_DEVPATH,
OPEN_FLAGS, OPEN_MODE); OPEN_FLAGS, OPEN_MODE);
if (g_syslog_dev_channel == NULL) if (dev_channel == NULL)
{ {
return NULL; return NULL;
} }
/* Use the character driver as the SYSLOG channel */ /* 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); syslog_dev_uninitialize(dev_channel);
g_syslog_dev_channel = NULL; dev_channel = NULL;
} }
return g_syslog_dev_channel; return dev_channel;
} }
#endif /* CONFIG_SYSLOG_CHAR */ #endif /* CONFIG_SYSLOG_CHAR */

View File

@ -49,14 +49,6 @@
#define OPEN_FLAGS (O_WRONLY | O_CREAT | O_APPEND) #define OPEN_FLAGS (O_WRONLY | O_CREAT | O_APPEND)
#define OPEN_MODE (S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR) #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 * Private Functions
****************************************************************************/ ****************************************************************************/
@ -175,6 +167,8 @@ end:
FAR struct syslog_channel_s *syslog_file_channel(FAR const char *devpath) 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 /* Reset the default SYSLOG channel so that we can safely modify the
* SYSLOG device. This is an atomic operation and we should be safe * SYSLOG device. This is an atomic operation and we should be safe
* after the default channel has been selected. * 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(); 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. */ /* Rotate the log file, if needed. */
#if CONFIG_SYSLOG_FILE_ROTATIONS > 0 #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 */ /* Then initialize the file interface */
g_syslog_file_channel = syslog_dev_initialize(devpath, OPEN_FLAGS, file_channel = syslog_dev_initialize(devpath, OPEN_FLAGS, OPEN_MODE);
OPEN_MODE); if (file_channel == NULL)
if (g_syslog_file_channel == NULL)
{ {
goto errout_with_lock; goto errout_with_lock;
} }
@ -217,15 +203,15 @@ FAR struct syslog_channel_s *syslog_file_channel(FAR const char *devpath)
* screwed. * screwed.
*/ */
if (syslog_channel(g_syslog_file_channel) != OK) if (syslog_channel(file_channel) != OK)
{ {
syslog_dev_uninitialize(g_syslog_file_channel); syslog_dev_uninitialize(file_channel);
g_syslog_file_channel = NULL; file_channel = NULL;
} }
errout_with_lock: errout_with_lock:
sched_unlock(); sched_unlock();
return g_syslog_file_channel; return file_channel;
} }
#endif /* CONFIG_SYSLOG_FILE */ #endif /* CONFIG_SYSLOG_FILE */