Merge pull request #2376 from zerkms/ISSUE-2358
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Tue, 3 Apr 2018 21:29:17 +0000 (23:29 +0200)
committerGitHub <noreply@github.com>
Tue, 3 Apr 2018 21:29:17 +0000 (23:29 +0200)
Skip `0.0.0.0` hosts in ntpd plugin

1  2 
src/ntpd.c

diff --combined src/ntpd.c
@@@ -337,8 -337,10 +337,8 @@@ static int ntpd_connect(void) 
                                .ai_socktype = SOCK_DGRAM};
  
    if ((status = getaddrinfo(host, port, &ai_hints, &ai_list)) != 0) {
 -    char errbuf[1024];
      ERROR("ntpd plugin: getaddrinfo (%s, %s): %s", host, port,
 -          (status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
 -                                 : gai_strerror(status));
 +          (status == EAI_SYSTEM) ? STRERRNO : gai_strerror(status));
      return -1;
    }
  
@@@ -407,7 -409,9 +407,7 @@@ static int ntpd_receive_response(int *r
    *res_data = NULL;
  
    if (gettimeofday(&time_end, NULL) < 0) {
 -    char errbuf[1024];
 -    ERROR("ntpd plugin: gettimeofday failed: %s",
 -          sstrerror(errno, errbuf, sizeof(errbuf)));
 +    ERROR("ntpd plugin: gettimeofday failed: %s", STRERRNO);
      return -1;
    }
    time_end.tv_sec++; /* wait for a most one second */
      struct timeval time_left;
  
      if (gettimeofday(&time_now, NULL) < 0) {
 -      char errbuf[1024];
 -      ERROR("ntpd plugin: gettimeofday failed: %s",
 -            sstrerror(errno, errbuf, sizeof(errbuf)));
 +      ERROR("ntpd plugin: gettimeofday failed: %s", STRERRNO);
        return -1;
      }
  
        continue;
  
      if (status < 0) {
 -      char errbuf[1024];
 -      ERROR("ntpd plugin: poll failed: %s",
 -            sstrerror(errno, errbuf, sizeof(errbuf)));
 +      ERROR("ntpd plugin: poll failed: %s", STRERRNO);
        return -1;
      }
  
        continue;
  
      if (status < 0) {
 -      char errbuf[1024];
 -      INFO("recv(2) failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
 +      INFO("recv(2) failed: %s", STRERRNO);
        DEBUG("Closing socket #%i", sd);
        close(sd);
        sock_descr = sd = -1;
       * Enough with the checks. Copy the data now.
       * We start by allocating some more memory.
       */
 -    DEBUG("realloc (%p, %zu)", (void *)*res_data,
 +    DEBUG("realloc (%p, %" PRIsz ")", (void *)*res_data,
            (items_num + pkt_item_num) * res_item_size);
      items = realloc(*res_data, (items_num + pkt_item_num) * res_item_size);
      if (items == NULL) {
@@@ -660,7 -669,7 +660,7 @@@ static int ntpd_send_request(int req_co
          (void *)req_data);
  
    status = swrite(sd, (const char *)&req, REQ_LEN_NOMAC);
 -  if (status < 0) {
 +  if (status != 0) {
      DEBUG("`swrite' failed. Closing socket #%i", sd);
      close(sd);
      sock_descr = sd = -1;
@@@ -754,8 -763,10 +754,8 @@@ static int ntpd_get_name_from_address(c
                         buffer_size, NULL, 0, /* No port name */
                         flags);
    if (status != 0) {
 -    char errbuf[1024];
      ERROR("ntpd plugin: getnameinfo failed: %s",
 -          (status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
 -                                 : gai_strerror(status));
 +          (status == EAI_SYSTEM) ? STRERRNO : gai_strerror(status));
      return -1;
    }
  
@@@ -835,9 -846,9 +835,9 @@@ static int ntpd_read(void) 
    }
  
    /* kerninfo -> estimated error */
 -  offset_loop = scale_loop * ((gauge_t)ntohl(ik->offset));
 +  offset_loop = (gauge_t)((int32_t)ntohl(ik->offset) * scale_loop);
    freq_loop = ntpd_read_fp(ik->freq);
 -  offset_error = scale_error * ((gauge_t)ntohl(ik->esterror));
 +  offset_error = (gauge_t)((int32_t)ntohl(ik->esterror) * scale_error);
  
    DEBUG("info_kernel:\n"
          "  pll offset    = %.8g\n"
        continue;
      }
  
+     // `0.0.0.0` hosts are caused by POOL servers
+     // see https://github.com/collectd/collectd/issues/2358
+     if (strcmp(peername, "0.0.0.0") == 0) {
+       continue;
+     }
      refclock_id = ntpd_get_refclock_id(ptr);
  
      /* Convert the `long floating point' offset value to double */