Merge branch 'collectd-4.6' into collectd-4.7
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sat, 20 Jun 2009 10:51:45 +0000 (12:51 +0200)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sat, 20 Jun 2009 10:51:45 +0000 (12:51 +0200)
src/dns.c
src/libcollectdclient/client.c
src/utils_cache.c

index 8339377..3de7c34 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -213,7 +213,7 @@ static void *dns_child_loop (void __attribute__((unused)) *dummy)
        }
 
        /* Passing `pcap_device == NULL' is okay and the same as passign "any" */
-       DEBUG ("Creating PCAP object..");
+       DEBUG ("dns plugin: Creating PCAP object..");
        pcap_obj = pcap_open_live ((pcap_device != NULL) ? pcap_device : "any",
                        PCAP_SNAPLEN,
                        0 /* Not promiscuous */,
index 501c729..407493c 100644 (file)
@@ -116,7 +116,7 @@ typedef struct lcc_response_s lcc_response_t;
 /* Even though Posix requires "strerror_r" to return an "int",
  * some systems (e.g. the GNU libc) return a "char *" _and_
  * ignore the second argument ... -tokkee */
-char *sstrerror (int errnum, char *buf, size_t buflen)
+static char *sstrerror (int errnum, char *buf, size_t buflen)
 {
   buf[0] = 0;
 
index 2995501..3cfe3a1 100644 (file)
@@ -260,8 +260,9 @@ int uc_check_timeout (void)
          (keys_len + 1) * sizeof (char *));
       if (tmp == NULL)
       {
-       ERROR ("uc_purge: realloc failed.");
+       ERROR ("uc_check_timeout: realloc failed.");
        c_avl_iterator_destroy (iter);
+       sfree (keys);
        pthread_mutex_unlock (&cache_lock);
        return (-1);
       }
@@ -277,6 +278,8 @@ int uc_check_timeout (void)
     }
   } /* while (c_avl_iterator_next) */
 
+  ce = NULL;
+
   for (i = 0; i < keys_len; i++)
   {
     int status;
@@ -287,10 +290,10 @@ int uc_check_timeout (void)
     {
       ERROR ("uc_check_timeout: ut_check_interesting failed.");
       sfree (keys[i]);
+      continue;
     }
     else if (status == 0) /* ``service'' is uninteresting */
     {
-      ce = NULL;
       DEBUG ("uc_check_timeout: %s is missing but ``uninteresting''",
          keys[i]);
       status = c_avl_remove (cache_tree, keys[i],
@@ -303,11 +306,23 @@ int uc_check_timeout (void)
       sfree (key);
       cache_free (ce);
     }
-    else if (status == 2) /* persist */
+
+    /* If we get here, the value is ``interesting''. Query the record from the
+     * cache and update the state field. */
+    if (c_avl_get (cache_tree, keys[i], (void *) &ce) != 0)
+    {
+      ERROR ("uc_check_timeout: cannot get data for %s from cache", keys[i]);
+      /* Do not free `keys[i]' so a notification is sent further down. */
+      continue;
+    }
+    assert (ce != NULL);
+
+    if (status == 2) /* persist */
     {
       DEBUG ("uc_check_timeout: %s is missing, sending notification.",
          keys[i]);
       ce->state = STATE_MISSING;
+      /* Do not free `keys[i]' so a notification is sent further down. */
     }
     else if (status == 1) /* do not persist */
     {
@@ -316,6 +331,7 @@ int uc_check_timeout (void)
        DEBUG ("uc_check_timeout: %s is missing but "
            "notification has already been sent.",
            keys[i]);
+       /* Set `keys[i]' to NULL to no notification is sent. */
        sfree (keys[i]);
       }
       else /* (ce->state != STATE_MISSING) */
@@ -323,6 +339,7 @@ int uc_check_timeout (void)
        DEBUG ("uc_check_timeout: %s is missing, sending one notification.",
            keys[i]);
        ce->state = STATE_MISSING;
+       /* Do not free `keys[i]' so a notification is sent further down. */
       }
     }
     else
@@ -330,6 +347,7 @@ int uc_check_timeout (void)
       WARNING ("uc_check_timeout: ut_check_interesting (%s) returned "
          "invalid status %i.",
          keys[i], status);
+      sfree (keys[i]);
     }
   } /* for (keys[i]) */