From: Alejandro Colomar Date: Mon, 3 Nov 2025 17:08:11 +0000 (+0100) Subject: lib/io/: SYSLOG(): Preserve errno X-Git-Tag: 4.20.0-rc3~32 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4d9ee349e975cd581d452cf872253e89974f68d4;p=thirdparty%2Fshadow.git lib/io/: SYSLOG(): Preserve errno In some cases, we print strerrno() with this macro. Because this is a macro, and internal calls such as strdup(3) may set errno, that value could be corrupted when we arrive at syslog(3). While we could solve this here, it's not robust. Instead, we'll use a dedicated wrapper for that, which will be added in the following commits: SYSLOGE(). What we'll do here is preserve errno when we exit from this macro, as we often follow SYSLOG() calls with fprintf(stderr,) calls, which also use the errno value, and we don't want to pollute that. Signed-off-by: Alejandro Colomar --- diff --git a/lib/io/syslog.h b/lib/io/syslog.h index 84c65c74f..323941c70 100644 --- a/lib/io/syslog.h +++ b/lib/io/syslog.h @@ -25,13 +25,22 @@ #endif #if !USE_SYSLOG -# define SYSLOG(...) +# define SYSLOG_(...) #elif defined(ENABLE_NLS) -# define SYSLOG(...) SYSLOG_C(__VA_ARGS__) +# define SYSLOG_(...) SYSLOG_C(__VA_ARGS__) #else -# define SYSLOG(...) syslog(__VA_ARGS__) +# define SYSLOG_(...) syslog(__VA_ARGS__) #endif +#define SYSLOG(...) do \ +{ \ + int e_; \ + \ + e_ = errno; \ + SYSLOG_(__VA_ARGS__); \ + errno = e_; \ +} while (0) + /* The default syslog settings can now be changed here, in just one place. */