From b0c3db2d98b74ec6fef30973500cdcab30a890f6 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 28 Oct 2007 09:57:17 +0100 Subject: [PATCH] plugin.h: Make DEBUG() a noop when compiling without debugging support. 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 Signed-off-by: Florian Forster --- 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 4f0bdfa6..174febe4 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 0432de73..0a93920b 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 384ecb5e..bad1a388 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 63b037a6..9e09f819 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 4ca6c771..7692ebdb 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, ...); -- 2.11.0