]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
logging: convert rate limited messages to debug messages
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 4 Jun 2014 10:26:27 +0000 (12:26 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 4 Jun 2014 10:26:27 +0000 (12:26 +0200)
cmdmon.c
logging.c
logging.h
ntp_core.c
ntp_io.c

index b056770016d448f3e415eac42898e5c6215daf74..fe314061fbead59b6aa0a3f8efeea948a325c322 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -734,7 +734,7 @@ transmit_reply(CMD_Reply *msg, union sockaddr_in46 *where_to, int auth_len)
   status = sendto(sock_fd, (void *) msg, tx_message_length, 0,
                   &where_to->u, addrlen);
 
-  if (status < 0 && !LOG_RateLimited()) {
+  if (status < 0) {
     unsigned short port;
     IPAddr ip;
 
@@ -755,7 +755,7 @@ transmit_reply(CMD_Reply *msg, union sockaddr_in46 *where_to, int auth_len)
         assert(0);
     }
 
-    LOG(LOGS_WARN, LOGF_CmdMon, "Could not send response to %s:%hu", UTI_IPToString(&ip), port);
+    DEBUG_LOG(LOGF_CmdMon, "Could not send response to %s:%hu", UTI_IPToString(&ip), port);
   }
 }
   
@@ -1767,9 +1767,7 @@ read_from_cmd_socket(void *anything)
   memset(&tx_message.auth, 0, sizeof(tx_message.auth));
 
   if (rx_message.version != PROTO_VERSION_NUMBER) {
-    if (!LOG_RateLimited()) {
-      LOG(LOGS_WARN, LOGF_CmdMon, "Read command packet with protocol version %d (expected %d) from %s:%hu", rx_message.version, PROTO_VERSION_NUMBER, UTI_IPToString(&remote_ip), remote_port);
-    }
+    DEBUG_LOG(LOGF_CmdMon, "Read command packet with protocol version %d (expected %d) from %s:%hu", rx_message.version, PROTO_VERSION_NUMBER, UTI_IPToString(&remote_ip), remote_port);
 
     CLG_LogCommandAccess(&remote_ip, CLG_CMD_BAD_PKT, cooked_now.tv_sec);
 
@@ -1781,9 +1779,7 @@ read_from_cmd_socket(void *anything)
   }
 
   if (rx_command >= N_REQUEST_TYPES) {
-    if (!LOG_RateLimited()) {
-      LOG(LOGS_WARN, LOGF_CmdMon, "Read command packet with invalid command %d from %s:%hu", rx_command, UTI_IPToString(&remote_ip), remote_port);
-    }
+    DEBUG_LOG(LOGF_CmdMon, "Read command packet with invalid command %d from %s:%hu", rx_command, UTI_IPToString(&remote_ip), remote_port);
 
     CLG_LogCommandAccess(&remote_ip, CLG_CMD_BAD_PKT, cooked_now.tv_sec);
 
@@ -1793,9 +1789,7 @@ read_from_cmd_socket(void *anything)
   }
 
   if (read_length < expected_length) {
-    if (!LOG_RateLimited()) {
-      LOG(LOGS_WARN, LOGF_CmdMon, "Read incorrectly sized command packet from %s:%hu", UTI_IPToString(&remote_ip), remote_port);
-    }
+    DEBUG_LOG(LOGF_CmdMon, "Read incorrectly sized command packet from %s:%hu", UTI_IPToString(&remote_ip), remote_port);
 
     CLG_LogCommandAccess(&remote_ip, CLG_CMD_BAD_PKT, cooked_now.tv_sec);
 
@@ -1878,8 +1872,8 @@ read_from_cmd_socket(void *anything)
       tx_message_length = PKL_ReplyLength(prev_tx_message);
       status = sendto(sock_fd, (void *) prev_tx_message, tx_message_length, 0,
                       &where_from.u, from_length);
-      if (status < 0 && !LOG_RateLimited()) {
-        LOG(LOGS_WARN, LOGF_CmdMon, "Could not send response to %s:%hu", UTI_IPToString(&remote_ip), remote_port);
+      if (status < 0) {
+        DEBUG_LOG(LOGF_CmdMon, "Could not send response to %s:%hu", UTI_IPToString(&remote_ip), remote_port);
       }
       return;
     }
@@ -2006,8 +2000,8 @@ read_from_cmd_socket(void *anything)
 
         case REQ_LOGON:
           /* If the log-on fails, record the reason why */
-          if (!issue_token && !LOG_RateLimited()) {
-            LOG(LOGS_WARN, LOGF_CmdMon,
+          if (!issue_token) {
+            DEBUG_LOG(LOGF_CmdMon,
                 "Bad command logon from %s port %d (auth_ok=%d valid_ts=%d)",
                 UTI_IPToString(&remote_ip),
                 remote_port,
index 42072ba94dba4e558ad4deff130fd1d93863cb79..fc08595b3ab45153061e8d9d1db47c78c21ffa8d 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -49,8 +49,6 @@ static int parent_fd = 0;
 #define DEBUG_LEVEL_PRINT_DEBUG 2
 static int debug_level = 0;
 
-static time_t last_limited = 0;
-
 #ifdef WINNT
 static FILE *logfile;
 #endif
@@ -242,22 +240,6 @@ LOG_CloseParentFd()
 
 /* ================================================== */
 
-int
-LOG_RateLimited(void)
-{
-  time_t now;
-
-  now = time(NULL);
-
-  if (last_limited + 10 > now && last_limited <= now)
-    return 1;
-
-  last_limited = now;
-  return 0;
-}
-
-/* ================================================== */
-
 LOG_FileID
 LOG_FileOpen(const char *name, const char *banner)
 {
index 70cff5a6e86bcc881a7c8bd11077e76135cea3aa..9477cbaef93b74f5424d02d7200cd3850f3e6958 100644 (file)
--- a/logging.h
+++ b/logging.h
@@ -123,9 +123,6 @@ extern void LOG_SetParentFd(int fd);
 /* Close the pipe to the foreground process so it can exit */
 extern void LOG_CloseParentFd(void);
 
-/* Return zero once per 10 seconds */
-extern int LOG_RateLimited(void);
-
 /* File logging functions */
 
 typedef int LOG_FileID;
index f5b40e7c82e9c7f8309ea1b71c4fe38f1193ef0b..6bc5bfbcc3f27df5fb0639316dd3f4fe665cf798 100644 (file)
@@ -1567,8 +1567,8 @@ NCR_ProcessUnknown
                         local_addr);
       }
     }
-  } else if (!LOG_RateLimited()) {
-    LOG(LOGS_WARN, LOGF_NtpCore, "NTP packet received from unauthorised host %s port %d",
+  } else {
+    DEBUG_LOG(LOGF_NtpCore, "NTP packet received from unauthorised host %s port %d",
         UTI_IPToString(&remote_addr->ip_addr),
         remote_addr->port);
   }
index 639ec46c73403acba2024d0681f6b534fdcbb273..f84becc5259b260ab1a1e72b38385f88ae09af54 100644 (file)
--- a/ntp_io.c
+++ b/ntp_io.c
@@ -675,15 +675,8 @@ send_packet(void *packet, int packetlen, NTP_Remote_Address *remote_addr, NTP_Lo
   if (!cmsglen)
     msg.msg_control = NULL;
 
-  if (sendmsg(local_addr->sock_fd, &msg, 0) < 0 &&
-#ifdef ENETUNREACH
-      errno != ENETUNREACH &&
-#endif
-#ifdef ENETDOWN
-      errno != ENETDOWN &&
-#endif
-      !LOG_RateLimited()) {
-    LOG(LOGS_WARN, LOGF_NtpIO, "Could not send to %s:%d : %s",
+  if (sendmsg(local_addr->sock_fd, &msg, 0) < 0) {
+    DEBUG_LOG(LOGF_NtpIO, "Could not send to %s:%d : %s",
         UTI_IPToString(&remote_addr->ip_addr), remote_addr->port, strerror(errno));
   }
 }