diff --git a/chrony.texi.in b/chrony.texi.in index 09740b9..8cf6e93 100644 --- a/chrony.texi.in +++ b/chrony.texi.in @@ -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 This option can be used to specify an alternate location for the configuration file (default @file{@SYSCONFDIR@/chrony.conf}). diff --git a/chronyd.8.in b/chronyd.8.in index e1b4fe0..b62805b 100644 --- a/chronyd.8.in +++ b/chronyd.8.in @@ -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 diff --git a/configure b/configure index 78750e4..4216997 100755 --- 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\"" diff --git a/logging.c b/logging.c index 019634e..053b1e9 100644 --- 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) { diff --git a/logging.h b/logging.h index 858ce85..2015c73 100644 --- a/logging.h +++ b/logging.h @@ -39,6 +39,11 @@ #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 cab0b87..207011f 100644 --- 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);