summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorNikolai Kondrashov <Nikolai.Kondrashov@redhat.com>2013-10-10 13:16:36 +0300
committerJakub Hrozek <jhrozek@redhat.com>2014-02-12 22:30:44 +0100
commitfb0332565892bc10998ca98b567d4dde2213844d (patch)
treee8736a34cd632072b4be7867e236a8120c39be14 /src/util
parentcb637a64fc51d6f4c718f75e23b19df6bdfe1c51 (diff)
downloadsssd-fb0332565892bc10998ca98b567d4dde2213844d.tar.gz
sssd-fb0332565892bc10998ca98b567d4dde2213844d.tar.xz
sssd-fb0332565892bc10998ca98b567d4dde2213844d.zip
Move DEBUG macro body to debug_fn
Move DEBUG macro body to the debug_fn function, adding "function" argument to the latter. Rename "debug_fn" in sssd_krb5_locator_plugin.c to "plugin_debug_fn" to remove conflict with the sssd debug_fn. Replace DEBUG_MSG macro usage with debug_fn function usage. Remove DEBUG_MSG macro along with tests. The above makes the total size of binaries drop by 20% for the standard Fedora build and by 44% for a build configured according to Debian packaging script. Reviewed-by: Jakub Hrozek <jhrozek@redhat.com> Reviewed-by: Stephen Gallagher <sgallagh@redhat.com> Reviewed-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/debug.c50
-rw-r--r--src/util/util.h78
2 files changed, 53 insertions, 75 deletions
diff --git a/src/util/debug.c b/src/util/debug.c
index 324f0daeb..91a030f2c 100644
--- a/src/util/debug.c
+++ b/src/util/debug.c
@@ -104,18 +104,59 @@ int debug_convert_old_level(int old_level)
return new_level;
}
-void debug_fn(const char *format, ...)
+static void debug_vprintf(const char *format, va_list ap)
+{
+ vfprintf(debug_file ? debug_file : stderr, format, ap);
+ fflush(debug_file ? debug_file : stderr);
+}
+
+static void debug_printf(const char *format, ...)
+ SSS_ATTRIBUTE_PRINTF(1, 2);
+
+static void debug_printf(const char *format, ...)
{
va_list ap;
va_start(ap, format);
- vfprintf(debug_file ? debug_file : stderr, format, ap);
- fflush(debug_file ? debug_file : stderr);
+ debug_vprintf(format, ap);
va_end(ap);
}
+void debug_fn(const char *function, int newlevel, const char *format, ...)
+{
+ va_list ap;
+ if (debug_timestamps) {
+ struct timeval tv;
+ struct tm *tm;
+ char datetime[20];
+ int year;
+ gettimeofday(&tv, NULL);
+ tm = localtime(&tv.tv_sec);
+ year = tm->tm_year + 1900;
+ /* get date time without year */
+ memcpy(datetime, ctime(&tv.tv_sec), 19);
+ datetime[19] = '\0';
+ if (debug_microseconds) {
+ debug_printf("(%s:%.6ld %d) [%s] [%s] (%#.4x): ",
+ datetime, tv.tv_usec,
+ year, debug_prg_name,
+ function, newlevel);
+ } else {
+ debug_printf("(%s %d) [%s] [%s] (%#.4x): ",
+ datetime, year,
+ debug_prg_name, function, newlevel);
+ }
+ } else {
+ debug_printf("[%s] [%s] (%#.4x): ",
+ debug_prg_name, function, newlevel);
+ }
+ va_start(ap, format);
+ debug_vprintf(format, ap);
+ va_end(ap);
+}
+
int debug_get_level(int old_level)
{
if ((old_level != 0) && !(old_level & 0x000F))
@@ -168,7 +209,8 @@ void ldb_debug_messages(void *context, enum ldb_debug_level level,
return;
}
- DEBUG_MSG(loglevel, "ldb", message);
+ if (DEBUG_IS_SET(loglevel))
+ debug_fn("ldb", loglevel, "%s\n", message);
free(message);
}
diff --git a/src/util/util.h b/src/util/util.h
index 04fe0cefb..7650e3e9a 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -68,7 +68,8 @@ extern int debug_timestamps;
extern int debug_microseconds;
extern int debug_to_file;
extern const char *debug_log_file;
-void debug_fn(const char *format, ...) SSS_ATTRIBUTE_PRINTF(1, 2);
+void debug_fn(const char *function, int newlevel, const char *format, ...)
+ SSS_ATTRIBUTE_PRINTF(3, 4);
int debug_get_level(int old_level);
int debug_convert_old_level(int old_level);
errno_t set_debug_file_from_fd(const int fd);
@@ -108,6 +109,8 @@ errno_t set_debug_file_from_fd(const int fd);
{"debug-microseconds", 0, POPT_ARG_INT, &debug_microseconds, 0, \
_("Show timestamps with microseconds"), NULL},
+#define DEBUG_UNWRAP(...) __VA_ARGS__
+
/** \def DEBUG(level, body)
\brief macro to generate debug messages
@@ -125,76 +128,9 @@ errno_t set_debug_file_from_fd(const int fd);
*/
#define DEBUG(level, body) do { \
int __debug_macro_newlevel = debug_get_level(level); \
- if (DEBUG_IS_SET(__debug_macro_newlevel)) { \
- if (debug_timestamps) { \
- struct timeval __debug_macro_tv; \
- struct tm *__debug_macro_tm; \
- char __debug_macro_datetime[20]; \
- int __debug_macro_year; \
- gettimeofday(&__debug_macro_tv, NULL); \
- __debug_macro_tm = localtime(&__debug_macro_tv.tv_sec); \
- __debug_macro_year = __debug_macro_tm->tm_year + 1900; \
- /* get date time without year */ \
- memcpy(__debug_macro_datetime, ctime(&__debug_macro_tv.tv_sec), 19); \
- __debug_macro_datetime[19] = '\0'; \
- if (debug_microseconds) { \
- debug_fn("(%s:%.6ld %d) [%s] [%s] (%#.4x): ", \
- __debug_macro_datetime, __debug_macro_tv.tv_usec, \
- __debug_macro_year, debug_prg_name, \
- __FUNCTION__, __debug_macro_newlevel); \
- } else { \
- debug_fn("(%s %d) [%s] [%s] (%#.4x): ", \
- __debug_macro_datetime, __debug_macro_year, \
- debug_prg_name, __FUNCTION__, __debug_macro_newlevel); \
- } \
- } else { \
- debug_fn("[%s] [%s] (%#.4x): ", \
- debug_prg_name, __FUNCTION__, __debug_macro_newlevel); \
- } \
- debug_fn body; \
- } \
-} while(0)
-
-/** \def DEBUG_MSG(level, function, message)
- \brief macro to generate debug messages with message from variable
-
- \param level the debug level, please use one of the SSSDBG_* macros
-
- \param function name of the function where DEBUG_MSG is called
-
- \param message message to be send (should not end with \n)
-*/
-#define DEBUG_MSG(level, function, message) do { \
- int __debug_macro_newlevel = debug_get_level(level); \
- if (DEBUG_IS_SET(__debug_macro_newlevel)) { \
- if (debug_timestamps) { \
- struct timeval __debug_macro_tv; \
- struct tm *__debug_macro_tm; \
- char __debug_macro_datetime[20]; \
- int __debug_macro_year; \
- gettimeofday(&__debug_macro_tv, NULL); \
- __debug_macro_tm = localtime(&__debug_macro_tv.tv_sec); \
- __debug_macro_year = __debug_macro_tm->tm_year + 1900; \
- /* get date time without year */ \
- memcpy(__debug_macro_datetime, ctime(&__debug_macro_tv.tv_sec), 19); \
- __debug_macro_datetime[19] = '\0'; \
- if (debug_microseconds) { \
- debug_fn("(%s:%.6ld %d) [%s] [%s] (%#.4x): %s\n", \
- __debug_macro_datetime, __debug_macro_tv.tv_usec, \
- __debug_macro_year, debug_prg_name, \
- function, __debug_macro_newlevel, message); \
- } else { \
- debug_fn("(%s %d) [%s] [%s] (%#.4x): %s\n", \
- __debug_macro_datetime, __debug_macro_year, \
- debug_prg_name, function, __debug_macro_newlevel, \
- message); \
- } \
- } else { \
- debug_fn("[%s] [%s] (%#.4x): %s\n", \
- debug_prg_name, function, __debug_macro_newlevel, message); \
- } \
- } \
-} while(0)
+ if (DEBUG_IS_SET(__debug_macro_newlevel)) \
+ debug_fn(__FUNCTION__, __debug_macro_newlevel, DEBUG_UNWRAP body); \
+} while (0)
/** \def DEBUG_IS_SET(level)
\brief checks whether level (must be in new format) is set in debug_level