Repository navigation
Conversation
xiaoxiang781216
previously approved these changes
Oct 29, 2026
Contributor
|
Not sure if this is okay to state that functions are "SUPPORTED" but DOES NOTHING as per proposition, over stating that functions are not implemented. Sounds like cheating :D Either we support them and their functionality is operational or not at all :-) |
casaroli
force-pushed
the
fb-openlog-functions-up
branch
from
October 29, 2026 15:57
be2f335 to
4f77204
Compare
acassis
previously approved these changes
Oct 29, 2026
| * the other builds each task group has its settings in its task_info_s. | ||
| */ | ||
|
|
||
| static struct openlog_s g_openlog; |
Contributor
There was a problem hiding this comment.
why not always put into task tls even for kernel mode
| * such a message goes out without the settings. | ||
| */ | ||
|
|
||
| nxrmutex_lock(&info->ta_lock); |
Contributor
There was a problem hiding this comment.
syslog is called in interrupt context, malloc and mutex need be avoided
| * | ||
| ****************************************************************************/ | ||
|
|
||
| static bool vsyslog_openlog(int priority, FAR const IPTR char *fmt, |
Contributor
There was a problem hiding this comment.
why not do the format in kernel side, so we can avoid malloc and mutex
Contributor
Author
Done. |
<syslog.h> defined openlog() as a macro that is a block of statements and closelog() as an empty macro, and syslog() did not use the ident or the options. Programs that write "(void) openlog(...);" or "(void) closelog();" did not compile (tcp-wrappers' tcpd.c), a program that declares them, or a link test, did not find them, and the messages of a program had no ident. Make them functions of libc, as in musl: openlog() keeps a copy of the ident (up to 31 characters), the options and the facility in the task information of the process (task_info_s.ta_openlog, one per task group), and the messages of the process get "ident: " before them, "ident[pid]: " with LOG_PID. With LOG_PERROR, syslog() writes the message to stderr too. The other options and the facility have no effect: NuttX has no system logger to connect to. closelog() has no descriptor to close; the settings stay, as in musl. The OS adds the ident in nx_vsyslog(), in the stream that already writes the header, so syslog() needs no buffer and no lock. vsyslog() of the programs sets the internal flag SYSLOG_OPENLOG in the priority, and only then nx_vsyslog() reads the settings: during a syslog() call of the process, when its task information is in memory. The messages of the OS have no ident, and neither have messages from an interrupt handler. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
openlog() and closelog() are now functions of libc, and syslog() uses the ident and the options of openlog(). Mark them as supported in the POSIX table, and describe them on the logging page. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
casaroli
force-pushed
the
fb-openlog-functions-up
branch
from
October 29, 2026 17:51
4f77204 to
b1022d8
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
<syslog.h>definedopenlog()as a macro that is a block of statements andcloselog()as an empty macro. Programs that write(void) openlog(...);or(void) closelog();did not compile (tcp-wrappers'tcpd.c, for example), and a program that declares them itself, takes their address, or a configure link test did not find them.The first commit makes them functions of libc, as in musl:
openlog()keeps a copy of the ident (up to 31 characters), the options and the facility in the task information of the process (task_info_s.ta_openlog, one per task group, in every build mode), and the messages of the process getident:before them,ident[pid]:withLOG_PID. WithLOG_PERROR,syslog()writes the message to stderr too. The other options and the facility have no effect (NuttX has no system logger to connect to);closelog()has no descriptor to close, and the settings stay, as in musl. The OS adds the ident innx_vsyslog(), in the stream that already writes the header, sosyslog()needs no buffer and no lock:vsyslog()of the programs sets the internal flagSYSLOG_OPENLOGin the priority, and only thennx_vsyslog()reads the settings, during asyslog()call of that process. Messages of the OS and from interrupt handlers have no ident. The second commit describes them inDocumentation/standards/posix.rstand on the logging page.Impact
Two new libc functions; the two macros are gone. The same in flat, protected and kernel builds; nothing per architecture. A file that defines its own
openlog()orcloselog()macro before<syslog.h>does not compile any more, because the macro now expands inside the declaration. nuttx-apps'interpreters/luamodules/luasyslogdid that (on the command line); apache/nuttx-apps#3939 removes those macros and works with both the old and the new<syslog.h>, so it must merge first (sim:lua builds luasyslog).Testing
Test program
openlog.c(expr:(void) openlog(...)and(void) closelog()compile;decl: the program declares both itself and takes the address ofopenlog();log:syslog()afteropenlog()and aftercloselog()), compiled against the export of qemu-armv8a:knsh (kernel build) and run under QEMU (HVF):openlogTest program
openlog2.c(stderr is a pipe, the test reads whatsyslog()wrote), qemu-armv8a:knsh (kernel) and qemu-armv8a:nsh (flat, builtin app), both withCONFIG_PIPES: identolt: one 1, LOG_PIDolt[5]: two, a message with its own newline, an ident of 40 characters cut to 31, the settings aftercloselog(), no ident: PASS; flat only: a new task group has its own settings (itsopenlog()does not change the ident of the parent): PASS. The console shows the same lines: the prefix thatnx_vsyslog()adds.ostest exits with status 0 on qemu-armv8a:knsh (kernel) and qemu-armv8a:nsh (flat).
Builds, each without new warnings: stm32f4discovery:nsh (flat, Cortex-M4), lm3s6965-ek:qemu-protected and mps2-an500:knsh (protected, Cortex-M3), rv-virt:knsh64 (kernel, RISC-V), qemu-armv8a:nsh with
CONFIG_SYSLOG_RFC5424(flat, arm64) and sim:lua (macOS host, with luasyslog and the nuttx-apps change). A file with the old luasyslog macros andopenlog()/closelog()calls, compiled against the knsh export: master compiles it, this PR fails ("macro "closelog" passed 1 arguments"); without the macros both compile.tools/checkpatch.sh -c -u -m -gpasses.depends-on: apache/nuttx-apps#3939