Merge branch 'collectd-4.5'
authorFlorian Forster <octo@noris.net>
Fri, 10 Oct 2008 07:02:33 +0000 (09:02 +0200)
committerFlorian Forster <octo@noris.net>
Fri, 10 Oct 2008 07:02:33 +0000 (09:02 +0200)
Conflicts:

configure.in

README
configure.in
src/collectd-nagios.c
src/collectd-nagios.pod
src/configfile.c
src/netlink.c
src/network.c
src/utils_cache.c

diff --git a/README b/README
index 8c8160c..b6bdb41 100644 (file)
--- a/README
+++ b/README
@@ -472,9 +472,11 @@ Configuring / Compiling / Installing
   disable all plugins whose requirements cannot be fulfilled (any other plugin
   will be enabled). To enable a plugin, install missing dependencies (see
   section `Prerequisites' above) and rerun `configure'. If you specify the
-  `--enable-<plugin>' configure option, you can force the plugin to be built.
-  This will most likely fail though unless you're working in a very unusual
-  setup and you really know what you're doing.
+  `--enable-<plugin>' configure option, the script will fail if the depen-
+  dencies for the specified plugin are not met. If you specify the
+  `--disable-<plugin>' configure option, the plugin will not be built. Both
+  options are meant for package maintainers and should not be used in everyday
+  situations.
 
   By default, collectd will be installed into `/opt/collectd'. You can adjust
   this setting by specifying the `--prefix' configure option - see INSTALL for
index ffaacc3..d416e69 100644 (file)
@@ -2567,7 +2567,13 @@ AC_DEFUN(
     ])
     if test "x$enable_plugin" = "xyes"
     then
-           AC_DEFINE([HAVE_PLUGIN_]my_toupper([$1]), 1, [Define to 1 if the $1 plugin is enabled.])
+           if test "x$2" = "xyes"
+           then
+                   AC_DEFINE([HAVE_PLUGIN_]my_toupper([$1]), 1, [Define to 1 if the $1 plugin is enabled.])
+           else # User passed "yes" but dependency checking yielded "no" => Dependency problem.
+                   dependency_error="yes"
+                   enable_plugin="no (dependency error)"
+           fi
     fi
     AM_CONDITIONAL([BUILD_PLUGIN_]my_toupper([$1]), test "x$enable_plugin" = "xyes")
     enable_$1="$enable_plugin"
@@ -2581,6 +2587,7 @@ AC_COLLECTD([debug],     [enable],  [feature], [debugging])
 AC_COLLECTD([daemon],    [disable], [feature], [daemon mode])
 AC_COLLECTD([getifaddrs],[enable],  [feature], [getifaddrs under Linux])
 
+dependency_error="no"
 plugin_ascent="no"
 plugin_battery="no"
 plugin_cpu="no"
@@ -3004,4 +3011,8 @@ Configuration:
 
 EOF
 
+if test "x$dependency_error" = "xyes"; then
+       AC_MSG_ERROR("Some plugins are missing dependencies - see above summary for details")
+fi
+
 # vim: set fdm=marker :
index 1bf5b3f..ca72a68 100644 (file)
@@ -150,6 +150,7 @@ static int get_values (int *ret_values_num, double **ret_values,
        char **values_names;
 
        int i;
+       int j;
 
        fd = socket (PF_UNIX, SOCK_STREAM, 0);
        if (fd < 0)
@@ -229,31 +230,58 @@ static int get_values (int *ret_values_num, double **ret_values,
                free (values);
                return (-1);
        }
+       memset (values_names, 0, values_num * sizeof (char *));
 
-       i = 0;
+       i = 0; /* index of the values returned by the server */
+       j = 0; /* number of values in `values_names' and `values' */
        while (fgets (buffer, sizeof (buffer), fh_in) != NULL)
        {
-               char *key;
-               char *value;
+               do /* while (0) */
+               {
+                       char *key;
+                       char *value;
+                       char *endptr;
+
+                       key = buffer;
 
-               key = buffer;
+                       value = strchr (key, '=');
+                       if (value == NULL)
+                       {
+                               fprintf (stderr, "Cannot parse line: %s\n", buffer);
+                               break;
+                       }
+                       *value = 0;
+                       value++;
 
-               value = strchr (key, '=');
-               if (value == NULL)
-                       continue;
-               *value = '\0'; value++;
+                       if (ignore_ds (key) != 0)
+                               break;
 
-               if (ignore_ds (key) != 0)
-                       continue;
+                       endptr = NULL;
+                       errno = 0;
+                       values[j] = strtod (value, &endptr);
+                       if ((endptr == value) || (errno != 0))
+                       {
+                               fprintf (stderr, "Could not parse buffer "
+                                               "as number: %s\n", value);
+                               break;
+                       }
 
-               values_names[i] = strdup (key);
-               values[i] = atof (value);
+                       values_names[j] = strdup (key);
+                       if (values_names[j] == NULL)
+                       {
+                               fprintf (stderr, "strdup failed.\n");
+                               break;
+                       }
+                       j++;
+               } while (0);
 
                i++;
                if (i >= values_num)
                        break;
        }
-       values_num = i;
+       /* Set `values_num' to the number of values actually stored in the
+        * array. */
+       values_num = j;
 
        fclose (fh_in); fh_in = NULL; fd = -1;
        fclose (fh_out); fh_out = NULL;
index 7b2442e..4980025 100644 (file)
@@ -45,7 +45,7 @@ handled according to the consolidation function given with the B<-g> option.
 
 =item B<-g> B<none>I<|>B<average>I<|>B<sum>
 
-When multiple data sources are selected from a value spec they can be handled
+When multiple data sources are selected from a value spec, they can be handled
 differently depending on this option. The values of the following meaning:
 
 =over 4
@@ -71,22 +71,32 @@ The warning and critical ranges are applied to the sum of all values.
 
 Set the critical (B<-c>) and warning (B<-w>) ranges. These options mostly
 follow the normal syntax of Nagios plugins. The general format is
-"I<min>B<:>I<max>". If a value if smaller than I<min> or bigger than I<max> a
-warning or critical is returned, otherwise okay is returned. I<min> (and the
-colon) may be omitted and are then assumed to be zero. If I<max> (but not the
-colon) is omitted I<max> is set to positive infinity. If either I<min> or
-I<max> if set to B<~> they are set to negative and positive infinity,
-respectively.
+"I<min>B<:>I<max>". If a value is smaller than I<min> or bigger than I<max>, a
+I<warning> or I<critical> status is returned, otherwise the status is
+I<success>.
+
+The tilde sign (B<~>) can be used to explicitly specify infinity. If B<~> is
+used as a I<min> value, negative infinity is used. In case of I<max>, it is
+interpreted as positive infinity.
+
+If the first character of the I<range> is the atE<nbsp>sign (B<@>), the meaning
+of the range will be inverted. I.E<nbsp>e. all values I<within> the range will
+yield a I<warning> or I<critical> status, while all values I<outside> the range
+will result in a I<success> status.
+
+I<min> (and the colon) may be omitted,
+I<min> is then assumed to be zero. If I<max> (but not the trailing colon) is
+omitted, I<max> is assumed to be positive infinity.
 
 =back
 
 =head1 RETURN VALUE
 
-As usual for Nagios plugins this program writes a short, one line status
+As usual for Nagios plugins, this program writes a short, one line status
 message to STDOUT and signals success or failure with it's return value. It
-exists with a return value of B<0> for success or B<1> or B<2> for warning and
-critical, respectively. If the values is not available or some other error
-occurred it returns B<3> for "unknown"
+exits with a return value of B<0> for I<success>, B<1> for I<warning> and B<2>
+for I<critical>. If the values are not available or some other error occurred,
+it returns B<3> for I<unknown>
 
 =head1 SEE ALSO
 
index d483032..9609086 100644 (file)
@@ -887,7 +887,11 @@ int cf_read (char *filename)
                        dispatch_block (conf->children + i);
        }
 
+       oconfig_free (conf);
+
+       /* Read the default types.db if no `TypesDB' option was given. */
        if (cf_default_typesdb)
-               read_types_list (PLUGINDIR"/types.db"); /* FIXME: Configure path */
+               read_types_list (PLUGINDIR"/types.db");
+
        return (0);
 } /* int cf_read */
index c2e4c9b..d14e510 100644 (file)
@@ -364,7 +364,7 @@ static int qos_filter (const struct sockaddr_nl *sa,
   if (msg->tcm_ifindex >= iflist_len)
   {
     ERROR ("netlink plugin: qos_filter: msg->tcm_ifindex = %i "
-       ">= iflist_len = %i",
+       ">= iflist_len = %zu",
        msg->tcm_ifindex, iflist_len);
     return (-1);
   }
index 39069aa..fbbcd12 100644 (file)
@@ -1548,7 +1548,10 @@ static int network_config (const char *key, const char *val)
                fields_num = strsplit (val_cpy, fields, 3);
                if ((fields_num != 1)
                                && (fields_num != 2))
+               {
+                       sfree (val_cpy);
                        return (1);
+               }
                else if (fields_num == 2)
                {
                        if ((service = strchr (fields[1], '.')) != NULL)
@@ -1561,6 +1564,8 @@ static int network_config (const char *key, const char *val)
                        network_add_listen_socket (node, service);
                else
                        network_add_sending_socket (node, service);
+
+               sfree (val_cpy);
        }
        else if (strcasecmp ("TimeToLive", key) == 0)
        {
index d0e77ef..241aa72 100644 (file)
@@ -298,6 +298,7 @@ int uc_check_timeout (void)
        ERROR ("uc_check_timeout: c_avl_remove (%s) failed.", keys[i]);
       }
       sfree (keys[i]);
+      sfree (key);
       cache_free (ce);
     }
     else if (status == 1) /* persist */