[collectd] [PATCH] plugin.h: Make DEBUG() a noop when compiling without debugging support.

Sebastian Harl sh at tokkee.org
Sun Oct 28 09:57:17 CET 2007


This saves a couple of useless calls to plugin_log() which the compiler
does not detect and remove itself.

A couple of DEBUG()'s in the apcups, hddtemp, mbmon and ntpd plugins have
been upgraded to INFO()'s. All of them provide error messages of failed
system / libc calls which should be available to the user somehow.
Besides, they use a local string buffer which generates an "unused
variable" warning if DEBUG() expands to a noop.

Signed-off-by: Sebastian Harl <sh at tokkee.org>
---
 src/apcups.c  |    4 ++--
 src/hddtemp.c |    2 +-
 src/mbmon.c   |    2 +-
 src/ntpd.c    |    2 +-
 src/plugin.h  |    6 +++++-
 5 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/apcups.c b/src/apcups.c
index 4f0bdfa..174febe 100644
--- a/src/apcups.c
+++ b/src/apcups.c
@@ -136,7 +136,7 @@ static int net_open (char *host, char *service, int port)
 	if (status != 0)
 	{
 		char errbuf[1024];
-		DEBUG ("getaddrinfo failed: %s",
+		INFO ("getaddrinfo failed: %s",
 				(status == EAI_SYSTEM)
 				? sstrerror (errno, errbuf, sizeof (errbuf))
 				: gai_strerror (status));
@@ -167,7 +167,7 @@ static int net_open (char *host, char *service, int port)
 	if (status != 0) /* `connect(2)' failed */
 	{
 		char errbuf[1024];
-		DEBUG ("connect failed: %s",
+		INFO ("connect failed: %s",
 				sstrerror (errno, errbuf, sizeof (errbuf)));
 		close (sd);
 		return (-1);
diff --git a/src/hddtemp.c b/src/hddtemp.c
index 0432de7..0a93920 100644
--- a/src/hddtemp.c
+++ b/src/hddtemp.c
@@ -144,7 +144,7 @@ static int hddtemp_query_daemon (char *buffer, int buffer_size)
 		if (connect (fd, (struct sockaddr *) ai_ptr->ai_addr, ai_ptr->ai_addrlen))
 		{
 			char errbuf[1024];
-			DEBUG ("hddtemp: connect (%s, %s): %s", host, port,
+			INFO ("hddtemp: connect (%s, %s): %s", host, port,
 					sstrerror (errno, errbuf, sizeof (errbuf)));
 			close (fd);
 			fd = -1;
diff --git a/src/mbmon.c b/src/mbmon.c
index 384ecb5..bad1a38 100644
--- a/src/mbmon.c
+++ b/src/mbmon.c
@@ -132,7 +132,7 @@ static int mbmon_query_daemon (char *buffer, int buffer_size)
 		if (connect (fd, (struct sockaddr *) ai_ptr->ai_addr, ai_ptr->ai_addrlen))
 		{
 			char errbuf[1024];
-			DEBUG ("mbmon: connect (%s, %s): %s", host, port,
+			INFO ("mbmon: connect (%s, %s): %s", host, port,
 					sstrerror (errno, errbuf,
 						sizeof (errbuf)));
 			close (fd);
diff --git a/src/ntpd.c b/src/ntpd.c
index 63b037a..9e09f81 100644
--- a/src/ntpd.c
+++ b/src/ntpd.c
@@ -493,7 +493,7 @@ static int ntpd_receive_response (int req_code, int *res_items, int *res_size,
 		if (status < 0)
 		{
 			char errbuf[1024];
-			DEBUG ("recv(2) failed: %s",
+			INFO ("recv(2) failed: %s",
 					sstrerror (errno, errbuf, sizeof (errbuf)));
 			DEBUG ("Closing socket #%i", sd);
 			close (sd);
diff --git a/src/plugin.h b/src/plugin.h
index 4ca6c77..7692ebd 100644
--- a/src/plugin.h
+++ b/src/plugin.h
@@ -193,7 +193,11 @@ void plugin_log (int level, const char *format, ...);
 #define WARNING(...) plugin_log (LOG_WARNING, __VA_ARGS__)
 #define NOTICE(...)  plugin_log (LOG_NOTICE,  __VA_ARGS__)
 #define INFO(...)    plugin_log (LOG_INFO,    __VA_ARGS__)
-#define DEBUG(...)   plugin_log (LOG_DEBUG,   __VA_ARGS__)
+#if COLLECT_DEBUG
+# define DEBUG(...)  plugin_log (LOG_DEBUG,   __VA_ARGS__)
+#else /* COLLECT_DEBUG */
+# define DEBUG(...)  /* noop */
+#endif /* ! COLLECT_DEBUG */
 
 /* TODO: Move plugin_{complain,relief} into `utils_complain.[ch]'. -octo */
 void plugin_complain (int level, complain_t *c, const char *format, ...);
-- 
1.5.3.4.395.g85b0

-------------- 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/20071028/a2f3d5d1/attachment.pgp 


More information about the collectd mailing list