On Tuesday 28 July 2009 02:24:15 Sebastian Harl wrote:
>
> What do you think about using interval_g instead (or interval_g / 2 and
> / or setting some maximum value)? Basically, that should not make a big
> difference, but, imho, it's a bit cleaner to let recv() fail before the
> end of the read interval.
>

sounds good. how about max( 2, interval_g * 3 / 4  )?
Updated the patch. Also fixed the error message to mention the LocalSocket 
config, not the Plugin config. Compiled the package with these modifications, 
but 
didn't install or run.

Luke Heberling
--- collectd-4.6.3.broken/src/powerdns.c	2009-06-02 02:17:47.000000000 -0700
+++ collectd-4.6.3/src/powerdns.c	2009-07-28 17:45:22.000000000 -0700
@@ -380,6 +380,18 @@ static int powerdns_get_data_dgram (list
       break;
     }
 
+    struct timeval timeout;
+    timeout.tv_sec=2;
+    if (timeout.tv_sec < interval_g * 3 / 4)
+      timeout.tv_sec = interval_g * 3 / 4;
+    timeout.tv_usec=0;
+    status = setsockopt (sd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof (timeout));
+    if (status != 0)
+    {
+      FUNC_ERROR ("setsockopt");
+      break;
+    }
+
     status = connect (sd, (struct sockaddr *) &item->sockaddr,
         sizeof (item->sockaddr));
     if (status != 0)
@@ -911,11 +923,18 @@ static int powerdns_config (oconfig_item
       powerdns_config_add_server (option);
     else if (strcasecmp ("LocalSocket", option->key) == 0)
     {
-      char *temp = strdup (option->key);
-      if (temp == NULL)
-        return (1);
-      sfree (local_sockpath);
-      local_sockpath = temp;
+      if ((option->values_num != 1) || (option->values[0].type != OCONFIG_TYPE_STRING))
+      {
+        WARNING ("powerdns plugin: `%s' needs exactly one string argument.", option->key);
+      }
+      else
+      {
+        char *temp = strdup (option->values[0].value.string);
+        if (temp == NULL)
+          return (1);
+        sfree (local_sockpath);
+        local_sockpath = temp;
+      }
     }
     else
     {

Reply via email to