setlogmask: fix setlogmask behavior according to POSIX standard

POSIX states "If the maskpri argument is 0, the current log mask is
not modified." The current implementation in NuttX doesn't
respect this and thus is in a clear violation with a strict POSIX
compliance rule in The Inviolable Principles of NuttX.

This commit therefore changes the behavior to the expected one. Passing
argument 0 doesn't change the current log mask, but just returns the
old one. Completely disabling logging at runtime is thus not possible,
but you may set the highest priority LOG_EMERG only to disable most of
the messages. Default can still be set to no logging with
CONFIG_SYSLOG_DEFAULT_MASK configuration option.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
This commit is contained in:
Michal Lenc 2025-04-28 17:26:59 +02:00 committed by CeDeROM
parent c84f7c630f
commit eeb4a0de83
2 changed files with 7 additions and 10 deletions

View file

@ -232,10 +232,6 @@ void vsyslog(int priority, FAR const IPTR char *fmt, va_list ap)
* to a priority p is LOG_MASK(p); LOG_UPTO(p) provides the mask of all
* priorities in the above list up to and including p.
*
* Per OpenGroup.org "If the maskpri argument is 0, the current log mask
* is not modified." In this implementation, the value zero is permitted
* in order to disable all syslog levels.
*
* NOTE: setlogmask is not a thread-safe, re-entrant function. Concurrent
* use of setlogmask() will have undefined behavior.
*

View file

@ -55,10 +55,6 @@ uint8_t g_syslog_mask = CONFIG_SYSLOG_DEFAULT_MASK;
* to a priority p is LOG_MASK(p); LOG_UPTO(p) provides the mask of all
* priorities in the above list up to and including p.
*
* Per OpenGroup.org "If the maskpri argument is 0, the current log mask
* is not modified." In this implementation, the value zero is permitted
* in order to disable all syslog levels.
*
* NOTE: setlogmask is not a thread-safe, re-entrant function. Concurrent
* use of setlogmask() will have undefined behavior.
*
@ -80,8 +76,13 @@ int setlogmask(int mask)
{
uint8_t oldmask;
oldmask = g_syslog_mask;
g_syslog_mask = (uint8_t)mask;
oldmask = g_syslog_mask;
if (mask != 0)
{
/* If the mask argument is 0, the current logmask is not modified. */
g_syslog_mask = (uint8_t)mask;
}
return oldmask;
}