]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Add support for debug messages
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 26 Nov 2013 17:53:10 +0000 (18:53 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 27 Nov 2013 13:35:38 +0000 (14:35 +0100)
Add new DEBUG_LOG macro for debug messages. The messages are enabled
when compiled with --enable-debug and they are printed when the -d
option is used twice.

chrony.texi.in
chronyd.8.in
configure
logging.c
logging.h
main.c

index 09740b9fb79bf2e497b3c1ee8bc42159b200cfa3..8cf6e9343a6f5f3b5ca549b78fda4cc06a1ad676 100644 (file)
@@ -992,7 +992,8 @@ terminal.
 @item -d
 When run in this mode, the program will not detach itself from the
 terminal, and all messages will be sent to the terminal instead of to
-syslog.
+syslog.  When @code{chronyd} was compiled with debugging support,
+this option can be used twice to print also debugging messages.
 @item -f <conf-file>
 This option can be used to specify an alternate location for the
 configuration file (default @file{@SYSCONFDIR@/chrony.conf}).
index e1b4fe0778ab1da13f33097bf6c5b0150f66aded..b62805b1416bf9f218da37564ee0566e2c8579fd 100644 (file)
@@ -52,7 +52,8 @@ terminal.
 .B \-d
 When run in this mode, the program will not detach itself from the
 terminal, and all messages will be sent to the terminal instead of
-to syslog.
+to syslog.  When \fBchronyd\fR was compiled with debugging support,
+this option can be used twice to print also debugging messages.
 .TP
 \fB\-f\fR \fIconf-file\fR
 This option can be used to specify an alternate location for the
index 78750e4eb191f50b0d4481451f57bcd1cf165125..4216997304786e66f02103cd678451280923b16e 100755 (executable)
--- a/configure
+++ b/configure
@@ -115,6 +115,7 @@ For better control, use the options below.
   --disable-forcednsretry Don't retry on permanent DNS error
   --with-sendmail=PATH   Path to sendmail binary [/usr/lib/sendmail]
   --enable-trace         Enable tracing
+  --enable-debug         Enable debugging support
 
 Fine tuning of the installation directories:
   --sysconfdir=DIR       chrony.conf location [/etc]
@@ -171,7 +172,7 @@ EXTRA_OBJECTS=""
 EXTRA_DEFS=""
 SYSDEFS=""
 
-# Support for readline (on by default)
+debug=0
 feat_readline=1
 try_readline=1
 try_editline=1
@@ -199,6 +200,9 @@ do
     --enable-trace )
       add_def TRACEON
     ;;
+    --enable-debug )
+      debug=1
+    ;;
     --disable-readline )
       feat_readline=0
     ;;
@@ -616,6 +620,7 @@ if [ "x$SETCHRONYVARDIR" != "x" ]; then
   CHRONYVARDIR=$SETCHRONYVARDIR
 fi
 
+add_def DEBUG $debug
 add_def DEFAULT_CONF_FILE "\"$SYSCONFDIR/chrony.conf\""
 add_def MAIL_PROGRAM "\"$mail_program\""
 
index 019634e3bf97a4b35970022cb532906552ee3622..053b1e95bf77c6e4d8c0a34ad7007d6ad2743beb 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -42,6 +42,8 @@ static int system_log = 0;
 
 static int parent_fd = 0;
 
+static int log_debug = 0;
+
 static time_t last_limited = 0;
 
 #ifdef WINNT
@@ -108,6 +110,9 @@ static void log_message(int fatal, LOG_Severity severity, const char *message)
   if (system_log) {
     int priority;
     switch (severity) {
+      case LOGS_DEBUG:
+        priority = LOG_DEBUG;
+        break;
       case LOGS_INFO:
         priority = LOG_INFO;
         break;
@@ -141,6 +146,10 @@ void LOG_Message(LOG_Severity severity, LOG_Facility facility,
   time_t t;
   struct tm stm;
 
+  /* Don't write debug messages if not enabled */
+  if (!log_debug && severity == LOGS_DEBUG)
+    return;
+
 #ifdef WINNT
 #else
   if (!system_log) {
@@ -157,6 +166,7 @@ void LOG_Message(LOG_Severity severity, LOG_Facility facility,
   va_end(other_args);
 
   switch (severity) {
+    case LOGS_DEBUG:
     case LOGS_INFO:
     case LOGS_WARN:
     case LOGS_ERR:
@@ -192,6 +202,13 @@ LOG_OpenSystemLog(void)
 
 /* ================================================== */
 
+void LOG_EnableDebug(void)
+{
+  log_debug = 1;
+}
+
+/* ================================================== */
+
 void
 LOG_SetParentFd(int fd)
 {
index 858ce85308ec808851dbcdd234c4376015d3d148..2015c7340787af881618e6321f0e989999d12e11 100644 (file)
--- a/logging.h
+++ b/logging.h
 #define FORMAT_ATTRIBUTE_PRINTF(str, first)
 #endif
 
+#define DEBUG_LOG(facility, ...) \
+  do { \
+    if (DEBUG) \
+      LOG_Message(LOGS_DEBUG, facility, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__); \
+  } while (0)
 #define LOG(severity, facility, ...) LOG_Message(severity, facility, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__)
 #define LOG_FATAL(facility, ...) LOG_Message(LOGS_FATAL, facility, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__)
 
@@ -47,7 +52,8 @@ typedef enum {
   LOGS_INFO,
   LOGS_WARN,
   LOGS_ERR,
-  LOGS_FATAL
+  LOGS_FATAL,
+  LOGS_DEBUG
 } LOG_Severity;
 
 /* Definition of facility.  Each message is tagged with who generated
@@ -95,6 +101,9 @@ extern void LOG_Message(LOG_Severity severity, LOG_Facility facility,
                         int line_number, const char *filename,
                         const char *function_name, const char *format, ...);
 
+/* Enable logging of debug messages */
+extern void LOG_EnableDebug(void);
+
 /* Log messages to syslog instead of stderr */
 extern void LOG_OpenSystemLog(void);
 
diff --git a/main.c b/main.c
index cab0b876be7865ce14309934625feea814dc30ef..207011f248f39c6c25b11296b8cf9f1f9dda683e 100644 (file)
--- a/main.c
+++ b/main.c
@@ -326,7 +326,7 @@ int main
     } else if (!strcmp("-n", *argv)) {
       nofork = 1;
     } else if (!strcmp("-d", *argv)) {
-      debug = 1;
+      debug++;
       nofork = 1;
     } else if (!strcmp("-4", *argv)) {
       address_family = IPADDR_INET4;
@@ -352,6 +352,10 @@ int main
     LOG_OpenSystemLog();
   }
   
+  if (debug > 1) {
+    LOG_EnableDebug();
+  }
+  
   LOG(LOGS_INFO, LOGF_Main, "chronyd version %s starting", CHRONY_VERSION);
 
   DNS_SetAddressFamily(address_family);