]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/io/syslog.h: SYSLOGE[C](): Add macros
authorAlejandro Colomar <alx@kernel.org>
Wed, 23 Jul 2025 12:23:11 +0000 (14:23 +0200)
committerSerge Hallyn <serge@hallyn.com>
Fri, 17 Jul 2026 13:48:04 +0000 (08:48 -0500)
like the fprintf(3) wrappers, these print an error message.  SYSLOGE()
uses errno, and SYSLOGEC() uses an errno-like error code.

This time we need to be careful to name the local copy of errno
differently than within SYSLOG() --which we call--.  Let's use a double
underscore.  In the future, C might have function literals (similar to
lambdas), which will solve this issue.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/io/syslog.h

index 323941c70e5170d88a7b5a016359223b507805cb..8a3ea455698b0e08d1806e07c627a7059421137f 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "config.h"
 
+#include <errno.h>
 #include <locale.h>
 #include <stddef.h>
 #include <stdlib.h>
 #define OPENLOG(progname) openlog(progname, SYSLOG_OPTIONS, SYSLOG_FACILITY)
 
 
+// SYSLOGE - system log errno
+#define SYSLOGE(prio, fmt, ...)  do                                   \
+{                                                                     \
+       int  e__;                                                     \
+                                                                      \
+       e__ = errno;                                                  \
+       SYSLOGEC(prio, e__, fmt __VA_OPT__(,) __VA_ARGS__);           \
+       errno = e__;                                                  \
+} while (0)
+
+
+// SYSLOGEC - system log errno code
+#define SYSLOGEC(prio, e, fmt, ...)  do                               \
+{                                                                     \
+       SYSLOG(prio, "" fmt ": %s" __VA_OPT__(,) __VA_ARGS__, strerror(e)); \
+} while (0)
+
+
 // system log C-locale
 #define SYSLOG_C(...)  do                                             \
 {                                                                     \