syslog: Fix in file channel initialization.
This commit is contained in:
parent
62e1821ca0
commit
0c41611429
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue