From 41354b0b972df187d5b6f6b02b26b736ec6bce23 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Feb 19 2014 11:28:05 +0000 Subject: DEBUG: Allow debug_fn to process __FILE__ and __LINE__ In preparation for enabling journald support for the DEBUG logs, we will need to be able to pass in certain additional arguments that will be required, specifically the code file and line number. We will be able to optionally enable this in the file-based logs as well if we so choose, but for right now we will avoid breaking the log format on disk. Reviewed-by: Jakub Hrozek Reviewed-by: Lukáš Slebodník --- diff --git a/src/tools/selinux.c b/src/tools/selinux.c index e10f806..1f87d40 100644 --- a/src/tools/selinux.c +++ b/src/tools/selinux.c @@ -122,7 +122,7 @@ static void sss_semanage_error_callback(void *varg, } if (DEBUG_IS_SET(level)) - debug_fn("libsemanage", level, "%s\n", message); + debug_fn(__FILE__, __LINE__, "libsemanage", level, "%s\n", message); free(message); } diff --git a/src/util/debug.c b/src/util/debug.c index 6ac9165..3643c2b 100644 --- a/src/util/debug.c +++ b/src/util/debug.c @@ -129,7 +129,11 @@ static void debug_printf(const char *format, ...) va_end(ap); } -void debug_fn(const char *function, int level, const char *format, ...) +void debug_fn(const char *file, + long line, + const char *function, + int level, + const char *format, ...) { va_list ap; struct timeval tv; @@ -194,7 +198,7 @@ void ldb_debug_messages(void *context, enum ldb_debug_level level, } if (DEBUG_IS_SET(loglevel)) - debug_fn("ldb", loglevel, "%s\n", message); + debug_fn(__FILE__, __LINE__, "ldb", loglevel, "%s\n", message); free(message); } diff --git a/src/util/util.h b/src/util/util.h index b5e742f..c74ff5b 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -68,8 +68,11 @@ extern int debug_timestamps; extern int debug_microseconds; extern int debug_to_file; extern const char *debug_log_file; -void debug_fn(const char *function, int level, const char *format, ...) - SSS_ATTRIBUTE_PRINTF(3, 4); +void 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); @@ -118,8 +121,11 @@ errno_t set_debug_file_from_fd(const int fd); */ #define DEBUG(level, format, ...) do { \ int __debug_macro_level = level; \ - if (DEBUG_IS_SET(__debug_macro_level)) \ - debug_fn(__FUNCTION__, __debug_macro_level, format, ##__VA_ARGS__); \ + if (DEBUG_IS_SET(__debug_macro_level)) { \ + debug_fn(__FILE__, __LINE__, __FUNCTION__, \ + __debug_macro_level, \ + format, ##__VA_ARGS__); \ + } \ } while (0) /** \def DEBUG_IS_SET(level)