From f5edd182195cb7a13fa32846ae869a8b8dcc1e3f Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 19 Dec 2008 18:20:41 +0100 Subject: [PATCH] Do not use *printf() to report errors / debugging messages. The only exception to that is during configuration (which is done before daemonization) to let the user know about problems immediately. --- src/common.c | 4 ++-- src/email.c | 6 ++++++ src/ipmi.c | 4 ++-- src/rrdtool.c | 9 +++++++++ src/utils_dns.c | 6 +++--- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/common.c b/src/common.c index 82b4aaae..8dbf976f 100644 --- a/src/common.c +++ b/src/common.c @@ -527,12 +527,12 @@ long long get_kstat_value (kstat_t *ksp, char *name) #else if (ksp == NULL) { - fprintf (stderr, "ERROR: %s:%i: ksp == NULL\n", __FILE__, __LINE__); + ERROR ("ERROR: %s:%i: ksp == NULL\n", __FILE__, __LINE__); return (-1LL); } else if (ksp->ks_type != KSTAT_TYPE_NAMED) { - fprintf (stderr, "ERROR: %s:%i: ksp->ks_type != KSTAT_TYPE_NAMED\n", __FILE__, __LINE__); + ERROR ("ERROR: %s:%i: ksp->ks_type != KSTAT_TYPE_NAMED\n", __FILE__, __LINE__); return (-1LL); } #endif diff --git a/src/email.c b/src/email.c index 0882ad46..cc68d3fc 100644 --- a/src/email.c +++ b/src/email.c @@ -187,12 +187,18 @@ static int email_config (const char *key, const char *value) fprintf (stderr, "email plugin: `MaxConns' was set to invalid " "value %li, will use default %i.\n", tmp, MAX_CONNS); + ERROR ("email plugin: `MaxConns' was set to invalid " + "value %li, will use default %i.\n", + tmp, MAX_CONNS); max_conns = MAX_CONNS; } else if (tmp > MAX_CONNS_LIMIT) { fprintf (stderr, "email plugin: `MaxConns' was set to invalid " "value %li, will use hardcoded limit %i.\n", tmp, MAX_CONNS_LIMIT); + ERROR ("email plugin: `MaxConns' was set to invalid " + "value %li, will use hardcoded limit %i.\n", + tmp, MAX_CONNS_LIMIT); max_conns = MAX_CONNS_LIMIT; } else { diff --git a/src/ipmi.c b/src/ipmi.c index 956aaf44..2d6d2485 100644 --- a/src/ipmi.c +++ b/src/ipmi.c @@ -385,7 +385,7 @@ static void domain_connection_change_handler (ipmi_domain_t *domain, { int status; - printf ("domain_connection_change_handler (domain = %p, err = %i, " + DEBUG ("domain_connection_change_handler (domain = %p, err = %i, " "conn_num = %u, port_num = %u, still_connected = %i, " "user_data = %p);\n", (void *) domain, err, conn_num, port_num, still_connected, user_data); @@ -452,7 +452,7 @@ static void *thread_main (void *user_data) status = thread_init (&os_handler); if (status != 0) { - fprintf (stderr, "ipmi plugin: thread_init failed.\n"); + ERROR ("ipmi plugin: thread_init failed.\n"); return ((void *) -1); } diff --git a/src/rrdtool.c b/src/rrdtool.c index 3b2c54fc..ac81d55c 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -970,6 +970,8 @@ static int rrd_config (const char *key, const char *value) { fprintf (stderr, "rrdtool: `CacheTimeout' must " "be greater than 0.\n"); + ERROR ("rrdtool: `CacheTimeout' must " + "be greater than 0.\n"); return (1); } cache_timeout = tmp; @@ -981,6 +983,8 @@ static int rrd_config (const char *key, const char *value) { fprintf (stderr, "rrdtool: `CacheFlush' must " "be greater than 0.\n"); + ERROR ("rrdtool: `CacheFlush' must " + "be greater than 0.\n"); return (1); } cache_flush_timeout = tmp; @@ -1024,6 +1028,8 @@ static int rrd_config (const char *key, const char *value) { fprintf (stderr, "rrdtool: `RRARows' must " "be greater than 0.\n"); + ERROR ("rrdtool: `RRARows' must " + "be greater than 0.\n"); return (1); } rrarows = tmp; @@ -1050,6 +1056,7 @@ static int rrd_config (const char *key, const char *value) if (tmp_alloc == NULL) { fprintf (stderr, "rrdtool: realloc failed.\n"); + ERROR ("rrdtool: realloc failed.\n"); free (value_copy); return (1); } @@ -1073,6 +1080,8 @@ static int rrd_config (const char *key, const char *value) { fprintf (stderr, "rrdtool: `XFF' must " "be in the range 0 to 1 (exclusive)."); + ERROR ("rrdtool: `XFF' must " + "be in the range 0 to 1 (exclusive)."); return (1); } xff = tmp; diff --git a/src/utils_dns.c b/src/utils_dns.c index 46e6018e..5316a71a 100644 --- a/src/utils_dns.c +++ b/src/utils_dns.c @@ -34,6 +34,7 @@ */ #include "collectd.h" +#include "plugin.h" #if HAVE_NETINET_IN_SYSTM_H # include @@ -354,7 +355,6 @@ handle_dns(const char *buf, int len, memcpy(&us, buf + 2, 2); us = ntohs(us); - fprintf (stderr, "Bytes 0, 1: 0x%04hx\n", us); qh.qr = (us >> 15) & 0x01; qh.opcode = (us >> 11) & 0x0F; qh.aa = (us >> 10) & 0x01; @@ -648,7 +648,7 @@ void handle_pcap(u_char *udata, const struct pcap_pkthdr *hdr, const u_char *pkt { int status; - fprintf (stderr, "handle_pcap (udata = %p, hdr = %p, pkt = %p): hdr->caplen = %i\n", + DEBUG ("handle_pcap (udata = %p, hdr = %p, pkt = %p): hdr->caplen = %i\n", (void *) udata, (void *) hdr, (void *) pkt, hdr->caplen); @@ -685,7 +685,7 @@ void handle_pcap(u_char *udata, const struct pcap_pkthdr *hdr, const u_char *pkt break; default: - fprintf (stderr, "unsupported data link type %d\n", + ERROR ("handle_pcap: unsupported data link type %d\n", pcap_datalink(pcap_obj)); status = 0; break; -- 2.11.0