mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 01:05:54 +08:00
syslog() will now automatically redirect output to lowsyslog() if called from an interrupt handler
This commit is contained in:
@@ -47,6 +47,15 @@
|
|||||||
#include "syslog/syslog.h"
|
#include "syslog/syslog.h"
|
||||||
|
|
||||||
#if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_SYSLOG)
|
#if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_SYSLOG)
|
||||||
|
/* The low-level SYSLOG functions can be used only if we have access to
|
||||||
|
* either the low-level serial interface, up_putc(), and to syslog_putc()
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(CONFIG_BUILD_FLAT) || defined (__KERNEL__)
|
||||||
|
/* The low-level serial interface, up_putc(), and syslog_putc() are only
|
||||||
|
* available in the FLAT build or during the kernel pass of the protected or
|
||||||
|
* kernel two pass builds.
|
||||||
|
*/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
@@ -136,4 +145,5 @@ int lowsyslog(int priority, FAR const IPTR char *fmt, ...)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_BUILD_FLAT) || __KERNEL__ */
|
||||||
#endif /* CONFIG_ARCH_LOWPUTC || CONFIG_SYSLOG */
|
#endif /* CONFIG_ARCH_LOWPUTC || CONFIG_SYSLOG */
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
#include <nuttx/init.h>
|
#include <nuttx/init.h>
|
||||||
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/clock.h>
|
#include <nuttx/clock.h>
|
||||||
#include <nuttx/streams.h>
|
#include <nuttx/streams.h>
|
||||||
|
|
||||||
@@ -162,13 +163,41 @@ int vsyslog(int priority, FAR const IPTR char *fmt, va_list ap)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
/* Check if this priority is enabled */
|
#if !defined(CONFIG_SYSLOG) && CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
|
/* Are we are generating output on stdout? If so, was this function
|
||||||
|
* called from an interrupt handler? We cannot send data to stdout from
|
||||||
|
* an interrupt handler.
|
||||||
|
*/
|
||||||
|
|
||||||
if ((g_syslog_mask & LOG_MASK(priority)) != 0)
|
if (up_interrupt_context())
|
||||||
{
|
{
|
||||||
/* Yes.. let vsylog_internal do the deed */
|
#ifdef CONFIG_ARCH_LOWPUTC
|
||||||
|
/* But the low-level serial interface up_putc() is provided so we may
|
||||||
|
* be able to generate low-level serial output instead.
|
||||||
|
* NOTE: The low-level serial output is not necessarily the same
|
||||||
|
* output destination as stdout!
|
||||||
|
*/
|
||||||
|
|
||||||
ret = vsyslog_internal(fmt, ap);
|
#if defined(CONFIG_BUILD_FLAT) || defined (__KERNEL__)
|
||||||
|
/* lowvsyslog() in only available in the FLAT build or during the
|
||||||
|
* kernel pass of the protected or kernel two pass builds.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ret = lowvsyslog(priority, fmt, ap);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
/* Check if this priority is enabled */
|
||||||
|
|
||||||
|
if ((g_syslog_mask & LOG_MASK(priority)) != 0)
|
||||||
|
{
|
||||||
|
/* Yes.. let vsylog_internal do the deed */
|
||||||
|
|
||||||
|
ret = vsyslog_internal(fmt, ap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user