Do not use *printf() to report errors / debugging messages.
authorSebastian Harl <sh@tokkee.org>
Fri, 19 Dec 2008 17:20:41 +0000 (18:20 +0100)
committerSebastian Harl <sh@tokkee.org>
Fri, 19 Dec 2008 17:20:41 +0000 (18:20 +0100)
The only exception to that is during configuration (which is done before
daemonization) to let the user know about problems immediately.

src/common.c
src/email.c
src/ipmi.c
src/rrdtool.c
src/utils_dns.c

index 82b4aaa..8dbf976 100644 (file)
@@ -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
index 0882ad4..cc68d3f 100644 (file)
@@ -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 {
index 956aaf4..2d6d248 100644 (file)
@@ -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);
   }
 
index 3b2c54f..ac81d55 100644 (file)
@@ -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;
index 46e6018..5316a71 100644 (file)
@@ -34,6 +34,7 @@
  */
 
 #include "collectd.h"
+#include "plugin.h"
 
 #if HAVE_NETINET_IN_SYSTM_H
 # include <netinet/in_systm.h>
@@ -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;