From 0c22d42aad659f7e81a6ff560ab4842f2cfd4f5c Mon Sep 17 00:00:00 2001
From: Utz-Uwe Haus <uhaus@cray.com>
Date: Wed, 4 Nov 2020 17:18:53 +0100
Subject: [PATCH] fix conflict between logging macros and syslog log levels

---
 maestro/logging.c | 43 ++++++++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 15 deletions(-)

diff --git a/maestro/logging.c b/maestro/logging.c
index 5eb57597..a51c134a 100644
--- a/maestro/logging.c
+++ b/maestro/logging.c
@@ -35,9 +35,6 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "maestro/env.h"
-#include "maestro/i_globals.h"
-#include "maestro/i_statistics.h"
 #include <errno.h>
 #include <ctype.h>
 
@@ -46,27 +43,43 @@
 #include <pthread_np.h>
 #endif /* HAVE_PTHREAD_NP_H */
 
-#include "maestro/logging.h"
-
+/* Careful! Syslog defines some constants that we use as macros (like LOG_ERR) */
 #ifdef HAVE_SYSLOG
-#include <syslog.h>
-#ifndef MSTRO_LOG_SYSLOG_FACILITY
+# include <syslog.h>
+# ifndef MSTRO_LOG_SYSLOG_FACILITY
 /** Log facility to use for syslog logging. Can be overridden at
  * compile time */
-#define MSTRO_LOG_SYSLOG_FACILITY LOG_LOCAL0
-#endif
+#  define MSTRO_LOG_SYSLOG_FACILITY LOG_LOCAL0
+# endif
+
+static const int g_syslog_err = LOG_ERR;
+static const int g_syslog_warning = LOG_WARNING;
+static const int g_syslog_info = LOG_INFO;
+static const int g_syslog_debug = LOG_DEBUG;
+#undef LOG_ERR
+#undef LOG_WARNING
+#undef LOG_INFO
+#undef LOG_DEBUG
 
+#include "maestro/logging.h"
 
 /* convert maestro log levels to syslog levels */
 static int mstro_loglevel2syslog[MSTRO_log__MAX] = {
-  [MSTRO_LOG_ERR]   = LOG_ERR,
-  [MSTRO_LOG_WARN]  = LOG_WARNING,
-  [MSTRO_LOG_INFO]  = LOG_INFO,
-  [MSTRO_LOG_DEBUG] = LOG_DEBUG,
-  [MSTRO_LOG_NOISE] = LOG_DEBUG
+  [MSTRO_LOG_ERR]   = g_syslog_err,
+  [MSTRO_LOG_WARN]  = g_syslog_warning,
+  [MSTRO_LOG_INFO]  = g_syslog_info,
+  [MSTRO_LOG_DEBUG] = g_syslog_debug,
+  [MSTRO_LOG_NOISE] = g_syslog_debug
 };
 
-#endif
+#endif /* SYSLOG */
+
+#include "maestro/logging.h"
+
+
+#include "maestro/env.h"
+#include "maestro/i_globals.h"
+#include "maestro/i_statistics.h"
 
 /** log to stderr */
 #define MSTRO_LOG_DST_STDERR 0
-- 
GitLab