ehlo,

I read log files from latest 1.13 today and it was a small challenge
due to missing line feed after some ldb messages.

LS
>From c9f7e99fb933706663948efc659937299ec54077 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lsleb...@redhat.com>
Date: Wed, 9 Mar 2016 17:14:16 +0100
Subject: [PATCH 1/2] UTIL: Move debug part from util.h -> new debug.h

---
 src/util/debug.h | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/util/util.h  | 119 +---------------------------------------------
 2 files changed, 141 insertions(+), 118 deletions(-)
 create mode 100644 src/util/debug.h

diff --git a/src/util/debug.h b/src/util/debug.h
new file mode 100644
index 
0000000000000000000000000000000000000000..667021ba1522eac8b4a736aa78b7df24015bb0dd
--- /dev/null
+++ b/src/util/debug.h
@@ -0,0 +1,140 @@
+/*
+    Authors:
+        Simo Sorce <sso...@redhat.com>
+
+    Copyright (C) 2009 Red Hat
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __SSSD_DEBUG_H__
+#define __SSSD_DEBUG_H__
+
+#include "config.h"
+
+#ifdef HAVE_FUNCTION_ATTRIBUTE_FORMAT
+#define SSS_ATTRIBUTE_PRINTF(a1, a2) __attribute__((format (printf, a1, a2)))
+#else
+#define SSS_ATTRIBUTE_PRINTF(a1, a2)
+#endif
+
+extern const char *debug_prg_name;
+extern int debug_level;
+extern int debug_timestamps;
+extern int debug_microseconds;
+extern int debug_to_file;
+extern int debug_to_stderr;
+extern const char *debug_log_file;
+void sss_vdebug_fn(const char *file,
+                   long line,
+                   const char *function,
+                   int level,
+                   const char *format,
+                   va_list ap);
+void sss_debug_fn(const char *file,
+                  long line,
+                  const char *function,
+                  int level,
+                  const char *format, ...) SSS_ATTRIBUTE_PRINTF(5, 6);
+int debug_convert_old_level(int old_level);
+errno_t set_debug_file_from_fd(const int fd);
+int get_fd_from_debug_file(void);
+
+#define SSS_DOM_ENV           "_SSS_DOM"
+
+#define SSSDBG_FATAL_FAILURE  0x0010   /* level 0 */
+#define SSSDBG_CRIT_FAILURE   0x0020   /* level 1 */
+#define SSSDBG_OP_FAILURE     0x0040   /* level 2 */
+#define SSSDBG_MINOR_FAILURE  0x0080   /* level 3 */
+#define SSSDBG_CONF_SETTINGS  0x0100   /* level 4 */
+#define SSSDBG_FUNC_DATA      0x0200   /* level 5 */
+#define SSSDBG_TRACE_FUNC     0x0400   /* level 6 */
+#define SSSDBG_TRACE_LIBS     0x1000   /* level 7 */
+#define SSSDBG_TRACE_INTERNAL 0x2000   /* level 8 */
+#define SSSDBG_TRACE_ALL      0x4000   /* level 9 */
+#define SSSDBG_BE_FO          0x8000   /* level 9 */
+#define SSSDBG_IMPORTANT_INFO SSSDBG_OP_FAILURE
+
+#define SSSDBG_INVALID        -1
+#define SSSDBG_UNRESOLVED     0
+#define SSSDBG_MASK_ALL       0xFFF0   /* enable all debug levels */
+#define SSSDBG_DEFAULT        SSSDBG_FATAL_FAILURE
+
+#define SSSDBG_TIMESTAMP_UNRESOLVED   -1
+#define SSSDBG_TIMESTAMP_DEFAULT       1
+
+#define SSSDBG_MICROSECONDS_UNRESOLVED   -1
+#define SSSDBG_MICROSECONDS_DEFAULT       0
+
+#define SSSD_DEBUG_OPTS \
+        {"debug-level", 'd', POPT_ARG_INT, &debug_level, 0, \
+         _("Debug level"), NULL}, \
+        {"debug-to-files", 'f', POPT_ARG_NONE, &debug_to_file, 0, \
+         _("Send the debug output to files instead of stderr"), NULL }, \
+        {"debug-to-stderr", 0, POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN, 
&debug_to_stderr, 0, \
+         _("Send the debug output to stderr directly."), NULL }, \
+        {"debug-timestamps", 0, POPT_ARG_INT, &debug_timestamps, 0, \
+         _("Add debug timestamps"), NULL}, \
+        {"debug-microseconds", 0, POPT_ARG_INT, &debug_microseconds, 0, \
+         _("Show timestamps with microseconds"), NULL},
+
+/** \def DEBUG(level, format, ...)
+    \brief macro to generate debug messages
+
+    \param level the debug level, please use one of the SSSDBG_* macros
+    \param format the debug message format string, should result in a
+                  newline-terminated message
+    \param ... the debug message format arguments
+*/
+#define DEBUG(level, format, ...) do { \
+    int __debug_macro_level = level; \
+    if (DEBUG_IS_SET(__debug_macro_level)) { \
+        sss_debug_fn(__FILE__, __LINE__, __FUNCTION__, \
+                     __debug_macro_level, \
+                     format, ##__VA_ARGS__); \
+    } \
+} while (0)
+
+/** \def DEBUG_IS_SET(level)
+    \brief checks whether level is set in debug_level
+
+    \param level the debug level, please use one of the SSSDBG*_ macros
+*/
+#define DEBUG_IS_SET(level) (debug_level & (level) || \
+                            (debug_level == SSSDBG_UNRESOLVED && \
+                                            (level & (SSSDBG_FATAL_FAILURE | \
+                                                      SSSDBG_CRIT_FAILURE))))
+
+#define DEBUG_INIT(dbg_lvl) do { \
+    if (dbg_lvl != SSSDBG_INVALID) { \
+        debug_level = debug_convert_old_level(dbg_lvl); \
+    } else { \
+        debug_level = SSSDBG_UNRESOLVED; \
+    } \
+\
+    talloc_set_log_fn(talloc_log_fn); \
+} while (0)
+
+/* CLI tools shall debug to stderr even when SSSD was compiled with journald
+ * support
+ */
+#define DEBUG_CLI_INIT(dbg_lvl) do { \
+    DEBUG_INIT(dbg_lvl);             \
+    debug_to_stderr = 1;             \
+} while (0)
+
+#define PRINT(fmt, ...) fprintf(stdout, gettext(fmt), ##__VA_ARGS__)
+#define ERROR(fmt, ...) fprintf(stderr, gettext(fmt), ##__VA_ARGS__)
+
+#endif /* __SSSD_DEBUG_H__ */
diff --git a/src/util/util.h b/src/util/util.h
index 
5df86b4cb084a01f31f3e11aaf3ffcbe79b996a9..477d0b28b9b3a1949b03c6e444698a29d50aa434
 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -51,6 +51,7 @@
 #include "util/util_errors.h"
 #include "util/util_safealign.h"
 #include "util/sss_format.h"
+#include "util/debug.h"
 
 #define _(STRING) gettext (STRING)
 
@@ -58,130 +59,12 @@
 
 #define CLEAR_MC_FLAG "clear_mc_flag"
 
-#ifdef HAVE_FUNCTION_ATTRIBUTE_FORMAT
-#define SSS_ATTRIBUTE_PRINTF(a1, a2) __attribute__ ((format (printf, a1, a2)))
-#else
-#define SSS_ATTRIBUTE_PRINTF(a1, a2)
-#endif
-
 /** Default secure umask */
 #define SSS_DFL_UMASK 0177
 
 /** Secure mask with executable bit */
 #define SSS_DFL_X_UMASK 0077
 
-extern const char *debug_prg_name;
-extern int debug_level;
-extern int debug_timestamps;
-extern int debug_microseconds;
-extern int debug_to_file;
-extern int debug_to_stderr;
-extern const char *debug_log_file;
-void sss_vdebug_fn(const char *file,
-                   long line,
-                   const char *function,
-                   int level,
-                   const char *format,
-                   va_list ap);
-void sss_debug_fn(const char *file,
-                  long line,
-                  const char *function,
-                  int level,
-                  const char *format, ...) SSS_ATTRIBUTE_PRINTF(5, 6);
-int debug_convert_old_level(int old_level);
-errno_t set_debug_file_from_fd(const int fd);
-int get_fd_from_debug_file(void);
-
-#define SSS_DOM_ENV           "_SSS_DOM"
-
-#define SSSDBG_FATAL_FAILURE  0x0010   /* level 0 */
-#define SSSDBG_CRIT_FAILURE   0x0020   /* level 1 */
-#define SSSDBG_OP_FAILURE     0x0040   /* level 2 */
-#define SSSDBG_MINOR_FAILURE  0x0080   /* level 3 */
-#define SSSDBG_CONF_SETTINGS  0x0100   /* level 4 */
-#define SSSDBG_FUNC_DATA      0x0200   /* level 5 */
-#define SSSDBG_TRACE_FUNC     0x0400   /* level 6 */
-#define SSSDBG_TRACE_LIBS     0x1000   /* level 7 */
-#define SSSDBG_TRACE_INTERNAL 0x2000   /* level 8 */
-#define SSSDBG_TRACE_ALL      0x4000   /* level 9 */
-#define SSSDBG_BE_FO          0x8000   /* level 9 */
-#define SSSDBG_IMPORTANT_INFO SSSDBG_OP_FAILURE
-
-#define SSSDBG_INVALID        -1
-#define SSSDBG_UNRESOLVED     0
-#define SSSDBG_MASK_ALL       0xFFF0   /* enable all debug levels */
-#define SSSDBG_DEFAULT        SSSDBG_FATAL_FAILURE
-
-#define SSSDBG_TIMESTAMP_UNRESOLVED   -1
-#define SSSDBG_TIMESTAMP_DEFAULT       1
-
-#define SSSDBG_MICROSECONDS_UNRESOLVED   -1
-#define SSSDBG_MICROSECONDS_DEFAULT       0
-
-#define SSSD_DEBUG_OPTS \
-        {"debug-level", 'd', POPT_ARG_INT, &debug_level, 0, \
-         _("Debug level"), NULL}, \
-        {"debug-to-files", 'f', POPT_ARG_NONE, &debug_to_file, 0, \
-         _("Send the debug output to files instead of stderr"), NULL }, \
-        {"debug-to-stderr", 0, POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN, 
&debug_to_stderr, 0, \
-         _("Send the debug output to stderr directly."), NULL }, \
-        {"debug-timestamps", 0, POPT_ARG_INT, &debug_timestamps, 0, \
-         _("Add debug timestamps"), NULL}, \
-         {"debug-microseconds", 0, POPT_ARG_INT, &debug_microseconds, 0, \
-          _("Show timestamps with microseconds"), NULL},
-
-/** \def DEBUG(level, format, ...)
-    \brief macro to generate debug messages
-
-    \param level the debug level, please use one of the SSSDBG_* macros
-    \param format the debug message format string, should result in a
-                  newline-terminated message
-    \param ... the debug message format arguments
-*/
-#define DEBUG(level, format, ...) do { \
-    int __debug_macro_level = level; \
-    if (DEBUG_IS_SET(__debug_macro_level)) { \
-        sss_debug_fn(__FILE__, __LINE__, __FUNCTION__, \
-                     __debug_macro_level, \
-                     format, ##__VA_ARGS__); \
-    } \
-} while (0)
-
-/** \def DEBUG_IS_SET(level)
-    \brief checks whether level is set in debug_level
-
-    \param level the debug level, please use one of the SSSDBG*_ macros
-*/
-#define DEBUG_IS_SET(level) (debug_level & (level) || \
-                            (debug_level == SSSDBG_UNRESOLVED && \
-                                            (level & (SSSDBG_FATAL_FAILURE | \
-                                                      SSSDBG_CRIT_FAILURE))))
-
-#define DEBUG_INIT(dbg_lvl) do { \
-    if (dbg_lvl != SSSDBG_INVALID) { \
-        debug_level = debug_convert_old_level(dbg_lvl); \
-    } else { \
-        debug_level = SSSDBG_UNRESOLVED; \
-    } \
-\
-    talloc_set_log_fn(talloc_log_fn); \
-} while (0)
-
-/* CLI tools shall debug to stderr even when SSSD was compiled with journald
- * support
- */
-#define DEBUG_CLI_INIT(dbg_lvl) do { \
-    DEBUG_INIT(dbg_lvl);             \
-    debug_to_stderr = 1;             \
-} while (0)
-
-#define PRINT(fmt, ...) fprintf(stdout, gettext(fmt), ##__VA_ARGS__)
-#define ERROR(fmt, ...) fprintf(stderr, gettext(fmt), ##__VA_ARGS__)
-
-#ifndef discard_const
-#define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
-#endif
-
 #ifndef NULL
 #define NULL 0
 #endif
-- 
2.7.2

>From f8d1f0ad9c026398d00ef2bbc2d2e42824c8d282 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lsleb...@redhat.com>
Date: Wed, 9 Mar 2016 17:09:06 +0100
Subject: [PATCH 2/2] UTIL: Allow to append new line in sss_vdebug_fn

libldb is not consistent with appending line feed
in debug messages. AS a result of this two messages can be on the same line
in sssd log files. Which makes analyzing log files more difficult.
---
 src/providers/ipa/ipa_access.c | 2 +-
 src/util/debug.c               | 9 +++++++--
 src/util/debug.h               | 3 +++
 src/util/sss_semanage.c        | 2 +-
 4 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/providers/ipa/ipa_access.c b/src/providers/ipa/ipa_access.c
index 
ad12f21fc36e52a2e8d7affcfc7128f018c50e4c..3fe7c0d4f43b49569e17adb1432816abf59cca94
 100644
--- a/src/providers/ipa/ipa_access.c
+++ b/src/providers/ipa/ipa_access.c
@@ -68,7 +68,7 @@ void hbac_debug_messages(const char *file, int line,
         va_list ap;
 
         va_start(ap, fmt);
-        sss_vdebug_fn(file, line, function, loglevel, fmt, ap);
+        sss_vdebug_fn(file, line, function, loglevel, 0, fmt, ap);
         va_end(ap);
     }
 }
diff --git a/src/util/debug.c b/src/util/debug.c
index 
2aeaee580f8c87721e324e008e800e8cdd5de860..ca4fa4c6f5b150700a0a136d8a7ca9df30c29d73
 100644
--- a/src/util/debug.c
+++ b/src/util/debug.c
@@ -210,6 +210,7 @@ void sss_vdebug_fn(const char *file,
                    long line,
                    const char *function,
                    int level,
+                   int flags,
                    const char *format,
                    va_list ap)
 {
@@ -265,6 +266,9 @@ void sss_vdebug_fn(const char *file,
     }
 
     debug_vprintf(format, ap);
+    if (flags & APPEND_LINE_FEED) {
+        debug_printf("\n");
+    }
     debug_fflush();
 }
 
@@ -277,7 +281,7 @@ void sss_debug_fn(const char *file,
     va_list ap;
 
     va_start(ap, format);
-    sss_vdebug_fn(file, line, function, level, format, ap);
+    sss_vdebug_fn(file, line, function, level, 0, format, ap);
     va_end(ap);
 }
 
@@ -302,7 +306,8 @@ void ldb_debug_messages(void *context, enum ldb_debug_level 
level,
     }
 
     if (DEBUG_IS_SET(loglevel)) {
-        sss_vdebug_fn(__FILE__, __LINE__, "ldb", loglevel, fmt, ap);
+        sss_vdebug_fn(__FILE__, __LINE__, "ldb", loglevel, APPEND_LINE_FEED,
+                      fmt, ap);
     }
 }
 
diff --git a/src/util/debug.h b/src/util/debug.h
index 
667021ba1522eac8b4a736aa78b7df24015bb0dd..2a1bd4ffd30817d7128805996c21105fe40982a2
 100644
--- a/src/util/debug.h
+++ b/src/util/debug.h
@@ -29,6 +29,8 @@
 #define SSS_ATTRIBUTE_PRINTF(a1, a2)
 #endif
 
+#define APPEND_LINE_FEED 0x1
+
 extern const char *debug_prg_name;
 extern int debug_level;
 extern int debug_timestamps;
@@ -40,6 +42,7 @@ void sss_vdebug_fn(const char *file,
                    long line,
                    const char *function,
                    int level,
+                   int flags,
                    const char *format,
                    va_list ap);
 void sss_debug_fn(const char *file,
diff --git a/src/util/sss_semanage.c b/src/util/sss_semanage.c
index 
7f746491174730acbf1539acaf3f6467ff92afcf..d76677ee746192b83d5aaa01de745a96411c1a38
 100644
--- a/src/util/sss_semanage.c
+++ b/src/util/sss_semanage.c
@@ -55,7 +55,7 @@ static void sss_semanage_error_callback(void *varg,
 
     va_start(ap, fmt);
     if (DEBUG_IS_SET(level)) {
-        sss_vdebug_fn(__FILE__, __LINE__, "libsemanage", level, fmt, ap);
+        sss_vdebug_fn(__FILE__, __LINE__, "libsemanage", level, 0, fmt, ap);
     }
     va_end(ap);
 }
-- 
2.7.2

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/sssd-devel@lists.fedorahosted.org

Reply via email to