Skip to content

libs/libc/syslog: Implement openlog() and closelog(). - #21128

Merged
xiaoxiang781216 merged 4 commits into
apache:masterfrom
casaroli:fb-openlog-functions-up
Nov 2, 2026
Merged

xiaoxiang781216 merged 4 commits into
apache:masterfrom
casaroli:fb-openlog-functions-up

Conversation

@casaroli

@casaroli casaroli commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

<syslog.h> defined openlog() as a macro that is a block of statements and closelog() 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_FULL on 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 (.vector and .rodata are aligned to 4 KiB in ocramboot.ld), this PR adds 464 bytes, so .rodata moves 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 get ident: before them, ident[pid]: with LOG_PID. With LOG_PERROR, syslog() writes the message to stderr too (also without va_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 in nx_vsyslog(), at the end of the header that it already writes (now in every configuration), so syslog() 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 in Documentation/standards/posix.rst and 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() or closelog() macro before <syslog.h> does not compile any more, because the macro now expands inside the declaration. nuttx-apps' interpreters/luamodules/luasyslog did 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 of openlog(); log: syslog() after openlog() and after closelog()), compiled against the export of qemu-armv8a:knsh (kernel build) and run under QEMU (HVF):

master aeab6fb this PR
openlog does not compile (macro "closelog" passed 1 arguments, expected identifier before '{') expr PASS, decl PASS, log PASS

Test program openlog2.c (stderr is a pipe, the test reads what syslog() wrote), qemu-armv8a:knsh (kernel) and qemu-armv8a:nsh (flat, builtin app), both with CONFIG_PIPES: ident olt: one 1, LOG_PID olt[5]: two, a message with its own newline, an ident of 40 characters cut to 31, the settings after closelog(), no ident: PASS; flat only: a new task group has its own settings (its openlog() does not change the ident of the parent): PASS. The console shows the same lines: the prefix that nx_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_RFC5424 and 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 and openlog()/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 savedefconfig gives the same defconfig (the same numbers on master 8fef4b9). imx93-evk:bootloader (GCC 13.2, master 8fef4b9): master has 175672 bytes of text and .rodata ends 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 -g passes.

@cederom

cederom commented Oct 29, 2026

Copy link
Copy Markdown
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
casaroli force-pushed the fb-openlog-functions-up branch from be2f335 to 4f77204 Compare October 29, 2026 15:57
@casaroli casaroli changed the title libs/libc/syslog: Make openlog() and closelog() functions. libs/libc/syslog: Implement openlog() and closelog(). Oct 29, 2026
acassis
acassis previously approved these changes Oct 29, 2026
Comment thread libs/libc/syslog/lib_openlog.c Resolved
Comment thread libs/libc/syslog/lib_syslog.c Resolved
Comment thread libs/libc/syslog/lib_syslog.c Resolved
@casaroli

Copy link
Copy Markdown
Contributor Author

Either we support them and their functionality is operational or not at all :-)

Done.

@github-actions github-actions Bot added Area: Documentation Improvements or additions to documentation Size: S The size of the change in this PR is small labels Oct 29, 2026
@casaroli
casaroli force-pushed the fb-openlog-functions-up branch from 4f77204 to b1022d8 Compare October 29, 2026 17:51
@github-actions github-actions Bot added Size: M The size of the change in this PR is medium Area: Drivers Drivers issues and removed Size: S The size of the change in this PR is small Area: Documentation Improvements or additions to documentation labels Oct 29, 2026
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

arduino-mega2560

  • flash: .data +25 B, .text +508 B (+0.8%, 66,037 B / 262,144 B, total: 25% used)
  • sram: .bss +32 B, .data +25 B (+2.1%, 2,795 B / 8,192 B, total: 34% used)

esp32-devkitc

  • ROM: .flash.rodata +24 B, .flash.text +360 B (+0.3%, 128,776 B / 4,194,272 B, total: 3% used)
  • dram0_0_seg: .dram0.bss +32 B (+0.3%, 10,024 B / 180,736 B, total: 6% used)
  • drom0_0_seg: .flash.rodata +24 B (+0.2%, 13,916 B / 4,194,272 B, total: 0% used)
  • irom0_0_seg: .flash.text +360 B (+0.4%, 94,632 B / 3,342,304 B, total: 3% used)

hifive1-revb

  • flash: .text +300 B (+0.4%, 85,388 B / 4,194,304 B, total: 2% used)
  • sram: .bss +32 B (+0.8%, 3,956 B / 16,384 B, total: 24% used)

mirtoo

  • kseg0_progmem: .text +544 B (+0.8%, 67,904 B / 131,072 B, total: 52% used)
  • kseg1_datamem: .bss +48 B (+1.9%, 2,600 B / 32,256 B, total: 8% used)

qemu-armv8a

  • Code: .rodata +24 B, .text.nx_vsyslog +152 B, .text.vsyslog +192 B (+0.1%, 355,652 B)
  • Data: .bss.g_kthread_group +40 B (+0.1%, 77,823 B)

qemu-intel64

  • Code: .text +605 B (+0.0%, 8,689,358 B)
  • Data: .bss +64 B, .rodata +32 B (+0.1%, 125,305 B)

rx65n-rsk2mb

  • RAM: .bss +32 B (+0.5%, 6,682 B / 262,144 B, total: 3% used)
  • ROM: .rodata +20 B, .text +272 B (+0.3%, 90,908 B / 2,097,152 B, total: 4% used)

s698pm-dkit

  • Code: .text +1,072 B (+0.3%, 387,408 B)
  • Data: .bss +48 B (+0.4%, 11,931 B)

stm32-nucleo-f103rb

  • flash: .text +312 B (+0.9%, 34,580 B / 131,072 B, total: 26% used)
  • sram: .bss +40 B (+1.7%, 2,460 B / 20,480 B, total: 12% used)

Catch memory regressions in CI with MemBrowse. Free for open source.

@casaroli
casaroli marked this pull request as ready for review October 30, 2026 12:25
@casaroli
casaroli force-pushed the fb-openlog-functions-up branch from b1022d8 to 1fb6b3d Compare October 30, 2026 17:38
Comment thread drivers/syslog/syslog.h Resolved
Comment thread drivers/syslog/syslog.h Resolved
Comment thread drivers/syslog/vsyslog_rfc5424.c Resolved
Comment thread libs/libc/syslog/lib_syslog.c Resolved
Comment thread drivers/syslog/vsyslog.c Resolved
Comment thread drivers/syslog/syslog.h Resolved
@casaroli
casaroli force-pushed the fb-openlog-functions-up branch from 1fb6b3d to c9bfd8d Compare October 31, 2026 10:55
Comment thread libs/libc/syslog/lib_syslog.c Resolved
Comment thread libs/libc/syslog/lib_syslog.c Resolved
Comment thread libs/libc/syslog/lib_syslog.c Resolved
Comment thread drivers/syslog/syslog.h Resolved
Comment thread drivers/syslog/syslog.h Resolved
@acassis

acassis commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

@casaroli please fix the conflict

xiaoxiang781216
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]>
@xiaoxiang781216
xiaoxiang781216 merged commit c6f0108 into apache:master Nov 2, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Board: arm Board: arm64 Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants