This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit c70b43a5f5570461732063ea831b7942ce9d91e6 Author: Marco Casaroli <[email protected]> AuthorDate: Sun Nov 8 18:04:25 2026 +0100 libc/syslog: Keep syslog() and vsyslog() with CONFIG_SYSLOG_TO_SCHED_NOTE. With CONFIG_SYSLOG_TO_SCHED_NOTE, <syslog.h> defines syslog() and vsyslog() as macros and there are no functions. Code that takes the address of syslog() does not build. For example, METAL_INIT_DEFAULTS of libmetal sets the log handler to syslog, and drivers/virtio/virtio.c, drivers/rpmsg/rpmsg.c and drivers/vhost/vhost.c use it: virtio/virtio.c:96:37: error: 'syslog' undeclared Declare the functions in all configurations, and add lib_syslog_note.c, which sends the message to sched_note_vprintf(). Direct calls still use the macros. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- include/syslog.h | 8 +++-- libs/libc/syslog/CMakeLists.txt | 4 +++ libs/libc/syslog/Make.defs | 4 +++ libs/libc/syslog/lib_syslog_note.c | 72 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 2 deletions(-) diff --git a/include/syslog.h b/include/syslog.h index f57a0a79fda..da2b4856f28 100644 --- a/include/syslog.h +++ b/include/syslog.h @@ -215,11 +215,15 @@ void closelog(void); * ****************************************************************************/ -#ifndef CONFIG_SYSLOG_TO_SCHED_NOTE 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); -#else + +/* With CONFIG_SYSLOG_TO_SCHED_NOTE, these macros replace the calls. The + * functions remain for code that takes their address. + */ + +#ifdef CONFIG_SYSLOG_TO_SCHED_NOTE # define syslog(priority, fmt, ...) \ sched_note_printf(NOTE_TAG_LOG + priority, fmt, ##__VA_ARGS__) # define vsyslog(priority, fmt, ap) \ diff --git a/libs/libc/syslog/CMakeLists.txt b/libs/libc/syslog/CMakeLists.txt index f9862c40955..257af30edf2 100644 --- a/libs/libc/syslog/CMakeLists.txt +++ b/libs/libc/syslog/CMakeLists.txt @@ -29,3 +29,7 @@ endif() if(CONFIG_SYSLOG_NONE) target_sources(c PRIVATE lib_syslog_none.c) endif() + +if(CONFIG_SYSLOG_TO_SCHED_NOTE) + target_sources(c PRIVATE lib_syslog_note.c) +endif() diff --git a/libs/libc/syslog/Make.defs b/libs/libc/syslog/Make.defs index 866dceaa7c2..92bf1a56439 100644 --- a/libs/libc/syslog/Make.defs +++ b/libs/libc/syslog/Make.defs @@ -32,6 +32,10 @@ ifeq ($(CONFIG_SYSLOG_NONE),y) CSRCS += lib_syslog_none.c endif +ifeq ($(CONFIG_SYSLOG_TO_SCHED_NOTE),y) +CSRCS += lib_syslog_note.c +endif + # Add the syslog directory to the build DEPPATH += --dep-path syslog diff --git a/libs/libc/syslog/lib_syslog_note.c b/libs/libc/syslog/lib_syslog_note.c new file mode 100644 index 00000000000..3e1c1ae10e0 --- /dev/null +++ b/libs/libc/syslog/lib_syslog_note.c @@ -0,0 +1,72 @@ +/**************************************************************************** + * libs/libc/syslog/lib_syslog_note.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdarg.h> +#include <syslog.h> + +#include <nuttx/sched_note.h> + +/* Define the functions, not the macros of <syslog.h> */ + +#undef syslog +#undef vsyslog + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: syslog/vsyslog + * + * Description: + * syslog() and vsyslog() for CONFIG_SYSLOG_TO_SCHED_NOTE. Direct calls + * use the macros of <syslog.h>; these functions are for code that takes + * the address of syslog() or vsyslog(). + * + ****************************************************************************/ + +void vsyslog(int priority, FAR const IPTR char *fmt, va_list ap) +{ + va_list copy; + + /* sched_note_vprintf() takes the address of its va_list. Where va_list + * is an array type (x86_64), a va_list parameter is a pointer, so give + * it a local copy. + */ + + va_copy(copy, ap); + sched_note_vprintf(NOTE_TAG_LOG + priority, fmt, copy); + va_end(copy); +} + +void syslog(int priority, FAR const IPTR char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vsyslog(priority, fmt, ap); + va_end(ap); +}
