This is an automated email from the ASF dual-hosted git repository.

cederom pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new eeb4a0de83 setlogmask: fix setlogmask behavior according to POSIX 
standard
eeb4a0de83 is described below

commit eeb4a0de83951719b1f67df6e2c631d759869716
Author: Michal Lenc <michall...@seznam.cz>
AuthorDate: Mon Apr 28 17:26:59 2025 +0200

    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 <michall...@seznam.cz>
---
 include/syslog.h                  |  4 ----
 libs/libc/syslog/lib_setlogmask.c | 13 +++++++------
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/include/syslog.h b/include/syslog.h
index 66936e034d..14c527cbce 100644
--- a/include/syslog.h
+++ b/include/syslog.h
@@ -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.
  *
diff --git a/libs/libc/syslog/lib_setlogmask.c 
b/libs/libc/syslog/lib_setlogmask.c
index 8b60a604b6..1ce329ef48 100644
--- a/libs/libc/syslog/lib_setlogmask.c
+++ b/libs/libc/syslog/lib_setlogmask.c
@@ -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;
 }

Reply via email to