From: Dave Hart Date: Tue, 9 Nov 2010 05:52:27 +0000 (+0000) Subject: [Bug 1681] sntp logging cleanup. X-Git-Tag: NTP_4_2_6P3_RC9~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca8abdc8e33a8b0d8178abb9f956fe015818e9ee;p=thirdparty%2Fntp.git [Bug 1681] sntp logging cleanup. bk: 4cd8e19b_yAqsvcAknXzOETZR4nhpw --- diff --git a/ChangeLog b/ChangeLog index a54f5534f..2a8477d79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ --- * [Bug 1574] sntp:set_time doesn't set tv_usec correctly. +* [Bug 1681] sntp logging cleanup. * [Bug 1683] Interface binding does not seem to work as intended. * [Bug 1691] Use first NMEA sentence each second. * [Bug 1709] ntpdate ignores replies with equal receive and transmit diff --git a/sntp/kod_management.c b/sntp/kod_management.c index 878a2a0c1..4bdb4e8d9 100644 --- a/sntp/kod_management.c +++ b/sntp/kod_management.c @@ -148,7 +148,7 @@ write_kod_db(void) #ifdef DEBUG debug_msg(msg); #endif - log_msg(msg, 2); + log_msg(msg, LOG_WARNING | LOG_CONS); return; } @@ -199,7 +199,7 @@ kod_init_kod_db( debug_msg(msg); printf("%s\n", msg); #endif - log_msg(msg, 2); + log_msg(msg, LOG_WARNING | LOG_CONS); return; } @@ -231,7 +231,7 @@ kod_init_kod_db( debug_msg(msg); printf("%s\n", msg); #endif - log_msg(msg, 1); + log_msg(msg, LOG_DEBUG | LOG_CONS); } fclose(db_s); return; @@ -297,7 +297,7 @@ kod_init_kod_db( #ifdef DEBUG debug_msg(msg); #endif - log_msg(msg, 2); + log_msg(msg, LOG_WARNING | LOG_CONS); fclose(db_s); return; diff --git a/sntp/log.c b/sntp/log.c index c6bfe2228..52d9fd25d 100644 --- a/sntp/log.c +++ b/sntp/log.c @@ -7,29 +7,14 @@ int filelog = 0; FILE *log_file; -void log_msg(char *message, char type) { - if(init) { +void log_msg(char *message, int type) { + if (init) { time_t cur_time = time(NULL); char *timestamp = ctime(&cur_time); fprintf(log_file, "%s: %s\n", timestamp, message); fflush(log_file); - } - else { - switch(type) { - case 0: - type = LOG_CONS; - break; - - case 1: - type = LOG_DEBUG | LOG_CONS; - break; - - case 2: - type = LOG_WARNING | LOG_CONS; - break; - } - + } else { syslog(type, message); } } diff --git a/sntp/log.h b/sntp/log.h index 328d96184..b35d5e40b 100644 --- a/sntp/log.h +++ b/sntp/log.h @@ -10,7 +10,7 @@ #include -void log_msg(char *message, char type); +void log_msg(char *message, int type); void debug_msg(char *message); void init_log(const char *logfile); diff --git a/sntp/main.c b/sntp/main.c index 3c8101124..23ccd4c12 100644 --- a/sntp/main.c +++ b/sntp/main.c @@ -85,8 +85,6 @@ sntp_main ( ai_fam_pref = AF_INET6; } - log_msg("Started sntp", 0); - optct = optionProcess(&sntpOptions, argc, argv); argc -= optct; argv += optct; @@ -97,6 +95,8 @@ sntp_main ( if (HAVE_OPT(FILELOG)) init_log(OPT_ARG(FILELOG)); + log_msg("Started sntp", LOG_CONS); + /* * If there's a specified KOD file init KOD system. If not use * default file. For embedded systems with no writable @@ -275,7 +275,7 @@ on_wire ( "Received a KOD packet with code %c%c%c%c from %s, demobilizing all connections", ref[0], ref[1], ref[2], ref[3], hostname); - log_msg(log_str, 2); + log_msg(log_str, LOG_WARNING | LOG_CONS); free(log_str); break; @@ -366,7 +366,7 @@ on_wire ( getnameinfo(host->ai_addr, host->ai_addrlen, addr_buf, sizeof(addr_buf), NULL, 0, NI_NUMERICHOST); snprintf(logmsg, sizeof(logmsg), "Received no useable packet from %s!", addr_buf); - log_msg(logmsg, 1); + log_msg(logmsg, LOG_DEBUG | LOG_CONS); if (ENABLED_OPT(NORMALVERBOSE)) printf("sntp on_wire: Received no useable packet from %s!\n", addr_buf); diff --git a/sntp/networking.c b/sntp/networking.c index ff9afa13e..d1d988870 100644 --- a/sntp/networking.c +++ b/sntp/networking.c @@ -49,7 +49,7 @@ resolve_hosts ( #ifdef DEBUG printf("%s\n", logmsg); #endif - log_msg(logmsg, 1); + log_msg(logmsg, LOG_DEBUG | LOG_CONS); free(logmsg); } else { #ifdef DEBUG