SYSLOG channel add functions return handle to the channel.

This commit is contained in:
Fotis Panagiotopoulos 2021-06-03 13:24:49 +03:00 committed by Xiang Xiao
parent 038941b11d
commit e189d83e11
9 changed files with 47 additions and 39 deletions

View File

@ -392,7 +392,8 @@ mounting of the file systems.
The interface ``syslog_file_channel()`` is used to configure the The interface ``syslog_file_channel()`` is used to configure the
SYSLOG file channel: SYSLOG file channel:
.. c:function:: int syslog_file_channel(FAR const char *devpath); .. c:function:: FAR struct syslog_channel_s *
syslog_file_channel(FAR const char *devpath);
Configure to use a file in a mounted file system Configure to use a file in a mounted file system
at ``devpath`` as the SYSLOG channel. at ``devpath`` as the SYSLOG channel.
@ -423,8 +424,8 @@ SYSLOG file channel:
``syslog_file_channel()`` will create the file. ``syslog_file_channel()`` will create the file.
:return: :return:
Zero (``OK``) is returned on success; a A pointer to the new syslog channel; ``NULL`` is returned
negated ``errno`` value is returned on any failure. on any failure.
References: ``drivers/syslog/syslog_filechannel.c``, References: ``drivers/syslog/syslog_filechannel.c``,
``drivers/syslog/syslog_device.c``, and ``drivers/syslog/syslog_device.c``, and

View File

@ -96,11 +96,12 @@ int board_app_initialize(uintptr_t arg)
nxsig_usleep(CONFIG_CLICKER2_STM32_SYSLOG_FILE_DELAY * 1000); nxsig_usleep(CONFIG_CLICKER2_STM32_SYSLOG_FILE_DELAY * 1000);
ret = syslog_file_channel(CONFIG_CLICKER2_STM32_SYSLOG_FILE_PATH); FAR struct syslog_channel_s *channel;
if (ret < 0) channel = syslog_file_channel(CONFIG_CLICKER2_STM32_SYSLOG_FILE_PATH);
if (channel == NULL)
{ {
syslog(LOG_ERR, "ERROR: syslog_file_channel() failed: %d\n", ret); syslog(LOG_ERR, "ERROR: syslog_file_channel() failed\n");
return ret; return -EINVAL;
} }
#endif #endif

View File

@ -372,7 +372,7 @@ SYSLOG Channel Options
Prototype: Prototype:
#ifdef CONFIG_SYSLOG_FILE #ifdef CONFIG_SYSLOG_FILE
int syslog_file_channel(FAR const char *devpath); FAR struct syslog_channel_s *syslog_file_channel(FAR const char *devpath);
#endif #endif
Description: Description:
@ -406,8 +406,7 @@ SYSLOG Channel Options
Returned Value: Returned Value:
Zero (OK) is returned on success; a negated errno value is returned on A pointer to the new SYSLOG channel; NULL is returned on any failure.
any failure.
References: drivers/syslog/syslog_filechannel.c, References: drivers/syslog/syslog_filechannel.c,
drivers/syslog/syslog_device.c, and include/nuttx/syslog/syslog.h. drivers/syslog/syslog_device.c, and include/nuttx/syslog/syslog.h.

View File

@ -125,13 +125,12 @@ void syslog_dev_uninitialize(FAR struct syslog_channel_s *channel);
* None * None
* *
* Returned Value: * Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on * A pointer to the new SYSLOG channel; NULL is returned on any failure.
* any failure.
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_SYSLOG_CHAR #ifdef CONFIG_SYSLOG_CHAR
int syslog_dev_channel(void); FAR struct syslog_channel_s *syslog_dev_channel(void);
#endif #endif
/**************************************************************************** /****************************************************************************
@ -156,13 +155,12 @@ int syslog_dev_channel(void);
* None * None
* *
* Returned Value: * Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on * A pointer to the new SYSLOG channel; NULL is returned on any failure.
* any failure.
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_SYSLOG_CONSOLE #ifdef CONFIG_SYSLOG_CONSOLE
int syslog_console_channel(void); FAR struct syslog_channel_s *syslog_console_channel(void);
#endif #endif
/**************************************************************************** /****************************************************************************

View File

@ -75,12 +75,11 @@ FAR static struct syslog_channel_s *g_syslog_console_channel;
* None * None
* *
* Returned Value: * Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on * A pointer to the new SYSLOG channel; NULL is returned on any failure.
* any failure.
* *
****************************************************************************/ ****************************************************************************/
int syslog_console_channel(void) FAR struct syslog_channel_s *syslog_console_channel(void)
{ {
/* Initialize the character driver interface */ /* Initialize the character driver interface */
@ -88,12 +87,18 @@ int syslog_console_channel(void)
OPEN_FLAGS, OPEN_MODE); OPEN_FLAGS, OPEN_MODE);
if (g_syslog_console_channel == NULL) if (g_syslog_console_channel == NULL)
{ {
return -ENOMEM; return NULL;
} }
/* Use the character driver as the SYSLOG channel */ /* Use the character driver as the SYSLOG channel */
return syslog_channel(g_syslog_console_channel); if (syslog_channel(g_syslog_console_channel) != OK)
{
syslog_dev_uninitialize(g_syslog_console_channel);
g_syslog_console_channel = NULL;
}
return g_syslog_console_channel;
} }
#endif /* CONFIG_SYSLOG_CONSOLE */ #endif /* CONFIG_SYSLOG_CONSOLE */

View File

@ -72,12 +72,11 @@ FAR static struct syslog_channel_s *g_syslog_dev_channel;
* None * None
* *
* Returned Value: * Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on * A pointer to the new SYSLOG channel; NULL is returned on any failure.
* any failure.
* *
****************************************************************************/ ****************************************************************************/
int syslog_dev_channel(void) FAR struct syslog_channel_s *syslog_dev_channel(void)
{ {
/* Initialize the character driver interface */ /* Initialize the character driver interface */
@ -85,12 +84,18 @@ int syslog_dev_channel(void)
OPEN_FLAGS, OPEN_MODE); OPEN_FLAGS, OPEN_MODE);
if (g_syslog_dev_channel == NULL) if (g_syslog_dev_channel == NULL)
{ {
return -ENOMEM; return NULL;
} }
/* Use the character driver as the SYSLOG channel */ /* Use the character driver as the SYSLOG channel */
return syslog_channel(g_syslog_dev_channel); if (syslog_channel(g_syslog_dev_channel) != OK)
{
syslog_dev_uninitialize(g_syslog_dev_channel);
g_syslog_dev_channel = NULL;
}
return g_syslog_dev_channel;
} }
#endif /* CONFIG_SYSLOG_CHAR */ #endif /* CONFIG_SYSLOG_CHAR */

View File

@ -85,15 +85,12 @@ FAR static struct syslog_channel_s *g_syslog_file_channel;
* file. * file.
* *
* Returned Value: * Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on * A pointer to the new SYSLOG channel; NULL is returned on any failure.
* any failure.
* *
****************************************************************************/ ****************************************************************************/
int syslog_file_channel(FAR const char *devpath) FAR struct syslog_channel_s *syslog_file_channel(FAR const char *devpath)
{ {
int ret;
/* 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.
@ -117,7 +114,6 @@ int syslog_file_channel(FAR const char *devpath)
OPEN_MODE); OPEN_MODE);
if (g_syslog_file_channel == NULL) if (g_syslog_file_channel == NULL)
{ {
ret = -ENOMEM;
goto errout_with_lock; goto errout_with_lock;
} }
@ -125,11 +121,15 @@ int syslog_file_channel(FAR const char *devpath)
* screwed. * screwed.
*/ */
ret = syslog_channel(g_syslog_file_channel); if (syslog_channel(g_syslog_file_channel) != OK)
{
syslog_dev_uninitialize(g_syslog_file_channel);
g_syslog_file_channel = NULL;
}
errout_with_lock: errout_with_lock:
sched_unlock(); sched_unlock();
return ret; return g_syslog_file_channel;
} }
#endif /* CONFIG_SYSLOG_FILE */ #endif /* CONFIG_SYSLOG_FILE */

View File

@ -72,11 +72,11 @@ int syslog_initialize(void)
#if defined(CONFIG_SYSLOG_CHAR) #if defined(CONFIG_SYSLOG_CHAR)
/* Enable use of a character device as the SYSLOG device */ /* Enable use of a character device as the SYSLOG device */
ret = syslog_dev_channel(); syslog_dev_channel();
#elif defined(CONFIG_SYSLOG_CONSOLE) #elif defined(CONFIG_SYSLOG_CONSOLE)
/* Use the console device as the SYSLOG device */ /* Use the console device as the SYSLOG device */
ret = syslog_console_channel(); syslog_console_channel();
#endif #endif
#ifdef CONFIG_RAMLOG_SYSLOG #ifdef CONFIG_RAMLOG_SYSLOG

View File

@ -233,13 +233,12 @@ int syslog_initialize(void);
* file. * file.
* *
* Returned Value: * Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on * A pointer to the new SYSLOG channel; NULL is returned on any failure.
* any failure.
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_SYSLOG_FILE #ifdef CONFIG_SYSLOG_FILE
int syslog_file_channel(FAR const char *devpath); FAR struct syslog_channel_s *syslog_file_channel(FAR const char *devpath);
#endif #endif
/**************************************************************************** /****************************************************************************