]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
logging: don't save debugging arguments when debug is disabled
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 24 Sep 2015 16:31:17 +0000 (18:31 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 24 Sep 2015 16:32:23 +0000 (18:32 +0200)
Don't save the facility number, line number, function name and filename
in the compiled binary unless the debugging support is enabled.

client.c
logging.c
logging.h

index 60f53fcdc2a77d26b7b6924aee8b2571c9492ac3..16d88d439ba07d9dc2a5cd120e7e0a7326eb7130 100644 (file)
--- a/client.c
+++ b/client.c
@@ -76,9 +76,12 @@ static int no_dns = 0;
 
 int log_debug_enabled = 0;
 
-void LOG_Message(LOG_Severity severity, LOG_Facility facility,
-                 int line_number, const char *filename,
-                 const char *function_name, const char *format, ...)
+void LOG_Message(LOG_Severity severity,
+#if DEBUG > 0
+                 LOG_Facility facility, int line_number,
+                 const char *filename, const char *function_name,
+#endif
+                 const char *format, ...)
 {
   va_list ap;
 
index d9685f1094db85c84f963053a1d61f251497b42c..7eb680d6423ee2a3fea07e1f31ab2fbe61101d9f 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -119,9 +119,12 @@ static void log_message(int fatal, LOG_Severity severity, const char *message)
 
 /* ================================================== */
 
-void LOG_Message(LOG_Severity severity, LOG_Facility facility,
-                 int line_number, const char *filename,
-                 const char *function_name, const char *format, ...)
+void LOG_Message(LOG_Severity severity,
+#if DEBUG > 0
+                 LOG_Facility facility, int line_number,
+                 const char *filename, const char *function_name,
+#endif
+                 const char *format, ...)
 {
   char buf[2048];
   va_list other_args;
@@ -134,8 +137,10 @@ void LOG_Message(LOG_Severity severity, LOG_Facility facility,
     stm = *gmtime(&t);
     strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", &stm);
     fprintf(stderr, "%s ", buf);
+#if DEBUG > 0
     if (debug_level >= DEBUG_LEVEL_PRINT_FUNCTION)
       fprintf(stderr, "%s:%d:(%s) ", filename, line_number, function_name);
+#endif
   }
 
   va_start(other_args, format);
index 7c89bb745dc50c32e7714cc23b9659ec3ab5c909..84504c258e10c78dea4249cdaff82e6d98743855 100644 (file)
--- a/logging.h
+++ b/logging.h
@@ -45,18 +45,28 @@ extern int log_debug_enabled;
 #define FORMAT_ATTRIBUTE_PRINTF(str, first)
 #endif
 
+#if DEBUG > 0
+#define LOG_MESSAGE(severity, facility, ...) \
+  LOG_Message(LOGS_DEBUG, facility, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__);
+#else
+#define LOG_MESSAGE(severity, facility, ...) \
+  LOG_Message(severity, __VA_ARGS__);
+#endif
+
 #define DEBUG_LOG(facility, ...) \
   do { \
     if (DEBUG && log_debug_enabled) \
-      LOG_Message(LOGS_DEBUG, facility, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__); \
+      LOG_MESSAGE(LOGS_DEBUG, facility, __VA_ARGS__); \
   } while (0)
-#define LOG(severity, facility, ...) LOG_Message(severity, facility, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__)
+
 #define LOG_FATAL(facility, ...) \
   do { \
-    LOG_Message(LOGS_FATAL, facility, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__); \
+    LOG_MESSAGE(LOGS_FATAL, facility, __VA_ARGS__); \
     exit(1); \
   } while (0)
 
+#define LOG(severity, facility, ...) LOG_MESSAGE(severity, facility, __VA_ARGS__)
+
 /* Definition of severity */
 typedef enum {
   LOGS_INFO,
@@ -114,10 +124,15 @@ extern void LOG_Initialise(void);
 extern void LOG_Finalise(void);
 
 /* Line logging function */
+#if DEBUG > 0
 FORMAT_ATTRIBUTE_PRINTF(6, 7)
 extern void LOG_Message(LOG_Severity severity, LOG_Facility facility,
                         int line_number, const char *filename,
                         const char *function_name, const char *format, ...);
+#else
+FORMAT_ATTRIBUTE_PRINTF(2, 3)
+extern void LOG_Message(LOG_Severity severity, const char *format, ...);
+#endif
 
 /* Set debug level:
    0, 1 - only non-debug messages are logged