Repository navigation
libs/libc/syslog: Implement openlog() and closelog(). - #21128
Merged
Merged
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
Contributor
Author
Done. |
casaroli
force-pushed
the
fb-openlog-functions-up
branch
from
October 29, 2026 17:51
4f77204 to
b1022d8
Compare
|
casaroli
marked this pull request as ready for review
October 30, 2026 12:25
casaroli
force-pushed
the
fb-openlog-functions-up
branch
from
October 30, 2026 17:38
b1022d8 to
1fb6b3d
Compare
casaroli
force-pushed
the
fb-openlog-functions-up
branch
from
October 31, 2026 10:55
1fb6b3d to
c9bfd8d
Compare
xiaoxiang781216
previously approved these changes
Oct 31, 2026
Contributor
|
@casaroli please fix the conflict |
casaroli
force-pushed
the
fb-openlog-functions-up
branch
from
November 1, 2026 09:09
c9bfd8d to
4fce774
Compare
casaroli
force-pushed
the
fb-openlog-functions-up
branch
from
November 1, 2026 12:58
4fce774 to
bc3491f
Compare
xiaoxiang781216
previously approved these changes
Nov 1, 2026
The ihm07m1_f32 (FOC motor control) configuration fills the 64 KiB flash of the STM32F302R8: master leaves 244 bytes free, and the ident of openlog() in the syslog header and the LOG_PERROR output of vsyslog() need 304 bytes more (Arm GNU 13.2). Enable CONFIG_LTO_FULL, as ihm07m1_b16 does since 16df6dc. The image is then 56412 bytes with make and 56387 bytes with CMake. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
The text of imx93-evk:bootloader ends 456 bytes below a 4 KiB boundary. .vector and .rodata are aligned to 4 KiB in ocramboot.ld, so 464 more bytes of text move .rodata up by 4 KiB and it overflows ocram by 624 bytes. The next commit (openlog() and closelog()) adds 464 bytes of syslog code. Disable the getprime test, as 30503f8 did for the work queues. The text then has 680 bytes left before the boundary. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
<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 header that it already writes, so syslog() needs no buffer and no lock. nx_vsyslog() now writes the header in every configuration, and reads the settings from the task information of the running task. So the messages that the OS prints while the process runs (in a system call, for example) get the ident too; messages from an interrupt handler have none. In PROTECTED and KERNEL builds the task information is in user memory: the kernel reads at most 31 characters of the ident. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
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 <[email protected]>
casaroli
force-pushed
the
fb-openlog-functions-up
branch
from
November 1, 2026 18:50
bc3491f to
9503de8
Compare
acassis
approved these changes
Nov 1, 2026
xiaoxiang781216
approved these changes
Nov 2, 2026
This was referenced Nov 13, 2026
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 enables
CONFIG_LTO_FULLon nucleo-f302r8:ihm07m1_f32, as 16df6dc did for ihm07m1_b16: the configuration has 244 bytes of flash free on master, and this PR needs 304 bytes more. The second commit disables the getprime test in imx93-evk:bootloader, as 30503f8 did for its work queues: the text of that configuration ends 456 bytes below a 4 KiB boundary (.vectorand.rodataare aligned to 4 KiB inocramboot.ld), this PR adds 464 bytes, so.rodatamoves up 4 KiB and overflows ocram by 624 bytes. The third 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 (also withoutva_copy). 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(), at the end of the header that it already writes (now in every configuration), sosyslog()needs no buffer and no lock.nx_vsyslog()reads the settings from the task information of the running task, so the messages that the OS prints while the process runs get the ident too; messages from interrupt handlers have none. In PROTECTED and KERNEL builds the task information is in user memory: the kernel reads at most 31 characters of the ident. The fourth 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). The same results after the review changes (ident in the
nx_vsyslog()header), on master 1be6287, and after the second review round, on master c7bde63.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_RFC5424and with all header options (timestamp, process ID, priority, process name, color) (flat, arm64), and sim:lua (before the review changes; 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.Size (GCC 13.2, master c7bde63): +308 bytes of flash on nucleo-g431kb:nsh, +324 on b-g431b-esc1:nsh, +296 on lm3s6965-ek:qemu-flat. These configurations are full on master: with this PR, nucleo-g431kb:nsh and b-g431b-esc1:nsh overflow by 124 and 168 bytes (#21219 trims them), and lm3s6965-ek:qemu-flat overflows in CI by 68 to 76 bytes. stm32f334-disco:buckboost: 63724 B of 65536. nucleo-f302r8:ihm07m1_f32 overflows by 60 bytes (make) and 56 bytes (CMake) without LTO; with LTO it uses 56412 bytes (make) and 56387 bytes (CMake) of 65536, without warnings, and
make savedefconfiggives the same defconfig (the same numbers on master 8fef4b9). imx93-evk:bootloader (GCC 13.2, master 8fef4b9): master has 175672 bytes of text and.rodataends at 0x204df230; with this PR 175448 bytes and 0x204df118, below the end of ocram at 0x204e0000, with 680 bytes of text left before the next 4 KiB boundary.tools/checkpatch.sh -c -u -m -gpasses.