dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0016-UTIL-Add-wrapper-function-to-configure-logger.patch

ced1f5
From 34fa82bc07c4da14606d7a8a9b68a872fe210a9f Mon Sep 17 00:00:00 2001
ced1f5
From: Lukas Slebodnik <lslebodn@redhat.com>
ced1f5
Date: Mon, 23 Oct 2017 14:58:14 +0200
ced1f5
Subject: [PATCH 16/21] UTIL: Add wrapper function to configure logger
ced1f5
MIME-Version: 1.0
ced1f5
Content-Type: text/plain; charset=UTF-8
ced1f5
Content-Transfer-Encoding: 8bit
ced1f5
ced1f5
Let's use one enum for logger type instead of many integers (debug_to_file,
ced1f5
debug_to_stderr plus some weird combination for journald).
ced1f5
Old variable were also transformed to enum for backward compatibility
ced1f5
ced1f5
Reviewed-by: Fabiano FidĂȘncio <fidencio@redhat.com>
ced1f5
(cherry picked from commit 09e3f0af96cecb94be69084c025f0355b3111993)
ced1f5
---
ced1f5
 src/util/debug.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
ced1f5
 src/util/debug.h | 18 ++++++++++++++++++
ced1f5
 2 files changed, 72 insertions(+)
ced1f5
ced1f5
diff --git a/src/util/debug.c b/src/util/debug.c
ced1f5
index ca4fa4c6f5b150700a0a136d8a7ca9df30c29d73..4e469447e5ab8aa89cd57bcd6d00269875a12bc6 100644
ced1f5
--- a/src/util/debug.c
ced1f5
+++ b/src/util/debug.c
ced1f5
@@ -43,9 +43,63 @@ int debug_timestamps = SSSDBG_TIMESTAMP_UNRESOLVED;
ced1f5
 int debug_microseconds = SSSDBG_MICROSECONDS_UNRESOLVED;
ced1f5
 int debug_to_file = 0;
ced1f5
 int debug_to_stderr = 0;
ced1f5
+enum sss_logger_t sss_logger;
ced1f5
 const char *debug_log_file = "sssd";
ced1f5
 FILE *debug_file = NULL;
ced1f5
 
ced1f5
+const char *sss_logger_str[] = {
ced1f5
+        [STDERR_LOGGER] = "stderr",
ced1f5
+        [FILES_LOGGER] = "files",
ced1f5
+#ifdef WITH_JOURNALD
ced1f5
+        [JOURNALD_LOGGER] = "journald",
ced1f5
+#endif
ced1f5
+        NULL,
ced1f5
+};
ced1f5
+
ced1f5
+#ifdef WITH_JOURNALD
ced1f5
+#define JOURNALD_STR " journald,"
ced1f5
+#else
ced1f5
+#define JOURNALD_STR ""
ced1f5
+#endif
ced1f5
+
ced1f5
+void sss_set_logger(const char *logger)
ced1f5
+{
ced1f5
+    /* use old flags */
ced1f5
+    if (logger == NULL) {
ced1f5
+        if (debug_to_stderr != 0) {
ced1f5
+            sss_logger = STDERR_LOGGER;
ced1f5
+        }
ced1f5
+        /* It is never described what should be used in case of
ced1f5
+         * debug_to_stderr == 1 && debug_to_file == 1. Because neither
ced1f5
+         * of binaries provide both command line arguments.
ced1f5
+         * Let files have higher priority.
ced1f5
+         */
ced1f5
+        if (debug_to_file != 0) {
ced1f5
+            sss_logger = FILES_LOGGER;
ced1f5
+        }
ced1f5
+#ifdef WITH_JOURNALD
ced1f5
+        if (debug_to_file == 0 && debug_to_stderr == 0) {
ced1f5
+            sss_logger = JOURNALD_LOGGER;
ced1f5
+        }
ced1f5
+#endif
ced1f5
+    } else {
ced1f5
+        if (strcmp(logger, "stderr") == 0) {
ced1f5
+            sss_logger = STDERR_LOGGER;
ced1f5
+        } else if (strcmp(logger, "files") == 0) {
ced1f5
+            sss_logger = FILES_LOGGER;
ced1f5
+#ifdef WITH_JOURNALD
ced1f5
+        } else if (strcmp(logger, "journald") == 0) {
ced1f5
+            sss_logger = JOURNALD_LOGGER;
ced1f5
+#endif
ced1f5
+        } else {
ced1f5
+            /* unexpected value */
ced1f5
+            fprintf(stderr, "Unexpected logger: %s\nExpected:%s stderr, "
ced1f5
+                            "files\n", logger, JOURNALD_STR);
ced1f5
+            sss_logger = STDERR_LOGGER;
ced1f5
+        }
ced1f5
+    }
ced1f5
+}
ced1f5
+
ced1f5
 errno_t set_debug_file_from_fd(const int fd)
ced1f5
 {
ced1f5
     FILE *dummy;
ced1f5
diff --git a/src/util/debug.h b/src/util/debug.h
ced1f5
index 2a1bd4ffd30817d7128805996c21105fe40982a2..4adafb7cfc03f7381c4d03071eb44edad04bee00 100644
ced1f5
--- a/src/util/debug.h
ced1f5
+++ b/src/util/debug.h
ced1f5
@@ -31,13 +31,26 @@
ced1f5
 
ced1f5
 #define APPEND_LINE_FEED 0x1
ced1f5
 
ced1f5
+enum sss_logger_t {
ced1f5
+    STDERR_LOGGER = 0,
ced1f5
+    FILES_LOGGER,
ced1f5
+#ifdef WITH_JOURNALD
ced1f5
+    JOURNALD_LOGGER,
ced1f5
+#endif
ced1f5
+};
ced1f5
+
ced1f5
+extern const char *sss_logger_str[];
ced1f5
 extern const char *debug_prg_name;
ced1f5
 extern int debug_level;
ced1f5
 extern int debug_timestamps;
ced1f5
 extern int debug_microseconds;
ced1f5
 extern int debug_to_file;
ced1f5
 extern int debug_to_stderr;
ced1f5
+extern enum sss_logger_t sss_logger;
ced1f5
 extern const char *debug_log_file;
ced1f5
+
ced1f5
+void sss_set_logger(const char *logger);
ced1f5
+
ced1f5
 void sss_vdebug_fn(const char *file,
ced1f5
                    long line,
ced1f5
                    const char *function,
ced1f5
@@ -80,6 +93,11 @@ int get_fd_from_debug_file(void);
ced1f5
 #define SSSDBG_MICROSECONDS_UNRESOLVED   -1
ced1f5
 #define SSSDBG_MICROSECONDS_DEFAULT       0
ced1f5
 
ced1f5
+#define SSSD_LOGGER_OPTS \
ced1f5
+        {"logger", '\0', POPT_ARG_STRING, &opt_logger, 0, \
ced1f5
+         _("Set logger"), "stderr|files|journald"},
ced1f5
+
ced1f5
+
ced1f5
 #define SSSD_DEBUG_OPTS \
ced1f5
         {"debug-level", 'd', POPT_ARG_INT, &debug_level, 0, \
ced1f5
          _("Debug level"), NULL}, \
ced1f5
-- 
ced1f5
2.13.5
ced1f5