This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 25b649e1c087632f6253c5a7bfdd6cda24e8ed5c Author: anjiahao <[email protected]> AuthorDate: Tue Nov 24 11:20:32 2026 +0800 syslog: filter kernel syslog() by the system wide mask only With the setlogmask() mask kept per process, syslog() called from kernel code was filtered by the mask of whichever task the kernel happened to run in, so one task's setlogmask(LOG_UPTO(LOG_ERR)) could hide the INFO messages of a driver while it served that task. The kernel logs on behalf of the whole system. Add nx_syslog(), which checks only g_syslog_mask, the mask that nx_setlogmask() sets, and map syslog() to it in code built with __KERNEL__. vsyslog() is unchanged. Signed-off-by: anjiahao <[email protected]> Signed-off-by: Bowen Wang <[email protected]> --- drivers/syslog/setlogmask.c | 22 ++++++++++++++++++++++ include/syslog.h | 20 ++++++++++++++++++++ libs/libc/syslog/lib_syslog.c | 4 ++++ 3 files changed, 46 insertions(+) diff --git a/drivers/syslog/setlogmask.c b/drivers/syslog/setlogmask.c index 623ffb5a66d..2fe8d5cd8d0 100644 --- a/drivers/syslog/setlogmask.c +++ b/drivers/syslog/setlogmask.c @@ -26,6 +26,7 @@ #include <nuttx/config.h> +#include <stdarg.h> #include <stdint.h> #include <syslog.h> @@ -113,3 +114,24 @@ int nx_setlogmask(int mask) nxsched_foreach(task_syslogmask, &mask); return oldmask; } + +/**************************************************************************** + * Name: nx_syslog + * + * Description: + * The syslog() of the kernel, see include/syslog.h. Only the system wide + * mask filters it. + * + ****************************************************************************/ + +void nx_syslog(int priority, FAR const IPTR char *fmt, ...) +{ + va_list ap; + + if ((g_syslog_mask & LOG_MASK(LOG_PRI(priority))) != 0) + { + va_start(ap, fmt); + nx_vsyslog(priority, fmt, &ap); + va_end(ap); + } +} diff --git a/include/syslog.h b/include/syslog.h index 43acbc8a534..83a56b60fab 100644 --- a/include/syslog.h +++ b/include/syslog.h @@ -219,6 +219,26 @@ void syslog(int priority, FAR const IPTR char *fmt, ...) syslog_like(2, 3); void vsyslog(int priority, FAR const IPTR char *fmt, va_list ap) syslog_like(2, 0); +/**************************************************************************** + * Name: nx_syslog + * + * Description: + * nx_syslog() is the syslog() of the kernel. The kernel logs on behalf + * of the whole system, not of the task it happens to run in, so it is + * filtered by the system wide mask that nx_setlogmask() sets, not by the + * setlogmask() mask of the current task. + * + ****************************************************************************/ + +#ifdef CONFIG_SYSLOG +void nx_syslog(int priority, FAR const IPTR char *fmt, ...) + syslog_like(2, 3); +# ifdef __KERNEL__ +# define syslog(priority, fmt, ...) \ + nx_syslog(priority, fmt, ##__VA_ARGS__) +# endif +#endif + /* With CONFIG_SYSLOG_TO_SCHED_NOTE, these macros replace the calls. The * functions remain for code that takes their address. */ diff --git a/libs/libc/syslog/lib_syslog.c b/libs/libc/syslog/lib_syslog.c index 6e30cc65a09..2478c013919 100644 --- a/libs/libc/syslog/lib_syslog.c +++ b/libs/libc/syslog/lib_syslog.c @@ -34,6 +34,10 @@ #include <nuttx/syslog/syslog.h> #include <nuttx/tls.h> +/* Define the function, not the kernel macro of <syslog.h> */ + +#undef syslog + /**************************************************************************** * Private Functions ****************************************************************************/
