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 <alx@kernel.org>
#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. */