diff --git a/libc/syslog/lib_lowsyslog.c b/libc/syslog/lib_lowsyslog.c index 8c9c84c177a..8c4b7ed9596 100644 --- a/libc/syslog/lib_lowsyslog.c +++ b/libc/syslog/lib_lowsyslog.c @@ -47,6 +47,15 @@ #include "syslog/syslog.h" #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 @@ -136,4 +145,5 @@ int lowsyslog(int priority, FAR const IPTR char *fmt, ...) return ret; } +#endif /* CONFIG_BUILD_FLAT) || __KERNEL__ */ #endif /* CONFIG_ARCH_LOWPUTC || CONFIG_SYSLOG */ diff --git a/libc/syslog/lib_syslog.c b/libc/syslog/lib_syslog.c index f6e35b35b56..32087d86f7b 100644 --- a/libc/syslog/lib_syslog.c +++ b/libc/syslog/lib_syslog.c @@ -43,6 +43,7 @@ #include #include +#include #include #include @@ -162,13 +163,41 @@ int vsyslog(int priority, FAR const IPTR char *fmt, va_list ap) { 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;