syslog() will now automatically redirect output to lowsyslog() if called from an interrupt handler

This commit is contained in:
Gregory Nutt
2016-06-16 19:57:06 -06:00
parent 46de4a5779
commit ea8241027e
2 changed files with 43 additions and 4 deletions
+10
View File
@@ -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 */
+33 -4
View File
@@ -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;