casaroli opened a new pull request, #21420: URL: https://github.com/apache/nuttx/pull/21420
## Summary `setlogmask()` selects the messages for all syslog channels together, and a channel gets only the bytes of a message, not its priority. Thus a system cannot show only the urgent messages on the console while the RAMLOG keeps all of them. To turn the console channel off is not a solution: the assertion and crash reports also go through the syslog channels (`_alert()` is `syslog(LOG_ALERT, ...)`). **drivers/syslog: Add the blank lines that nxstyle asks for.** Two blank lines after declarations in `syslog_channel.c`, so that the whole file passes nxstyle. No change of the code. **drivers/syslog: Let a channel drop messages by priority.** - The new option `SYSLOG_DROPMASK` (default n) gives `struct syslog_channel_s` the field `sc_dropmask`: an OR of `LOG_MASK()` values, the priorities that the channel does not write. Zero (the value of every channel that does not set it) writes all messages. - `nx_vsyslog()` (both formats) gives the priority of the message to the syslog stream, and the stream writes with the new `syslog_write_priority()`. `syslog_write_foreach()` skips a channel whose mask has the bit of the priority. A channel that drops a message counts as a full write, so the write does not return `-EIO` when all channels drop the message. - Output without a priority goes to all channels, as before: `syslog_write()`, the interrupt buffer, and the other users of the raw stream (note dumps, gdbstub). - The new option `SYSLOG_CONSOLE_LEVEL` (0..7, default 7, depends on `SYSLOG_DROPMASK`) sets the mask of the console channels (`SYSLOG_DEFAULT` and `SYSLOG_CONSOLE`): they write only the messages of this priority and of the more urgent ones. **Documentation/syslog: Describe the channel priorities.** A new section "SYSLOG Channel Priorities" and the two options in the configuration list. ## Impact - Without `SYSLOG_DROPMASK` (the default), the structures do not change and the code is the same as before, except one more argument to the internal `syslog_write_foreach()`. Size of `nuttx` (text, data and bss), master 6569424cfa6 and this PR: text +8 B on lm3s6965-ek:qemu-flat and on lm3s6965-ek:qemu-protected, data and bss +0. With `SYSLOG_DROPMASK=y`: text +64 B (flat) and +56 B (protected). - With `SYSLOG_DROPMASK=y`, `struct syslog_channel_s` has one more byte and `struct lib_syslograwstream_s` one more `int`. Channels with positional initializers do not change: the new last field is 0. - With `SYSLOG_INTBUFFER`, the messages that interrupt handlers put into the interrupt buffer have no priority when they are written, so they go to all channels (documented). - The same in flat, protected and kernel builds (the syslog channels are kernel code in all of them); no architecture code. No change of an existing interface. ## Testing Test program `syslogtest.c` (POSIX only): `syslog()` with each priority from `LOG_EMERG` to `LOG_DEBUG` reaches the RAMLOG (`/dev/kmsg`); a priority that `setlogmask()` removed does not; the facility bits do not change the priority; a 600-byte message is one line. The program prints the markers that the console must show and must not show; a script compares them with the console output. qemu-armv8a:knsh (kernel build, HVF) with `RAMLOG`, `RAMLOG_SYSLOG` (`/dev/kmsg`), `SYSLOG_MAX_CHANNELS=2`, `SYSLOG_DEFAULT`, `SYSLOG_DROPMASK` and `SYSLOG_CONSOLE_LEVEL` 2 or 7: | Case | master 6569424cfa6 | this PR, level 2 | this PR, level 7 | |---|---|---|---| | `pri-emerg` .. `pri-debug`: each message in the RAMLOG | PASS | PASS | PASS | | `mask`, `facility`, `long` | PASS | PASS | PASS | | console shows `LOG_EMERG`, `LOG_ALERT`, `LOG_CRIT` | yes | yes | yes | | console does not show the 6 messages of `LOG_ERR` .. `LOG_DEBUG` (one with `LOG_USER`) | FAIL (6 shown) | PASS (0 shown) | 6 shown (as master) | On master the options do not exist, so the console writes every message. qemu-armv8a:nsh (flat) with the same options: the same results as on knsh (master 6 shown, this PR 0 shown), also with `SYSLOG_BUFFER`, `SYSLOG_INTBUFFER` and `SYSLOG_IOCTL`. ostest exits with status 0 on qemu-armv8a:knsh and qemu-armv8a:nsh, on master and with this PR. Builds with `-Werror`, all OK without new warnings: qemu-armv8a:knsh, qemu-armv8a:nsh, rv-virt:knsh64, rv-virt:pnsh64 (protected), qemu-armv7a:knsh, qemu-intel64:knsh_romfs, qemu-intel64:earlyfb (`CONSOLE_SYSLOG`), esp32s3-devkit:knsh, sim:nsh (macOS, clang), lm3s6965-ek:qemu-protected. With `SYSLOG_DROPMASK` and a level below 7: qemu-armv8a:knsh with the RAMLOG channel; qemu-armv8a:knsh with `SYSLOG_CONSOLE` instead of `SYSLOG_DEFAULT`; qemu-armv8a:nsh with the RAMLOG channel, `SYSLOG_INTBUFFER`, `SYSLOG_IOCTL`, `SYSLOG_BUFFER` and `SYSLOG_CHARDEV`; qemu-armv8a:nsh with `SYSLOG_IOCTL` and `SYSLOG_CRLF` on and off (the three layouts of the default channel initializer); rv-virt:pnsh64 with the RAMLOG channel, `SYSLOG_RFC5424`, `SYSLOG_TIMESTAMP` and `SYSLOG_PROCESSID`; sim:nsh with the RAMLOG channel; lm3s6965-ek:qemu-protected; nucleo-l432kc:nsh. `tools/checkpatch.sh -c -u -m -g` passes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
