Add support for debug messages
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.
This commit is contained in:
parent
0731cd6950
commit
4bbc5520b8
6 changed files with 42 additions and 5 deletions
|
@ -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}).
|
||||
|
|
|
@ -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
|
||||
|
|
7
configure
vendored
7
configure
vendored
|
@ -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\""
|
||||
|
||||
|
|
17
logging.c
17
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)
|
||||
{
|
||||
|
|
11
logging.h
11
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);
|
||||
|
||||
|
|
6
main.c
6
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);
|
||||
|
|
Loading…
Reference in a new issue