[collectd] [PATCH] Use -Wall -Werror (AM_CFLAGS) when building any module.

Sebastian Harl sh at tokkee.org
Mon Jun 16 23:02:36 CEST 2008


A few plugins have to set custom CFLAGS. When using "<plugin>_la_CFLAGS =",
$(AM_CFLAGS) will no longer be used when compiling <plugin> as that resets the
CFLAGS to the empty string. So, in that case, we have to explicitly add
$(AM_CFLAGS) to the custom CFLAGS of that plugin.

After doing so, a couple of problems have been identified which have been
fixed in this patch as well. That includes a possible SEGFAULT in the snmp
plugin which was missing an argument to WARNING().

Signed-off-by: Sebastian Harl <sh at tokkee.org>
---
 src/Makefile.am      |   45 +++++++++++++++++++++++----------------------
 src/netlink.c        |    4 ++--
 src/notify_desktop.c |    1 +
 src/plugin.c         |    4 +++-
 src/rrdtool.c        |   19 +++++++++++--------
 src/snmp.c           |    6 +++---
 src/utils_cache.c    |    2 +-
 7 files changed, 44 insertions(+), 37 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 5e12742..4e157fa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -42,7 +42,7 @@ collectd_SOURCES = collectd.c collectd.h \
 		   types_list.c types_list.h
 
 collectd_CPPFLAGS =  $(AM_CPPFLAGS) $(LTDLINCL)
-collectd_CFLAGS =
+collectd_CFLAGS = $(AM_CFLAGS)
 collectd_LDFLAGS = -export-dynamic
 collectd_LDADD =
 collectd_DEPENDENCIES =
@@ -96,7 +96,7 @@ if BUILD_PLUGIN_APACHE
 pkglib_LTLIBRARIES += apache.la
 apache_la_SOURCES = apache.c
 apache_la_LDFLAGS = -module -avoid-version
-apache_la_CFLAGS =
+apache_la_CFLAGS = $(AM_CFLAGS)
 apache_la_LIBADD =
 collectd_LDADD += "-dlopen" apache.la
 if BUILD_WITH_LIBCURL
@@ -129,7 +129,8 @@ if BUILD_PLUGIN_ASCENT
 pkglib_LTLIBRARIES += ascent.la
 ascent_la_SOURCES = ascent.c
 ascent_la_LDFLAGS = -module -avoid-version
-ascent_la_CFLAGS = $(BUILD_WITH_LIBCURL_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
+ascent_la_CFLAGS = $(AM_CFLAGS) \
+		$(BUILD_WITH_LIBCURL_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
 ascent_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
 collectd_LDADD += "-dlopen" apache.la
 collectd_DEPENDENCIES += ascent.la
@@ -149,7 +150,7 @@ endif
 if BUILD_PLUGIN_CPU
 pkglib_LTLIBRARIES += cpu.la
 cpu_la_SOURCES = cpu.c
-cpu_la_CFLAGS =
+cpu_la_CFLAGS = $(AM_CFLAGS)
 cpu_la_LDFLAGS = -module -avoid-version
 cpu_la_LIBADD = 
 if BUILD_WITH_LIBKSTAT
@@ -193,7 +194,7 @@ endif
 if BUILD_PLUGIN_DISK
 pkglib_LTLIBRARIES += disk.la
 disk_la_SOURCES = disk.c
-disk_la_CFLAGS =
+disk_la_CFLAGS = $(AM_CFLAGS)
 disk_la_LDFLAGS = -module -avoid-version
 disk_la_LIBADD = 
 if BUILD_WITH_LIBKSTAT
@@ -267,7 +268,7 @@ endif
 if BUILD_PLUGIN_INTERFACE
 pkglib_LTLIBRARIES += interface.la
 interface_la_SOURCES = interface.c
-interface_la_CFLAGS =
+interface_la_CFLAGS = $(AM_CFLAGS)
 interface_la_LDFLAGS = -module -avoid-version
 interface_la_LIBADD =
 collectd_LDADD += "-dlopen" interface.la
@@ -302,7 +303,7 @@ endif
 if BUILD_PLUGIN_IPMI
 pkglib_LTLIBRARIES += ipmi.la
 ipmi_la_SOURCES = ipmi.c
-ipmi_la_CFLAGS = $(BUILD_WITH_OPENIPMI_CFLAGS)
+ipmi_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_OPENIPMI_CFLAGS)
 ipmi_la_LDFLAGS = -module -avoid-version
 ipmi_la_LIBADD = $(BUILD_WITH_OPENIPMI_LIBS)
 collectd_LDADD += "-dlopen" ipmi.la
@@ -328,7 +329,8 @@ endif
 if BUILD_PLUGIN_LIBVIRT
 pkglib_LTLIBRARIES += libvirt.la
 libvirt_la_SOURCES = libvirt.c
-libvirt_la_CFLAGS = $(BUILD_WITH_LIBVIRT_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
+libvirt_la_CFLAGS = $(AM_CFLAGS) \
+		$(BUILD_WITH_LIBVIRT_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
 libvirt_la_LIBADD = $(BUILD_WITH_LIBVIRT_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
 libvirt_la_LDFLAGS = -module -avoid-version
 collectd_LDADD += "-dlopen" libvirt.la
@@ -338,7 +340,7 @@ endif
 if BUILD_PLUGIN_LOAD
 pkglib_LTLIBRARIES += load.la
 load_la_SOURCES = load.c
-load_la_CFLAGS =
+load_la_CFLAGS = $(AM_CFLAGS)
 load_la_LDFLAGS = -module -avoid-version
 load_la_LIBADD =
 collectd_LDADD += "-dlopen" load.la
@@ -372,7 +374,6 @@ if BUILD_PLUGIN_MEMCACHED
 pkglib_LTLIBRARIES += memcached.la
 memcached_la_SOURCES = memcached.c
 memcached_la_LDFLAGS = -module -avoid-version
-memcached_la_CFLAGS =
 memcached_la_LIBADD =
 if BUILD_WITH_LIBSOCKET
 memcached_la_LDFLAGS += -lsocket
@@ -384,7 +385,7 @@ endif
 if BUILD_PLUGIN_MEMORY
 pkglib_LTLIBRARIES += memory.la
 memory_la_SOURCES = memory.c
-memory_la_CFLAGS =
+memory_la_CFLAGS = $(AM_CFLAGS)
 memory_la_LDFLAGS = -module -avoid-version
 memory_la_LIBADD =
 collectd_LDADD += "-dlopen" memory.la
@@ -413,7 +414,7 @@ if BUILD_PLUGIN_MYSQL
 pkglib_LTLIBRARIES += mysql.la
 mysql_la_SOURCES = mysql.c
 mysql_la_LDFLAGS = -module -avoid-version
-mysql_la_CFLAGS =
+mysql_la_CFLAGS = $(AM_CFLAGS)
 mysql_la_LIBADD =
 collectd_LDADD += "-dlopen" mysql.la
 if BUILD_WITH_LIBMYSQL
@@ -427,7 +428,7 @@ if BUILD_PLUGIN_NETLINK
 pkglib_LTLIBRARIES += netlink.la
 netlink_la_SOURCES = netlink.c
 netlink_la_LDFLAGS = -module -avoid-version
-netlink_la_CFLAGS = $(BUILD_WITH_LIBNETLINK_CFLAGS)
+netlink_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBNETLINK_CFLAGS)
 netlink_la_LIBADD = $(BUILD_WITH_LIBNETLINK_LIBS)
 collectd_LDADD += "-dlopen" netlink.la
 collectd_DEPENDENCIES += netlink.la
@@ -472,7 +473,7 @@ endif
 if BUILD_PLUGIN_NOTIFY_DESKTOP
 pkglib_LTLIBRARIES += notify_desktop.la
 notify_desktop_la_SOURCES = notify_desktop.c
-notify_desktop_la_CFLAGS = $(LIBNOTIFY_CFLAGS)
+notify_desktop_la_CFLAGS = $(AM_CFLAGS) $(LIBNOTIFY_CFLAGS)
 notify_desktop_la_LDFLAGS = -module -avoid-version $(LIBNOTIFY_LIBS)
 collectd_LDADD += "-dlopen" notify_desktop.la
 collectd_DEPENDENCIES += notify_desktop.la
@@ -510,10 +511,10 @@ if BUILD_PLUGIN_PERL
 pkglib_LTLIBRARIES += perl.la
 perl_la_SOURCES = perl.c
 perl_la_CFLAGS  = $(AM_CFLAGS) \
-		  $(PERL_CFLAGS) \
-		  -DXS_VERSION=\"$(VERSION)\" -DVERSION=\"$(VERSION)\"
+		$(PERL_CFLAGS) \
+		-DXS_VERSION=\"$(VERSION)\" -DVERSION=\"$(VERSION)\"
 perl_la_LDFLAGS = -module -avoid-version \
-		  $(PERL_LDFLAGS)
+		$(PERL_LDFLAGS)
 collectd_LDADD += "-dlopen" perl.la
 collectd_DEPENDENCIES += perl.la
 endif
@@ -552,7 +553,7 @@ if BUILD_PLUGIN_RRDTOOL
 pkglib_LTLIBRARIES += rrdtool.la
 rrdtool_la_SOURCES = rrdtool.c
 rrdtool_la_LDFLAGS = -module -avoid-version
-rrdtool_la_CFLAGS = $(BUILD_WITH_LIBRRD_CFLAGS)
+rrdtool_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBRRD_CFLAGS)
 rrdtool_la_LIBADD = $(BUILD_WITH_LIBRRD_LDFLAGS)
 collectd_LDADD += "-dlopen" rrdtool.la
 collectd_DEPENDENCIES += rrdtool.la
@@ -561,7 +562,7 @@ endif
 if BUILD_PLUGIN_SENSORS
 pkglib_LTLIBRARIES += sensors.la
 sensors_la_SOURCES = sensors.c
-sensors_la_CFLAGS = $(BUILD_WITH_LIBSENSORS_CFLAGS)
+sensors_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBSENSORS_CFLAGS)
 sensors_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBSENSORS_LDFLAGS)
 sensors_la_LIBADD = -lsensors
 collectd_LDADD += "-dlopen" sensors.la
@@ -580,7 +581,7 @@ if BUILD_PLUGIN_SNMP
 pkglib_LTLIBRARIES += snmp.la
 snmp_la_SOURCES = snmp.c
 snmp_la_LDFLAGS = -module -avoid-version
-snmp_la_CFLAGS =
+snmp_la_CFLAGS = $(AM_CFLAGS)
 snmp_la_LIBADD =
 if BUILD_WITH_LIBNETSNMP
 snmp_la_CFLAGS += $(BUILD_WITH_LIBSNMP_CFLAGS)
@@ -596,7 +597,7 @@ endif
 if BUILD_PLUGIN_SWAP
 pkglib_LTLIBRARIES += swap.la
 swap_la_SOURCES = swap.c
-swap_la_CFLAGS =
+swap_la_CFLAGS = $(AM_CFLAGS)
 swap_la_LDFLAGS = -module -avoid-version
 swap_la_LIBADD =
 collectd_LDADD += "-dlopen" swap.la
@@ -680,7 +681,7 @@ endif
 if BUILD_PLUGIN_USERS
 pkglib_LTLIBRARIES += users.la
 users_la_SOURCES = users.c
-users_la_CFLAGS =
+users_la_CFLAGS = $(AM_CFLAGS)
 users_la_LDFLAGS = -module -avoid-version
 users_la_LIBADD =
 if BUILD_WITH_LIBSTATGRAB
diff --git a/src/netlink.c b/src/netlink.c
index f597b01..d621da5 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -207,7 +207,7 @@ static void submit_two (const char *dev, const char *type,
 } /* void submit_two */
 
 static int link_filter (const struct sockaddr_nl *sa,
-    const struct nlmsghdr *nmh, void *args)
+    struct nlmsghdr *nmh, void *args)
 {
   struct ifinfomsg *msg;
   int msg_len;
@@ -317,7 +317,7 @@ static int link_filter (const struct sockaddr_nl *sa,
 } /* int link_filter */
 
 static int qos_filter (const struct sockaddr_nl *sa,
-    const struct nlmsghdr *nmh, void *args)
+    struct nlmsghdr *nmh, void *args)
 {
   struct tcmsg *msg;
   int msg_len;
diff --git a/src/notify_desktop.c b/src/notify_desktop.c
index 822b506..2e62e88 100644
--- a/src/notify_desktop.c
+++ b/src/notify_desktop.c
@@ -24,6 +24,7 @@
  */
 
 #include "collectd.h"
+#include "common.h"
 #include "plugin.h"
 #include "configfile.h"
 
diff --git a/src/plugin.c b/src/plugin.c
index 2d431db..4a25aaa 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -716,6 +716,7 @@ int plugin_flush (const char *plugin, int timeout, const char *identifier)
 
     (*callback) (timeout, identifier);
   }
+  return (0);
 } /* int plugin_flush */
 
 void plugin_shutdown_all (void)
@@ -1064,7 +1065,8 @@ int plugin_notification_meta_free (notification_t *n)
 
     if (this->type == NM_TYPE_STRING)
     {
-      sfree (this->value_string);
+      free ((char *)this->value_string);
+      this->value_string = NULL;
     }
     sfree (this);
 
diff --git a/src/rrdtool.c b/src/rrdtool.c
index b3bc381..fd499fd 100644
--- a/src/rrdtool.c
+++ b/src/rrdtool.c
@@ -332,7 +332,7 @@ static int ds_get (char ***ret, const data_set_t *ds, const value_list_t *vl)
 
 #if HAVE_THREADSAFE_LIBRRD
 static int srrd_create (char *filename, unsigned long pdp_step, time_t last_up,
-		int argc, char **argv)
+		int argc, const char **argv)
 {
 	int status;
 
@@ -350,7 +350,8 @@ static int srrd_create (char *filename, unsigned long pdp_step, time_t last_up,
 	return (status);
 } /* int srrd_create */
 
-static int srrd_update (char *filename, char *template, int argc, char **argv)
+static int srrd_update (char *filename, char *template,
+		int argc, const char **argv)
 {
 	int status;
 
@@ -371,7 +372,7 @@ static int srrd_update (char *filename, char *template, int argc, char **argv)
 
 #else /* !HAVE_THREADSAFE_LIBRRD */
 static int srrd_create (char *filename, unsigned long pdp_step, time_t last_up,
-		int argc, char **argv)
+		int argc, const char **argv)
 {
 	int status;
 
@@ -423,7 +424,8 @@ static int srrd_create (char *filename, unsigned long pdp_step, time_t last_up,
 	return (status);
 } /* int srrd_create */
 
-static int srrd_update (char *filename, char *template, int argc, char **argv)
+static int srrd_update (char *filename, char *template,
+		int argc, const char **argv)
 {
 	int status;
 
@@ -508,7 +510,7 @@ static int rrd_create_file (char *filename, const data_set_t *ds, const value_li
 	status = srrd_create (filename,
 			(stepsize > 0) ? stepsize : vl->interval,
 			vl->time - 10,
-			argc, argv);
+			argc, (const char **)argv);
 
 	free (argv);
 	ds_free (ds_num, ds_def);
@@ -648,7 +650,8 @@ static void *rrd_queue_thread (void *data)
 		pthread_mutex_unlock (&cache_lock);
 
 		/* Write the values to the RRD-file */
-		srrd_update (queue_entry->filename, NULL, values_num, values);
+		srrd_update (queue_entry->filename, NULL,
+				values_num, (const char **)values);
 		DEBUG ("rrdtool plugin: queue thread: Wrote %i values to %s",
 				values_num, queue_entry->filename);
 
@@ -942,9 +945,9 @@ static int rrd_cache_insert (const char *filename,
 	}
 
 	DEBUG ("rrdtool plugin: rrd_cache_insert: file = %s; "
-			"values_num = %i; age = %u;",
+			"values_num = %i; age = %lu;",
 			filename, rc->values_num,
-			rc->last_value - rc->first_value);
+			(unsigned long)(rc->last_value - rc->first_value));
 
 	if ((rc->last_value - rc->first_value) >= cache_timeout)
 	{
diff --git a/src/snmp.c b/src/snmp.c
index 6f11af0..75fa880 100644
--- a/src/snmp.c
+++ b/src/snmp.c
@@ -780,7 +780,7 @@ static int csnmp_check_res_left_subtree (const host_definition_t *host,
     if (vb == NULL)
     {
       ERROR ("snmp plugin: host %s: Expected one more variable for "
-	  "the instance..");
+	  "the instance..", host->name);
       return (-1);
     }
 
@@ -1395,8 +1395,8 @@ static int csnmp_read_host (host_definition_t *host)
   if ((time_end - time_start) > host->interval)
   {
     WARNING ("snmp plugin: Host `%s' should be queried every %i seconds, "
-	"but reading all values takes %i seconds.",
-	host->name, host->interval, time_end - time_start);
+	"but reading all values takes %lu seconds.",
+	host->name, host->interval, (unsigned long)(time_end - time_start));
   }
 
   return (0);
diff --git a/src/utils_cache.c b/src/utils_cache.c
index d7d31c5..04075f5 100644
--- a/src/utils_cache.c
+++ b/src/utils_cache.c
@@ -324,7 +324,7 @@ int uc_check_timeout (void)
     }
     else
     {
-      WARNING ("uc_check_timeout: ut_check_interesting (%s) returned ",
+      WARNING ("uc_check_timeout: ut_check_interesting (%s) returned "
 	  "invalid status %i.",
 	  keys[i], status);
     }
-- 
1.5.6.rc2

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20080616/158922ee/attachment.pgp 


More information about the collectd mailing list