From: Florian Forster Date: Thu, 15 Mar 2007 18:34:46 +0000 (+0100) Subject: Replace all syslog-calls with one of the new logging-macros. X-Git-Tag: collectd-4.0.0~152 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=838af4cdc6c8674ed3e14a95fea172118c707a85;p=collectd.git Replace all syslog-calls with one of the new logging-macros. --- diff --git a/src/Makefile.am b/src/Makefile.am index 0610aa69..adf83da6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,7 +11,6 @@ sbin_PROGRAMS = collectd bin_PROGRAMS = collectd-nagios collectd_SOURCES = collectd.c collectd.h \ - utils_debug.c utils_debug.h \ utils_avltree.c utils_avltree.h \ utils_mount.c utils_mount.h \ utils_llist.c utils_llist.h \ diff --git a/src/apache.c b/src/apache.c index 167ead1f..887977e4 100644 --- a/src/apache.c +++ b/src/apache.c @@ -26,7 +26,6 @@ #include "common.h" #include "plugin.h" #include "configfile.h" -#include "utils_debug.h" #if HAVE_LIBCURL && HAVE_CURL_CURL_H # define APACHE_HAVE_READ 1 @@ -159,7 +158,7 @@ static int init (void) if ((curl = curl_easy_init ()) == NULL) { - syslog (LOG_ERR, "apache: `curl_easy_init' failed."); + ERROR ("apache: `curl_easy_init' failed."); return (-1); } @@ -171,7 +170,7 @@ static int init (void) { if (snprintf (credentials, 1024, "%s:%s", user, pass == NULL ? "" : pass) >= 1024) { - syslog (LOG_ERR, "apache: Credentials would have been truncated."); + ERROR ("apache: Credentials would have been truncated."); return (-1); } @@ -197,7 +196,7 @@ static void submit_counter (const char *type, const char *type_instance, value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - DBG ("type = %s; type_instance = %s; value = %llu;", + DEBUG ("type = %s; type_instance = %s; value = %llu;", type, type_instance, value); values[0].counter = value; @@ -219,7 +218,7 @@ static void submit_gauge (const char *type, const char *type_instance, value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - DBG ("type = %s; type_instance = %s; value = %lf;", + DEBUG ("type = %s; type_instance = %s; value = %lf;", type, type_instance, value); values[0].gauge = value; @@ -309,7 +308,7 @@ static int apache_read (void) apache_buffer_len = 0; if (curl_easy_perform (curl) != 0) { - syslog (LOG_ERR, "apache: curl_easy_perform failed: %s", + ERROR ("apache: curl_easy_perform failed: %s", apache_curl_error); return (-1); } diff --git a/src/apcups.c b/src/apcups.c index 9fab7858..b5b939a1 100644 --- a/src/apcups.c +++ b/src/apcups.c @@ -33,7 +33,6 @@ #include "common.h" /* rrd_update_file */ #include "plugin.h" /* plugin_register, plugin_submit */ #include "configfile.h" /* cf_register */ -#include "utils_debug.h" #if HAVE_SYS_TYPES_H # include @@ -148,7 +147,7 @@ static int apcups_shutdown (void) if (global_sockfd < 0) return (0); - DBG ("Gracefully shutting down socket %i.", global_sockfd); + DEBUG ("Gracefully shutting down socket %i.", global_sockfd); /* send EOF sentinel */ swrite (global_sockfd, (void *) &packet_size, sizeof (packet_size)); @@ -187,7 +186,7 @@ static int net_open (char *host, char *service, int port) status = getaddrinfo (host, port_str, &ai_hints, &ai_return); if (status != 0) { - DBG ("getaddrinfo failed: %s", status == EAI_SYSTEM ? strerror (errno) : gai_strerror (status)); + DEBUG ("getaddrinfo failed: %s", status == EAI_SYSTEM ? strerror (errno) : gai_strerror (status)); return (-1); } @@ -203,7 +202,7 @@ static int net_open (char *host, char *service, int port) if (sd < 0) { - DBG ("Unable to open a socket"); + DEBUG ("Unable to open a socket"); freeaddrinfo (ai_return); return (-1); } @@ -214,12 +213,12 @@ static int net_open (char *host, char *service, int port) if (status != 0) /* `connect(2)' failed */ { - DBG ("connect failed: %s", strerror (errno)); + DEBUG ("connect failed: %s", strerror (errno)); close (sd); return (-1); } - DBG ("Done opening a socket %i", sd); + DEBUG ("Done opening a socket %i", sd); return (sd); } /* int net_open (char *host, char *service, int port) */ @@ -247,7 +246,7 @@ static int net_recv (int *sockfd, char *buf, int buflen) packet_size = ntohs (packet_size); if (packet_size > buflen) { - DBG ("record length too large"); + DEBUG ("record length too large"); return (-2); } @@ -333,7 +332,7 @@ static int apc_query_server (char *host, int port, if (net_send (&global_sockfd, "status", 6) < 0) { - syslog (LOG_ERR, "apcups plugin: Writing to the socket failed."); + ERROR ("apcups plugin: Writing to the socket failed."); return (-1); } @@ -379,7 +378,7 @@ static int apc_query_server (char *host, int port, if (n < 0) { - syslog (LOG_WARNING, "apcups plugin: Error reading from socket"); + WARNING ("apcups plugin: Error reading from socket"); return (-1); } @@ -403,7 +402,7 @@ static int apcups_config (const char *key, const char *value) int port_tmp = atoi (value); if (port_tmp < 1 || port_tmp > 65535) { - syslog (LOG_WARNING, "apcups plugin: Invalid port: %i", port_tmp); + WARNING ("apcups plugin: Invalid port: %i", port_tmp); return (1); } conf_port = port_tmp; @@ -470,7 +469,7 @@ static int apcups_read (void) */ if (status != 0) { - DBG ("apc_query_server (%s, %i) = %i", + DEBUG ("apc_query_server (%s, %i) = %i", conf_host == NULL ? APCUPS_DEFAULT_HOST : conf_host, diff --git a/src/apple_sensors.c b/src/apple_sensors.c index 29d50915..f994b319 100644 --- a/src/apple_sensors.c +++ b/src/apple_sensors.c @@ -22,7 +22,6 @@ #include "collectd.h" #include "common.h" #include "plugin.h" -#include "utils_debug.h" #if HAVE_CTYPE_H # include @@ -95,7 +94,7 @@ static int as_init (void) status = IOMasterPort (MACH_PORT_NULL, &io_master_port); if (status != kIOReturnSuccess) { - syslog (LOG_ERR, "IOMasterPort failed: %s", + ERROR ("IOMasterPort failed: %s", mach_error_string (status)); io_master_port = MACH_PORT_NULL; return (-1); @@ -110,7 +109,7 @@ static void as_submit (const char *type, const char *type_instance, value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - DBG ("type = %s; type_instance = %s; val = %f;", + DEBUG ("type = %s; type_instance = %s; val = %f;", type, type_instance, val); values[0].gauge = val; @@ -148,7 +147,7 @@ static int as_read (void) &iterator); if (status != kIOReturnSuccess) { - syslog (LOG_ERR, "IOServiceGetMatchingServices failed: %s", + ERROR ("IOServiceGetMatchingServices failed: %s", mach_error_string (status)); return (-1); } @@ -162,7 +161,7 @@ static int as_read (void) kNilOptions); if (status != kIOReturnSuccess) { - DBG ("IORegistryEntryCreateCFProperties failed: %s", + DEBUG ("IORegistryEntryCreateCFProperties failed: %s", mach_error_string (status)); continue; } @@ -246,7 +245,7 @@ static int as_read (void) } else { - DBG ("apple_sensors: Read unknown sensor type: %s", + DEBUG ("apple_sensors: Read unknown sensor type: %s", type); value_double = (double) value_int; } diff --git a/src/battery.c b/src/battery.c index 8a74b3db..85bfc00a 100644 --- a/src/battery.c +++ b/src/battery.c @@ -22,7 +22,6 @@ #include "collectd.h" #include "common.h" #include "plugin.h" -#include "utils_debug.h" #if HAVE_MACH_MACH_TYPES_H # include @@ -151,13 +150,13 @@ double dict_get_double (CFDictionaryRef dict, char *key_string) kCFStringEncodingASCII); if (key_obj == NULL) { - DBG ("CFStringCreateWithCString (%s) failed.\n", key_string); + DEBUG ("CFStringCreateWithCString (%s) failed.\n", key_string); return (INVALID_VALUE); } if ((val_obj = CFDictionaryGetValue (dict, key_obj)) == NULL) { - DBG ("CFDictionaryGetValue (%s) failed.", key_string); + DEBUG ("CFDictionaryGetValue (%s) failed.", key_string); CFRelease (key_obj); return (INVALID_VALUE); } @@ -181,7 +180,7 @@ double dict_get_double (CFDictionaryRef dict, char *key_string) } else { - DBG ("CFGetTypeID (val_obj) = %i", (int) CFGetTypeID (val_obj)); + DEBUG ("CFGetTypeID (val_obj) = %i", (int) CFGetTypeID (val_obj)); return (INVALID_VALUE); } @@ -207,7 +206,7 @@ static void get_via_io_power_sources (double *ret_charge, ps_array = IOPSCopyPowerSourcesList (ps_raw); ps_array_len = CFArrayGetCount (ps_array); - DBG ("ps_array_len == %i", ps_array_len); + DEBUG ("ps_array_len == %i", ps_array_len); for (i = 0; i < ps_array_len; i++) { @@ -216,13 +215,13 @@ static void get_via_io_power_sources (double *ret_charge, if (ps_dict == NULL) { - DBG ("IOPSGetPowerSourceDescription failed."); + DEBUG ("IOPSGetPowerSourceDescription failed."); continue; } if (CFGetTypeID (ps_dict) != CFDictionaryGetTypeID ()) { - DBG ("IOPSGetPowerSourceDescription did not return a CFDictionaryRef"); + DEBUG ("IOPSGetPowerSourceDescription did not return a CFDictionaryRef"); continue; } @@ -283,7 +282,7 @@ static void get_via_generic_iokit (double *ret_charge, &iterator); if (status != kIOReturnSuccess) { - DBG ("IOServiceGetMatchingServices failed."); + DEBUG ("IOServiceGetMatchingServices failed."); return; } @@ -295,7 +294,7 @@ static void get_via_generic_iokit (double *ret_charge, kNilOptions); if (status != kIOReturnSuccess) { - DBG ("IORegistryEntryCreateCFProperties failed."); + DEBUG ("IORegistryEntryCreateCFProperties failed."); continue; } @@ -458,7 +457,7 @@ static int battery_read (void) if ((dh = opendir ("/proc/acpi/battery")) == NULL) { - syslog (LOG_ERR, "Cannot open `/proc/acpi/battery': %s", strerror (errno)); + ERROR ("Cannot open `/proc/acpi/battery': %s", strerror (errno)); return (-1); } @@ -475,7 +474,7 @@ static int battery_read (void) if ((fh = fopen (filename, "r")) == NULL) { - syslog (LOG_ERR, "Cannot open `%s': %s", filename, strerror (errno)); + ERROR ("Cannot open `%s': %s", filename, strerror (errno)); continue; } diff --git a/src/collectd.c b/src/collectd.c index 68a70bac..e873adc2 100644 --- a/src/collectd.c +++ b/src/collectd.c @@ -22,7 +22,6 @@ #include "collectd.h" #include "common.h" -#include "utils_debug.h" #include "network.h" #include "plugin.h" @@ -67,7 +66,7 @@ static int init_global_variables (void) return (-1); } } - DBG ("hostname_g = %s;", hostname_g); + DEBUG ("hostname_g = %s;", hostname_g); str = global_option_get ("Interval"); if (str == NULL) @@ -79,7 +78,7 @@ static int init_global_variables (void) "Please check your settings.\n"); return (-1); } - DBG ("interval_g = %i;", interval_g); + DEBUG ("interval_g = %i;", interval_g); return (0); } /* int init_global_variables */ @@ -92,7 +91,7 @@ static int change_basedir (const char *orig_dir) if (dir == NULL) { - syslog (LOG_ERR, "strdup failed: %s", strerror (errno)); + ERROR ("strdup failed: %s", strerror (errno)); return (-1); } @@ -112,20 +111,20 @@ static int change_basedir (const char *orig_dir) { if (mkdir (orig_dir, 0755) == -1) { - syslog (LOG_ERR, "mkdir (%s): %s", orig_dir, + ERROR ("mkdir (%s): %s", orig_dir, strerror (errno)); return (-1); } else if (chdir (orig_dir) == -1) { - syslog (LOG_ERR, "chdir (%s): %s", orig_dir, + ERROR ("chdir (%s): %s", orig_dir, strerror (errno)); return (-1); } } else { - syslog (LOG_ERR, "chdir (%s): %s", orig_dir, + ERROR ("chdir (%s): %s", orig_dir, strerror (errno)); return (-1); } @@ -140,7 +139,7 @@ static void update_kstat (void) if (kc == NULL) { if ((kc = kstat_open ()) == NULL) - syslog (LOG_ERR, "Unable to open kstat control structure"); + ERROR ("Unable to open kstat control structure"); } else { @@ -148,11 +147,11 @@ static void update_kstat (void) kid = kstat_chain_update (kc); if (kid > 0) { - syslog (LOG_INFO, "kstat chain has been updated"); + INFO ("kstat chain has been updated"); plugin_init_all (); } else if (kid < 0) - syslog (LOG_ERR, "kstat chain update failed"); + ERROR ("kstat chain update failed"); /* else: everything works as expected */ } @@ -201,13 +200,13 @@ static int do_init (void) #if HAVE_LIBSTATGRAB if (sg_init ()) { - syslog (LOG_ERR, "sg_init: %s", sg_str_error (sg_get_error ())); + ERROR ("sg_init: %s", sg_str_error (sg_get_error ())); return (-1); } if (sg_drop_privileges ()) { - syslog (LOG_ERR, "sg_drop_privileges: %s", sg_str_error (sg_get_error ())); + ERROR ("sg_drop_privileges: %s", sg_str_error (sg_get_error ())); return (-1); } #endif @@ -228,7 +227,7 @@ static int do_loop (void) { if (gettimeofday (&tv_next, NULL) < 0) { - syslog (LOG_ERR, "gettimeofday failed: %s", strerror (errno)); + ERROR ("gettimeofday failed: %s", strerror (errno)); return (-1); } tv_next.tv_sec += interval_g; @@ -242,14 +241,14 @@ static int do_loop (void) if (gettimeofday (&tv_now, NULL) < 0) { - syslog (LOG_ERR, "gettimeofday failed: %s", + ERROR ("gettimeofday failed: %s", strerror (errno)); return (-1); } if (timeval_sub_timespec (&tv_next, &tv_now, &ts_wait) != 0) { - syslog (LOG_WARNING, "Not sleeping because " + WARNING ("Not sleeping because " "`timeval_sub_timespec' returned " "non-zero!"); continue; @@ -259,13 +258,13 @@ static int do_loop (void) { if (errno != EINTR) { - syslog (LOG_ERR, "nanosleep failed: %s", strerror (errno)); + ERROR ("nanosleep failed: %s", strerror (errno)); return (-1); } } } /* while (loop == 0) */ - DBG ("return (0);"); + DEBUG ("return (0);"); return (0); } /* int do_loop */ @@ -283,7 +282,7 @@ static int pidfile_create (void) if ((fh = fopen (file, "w")) == NULL) { - syslog (LOG_ERR, "fopen (%s): %s", file, strerror (errno)); + ERROR ("fopen (%s): %s", file, strerror (errno)); return (1); } @@ -297,7 +296,7 @@ static int pidfile_remove (void) { const char *file = global_option_get ("PIDFile"); - DBG ("unlink (%s)", (file != NULL) ? file : ""); + DEBUG ("unlink (%s)", (file != NULL) ? file : ""); return (unlink (file)); } /* static int pidfile_remove (const char *file) */ #endif /* COLLECT_DAEMON */ @@ -313,12 +312,6 @@ int main (int argc, char **argv) pid_t pid; int daemonize = 1; #endif -#if COLLECT_DEBUG - const char *logfile; -#endif - - /* open syslog */ - openlog (PACKAGE, LOG_CONS | LOG_PID, LOG_DAEMON); /* read options */ while (1) @@ -353,11 +346,6 @@ int main (int argc, char **argv) } /* switch (c) */ } /* while (1) */ -#if COLLECT_DEBUG - if ((logfile = global_option_get ("LogFile")) != NULL) - DBG_STARTFILE (logfile, "Debug file opened."); -#endif - /* * Read options from the config file, the environment and the command * line (in that order, with later options overwriting previous ones in @@ -432,17 +420,17 @@ int main (int argc, char **argv) if (open ("/dev/null", O_RDWR) != 0) { - syslog (LOG_ERR, "Error: Could not connect `STDIN' to `/dev/null'"); + ERROR ("Error: Could not connect `STDIN' to `/dev/null'"); return (1); } if (dup (0) != 1) { - syslog (LOG_ERR, "Error: Could not connect `STDOUT' to `/dev/null'"); + ERROR ("Error: Could not connect `STDOUT' to `/dev/null'"); return (1); } if (dup (0) != 2) { - syslog (LOG_ERR, "Error: Could not connect `STDERR' to `/dev/null'"); + ERROR ("Error: Could not connect `STDERR' to `/dev/null'"); return (1); } } /* if (daemonize) */ @@ -464,16 +452,11 @@ int main (int argc, char **argv) */ do_init (); do_loop (); - do_shutdown (); - -#if COLLECT_DEBUG - if (logfile != NULL) - DBG_STOPFILE("debug file closed."); -#endif /* close syslog */ - syslog (LOG_INFO, "Exiting normally"); - closelog (); + INFO ("Exiting normally"); + + do_shutdown (); #if COLLECT_DAEMON if (daemonize) diff --git a/src/common.c b/src/common.c index 922bd15e..ede2ea5c 100644 --- a/src/common.c +++ b/src/common.c @@ -21,7 +21,7 @@ **/ #include "common.h" -#include "utils_debug.h" +#include "plugin.h" #ifdef HAVE_MATH_H # include @@ -51,7 +51,7 @@ char *sstrdup (const char *s) if((r = strdup (s)) == NULL) { - DBG ("Not enough memory."); + DEBUG ("Not enough memory."); exit(3); } @@ -64,7 +64,7 @@ void *smalloc (size_t size) if ((r = malloc (size)) == NULL) { - DBG("Not enough memory."); + DEBUG("Not enough memory."); exit(3); } @@ -105,7 +105,7 @@ ssize_t sread (int fd, void *buf, size_t count) if (status == 0) { - DBG ("Received EOF from fd %i. " + DEBUG ("Received EOF from fd %i. " "Closing fd and returning error.", fd); close (fd); @@ -351,7 +351,7 @@ int check_create_dir (const char *file_orig) */ if (fields[i][0] == '.') { - syslog (LOG_ERR, "Cowardly refusing to create a directory that begins with a `.' (dot): `%s'", file_orig); + ERROR ("Cowardly refusing to create a directory that begins with a `.' (dot): `%s'", file_orig); return (-2); } @@ -362,7 +362,7 @@ int check_create_dir (const char *file_orig) if (strjoin (dir + path_is_absolute, dir_len - path_is_absolute, fields, i + 1, "/") < 0) { - syslog (LOG_ERR, "strjoin failed: `%s', component #%i", file_orig, i); + ERROR ("strjoin failed: `%s', component #%i", file_orig, i); return (-1); } @@ -372,19 +372,19 @@ int check_create_dir (const char *file_orig) { if (mkdir (dir, 0755) == -1) { - syslog (LOG_ERR, "mkdir (%s): %s", dir, strerror (errno)); + ERROR ("mkdir (%s): %s", dir, strerror (errno)); return (-1); } } else { - syslog (LOG_ERR, "stat (%s): %s", dir, strerror (errno)); + ERROR ("stat (%s): %s", dir, strerror (errno)); return (-1); } } else if (!S_ISDIR (statbuf.st_mode)) { - syslog (LOG_ERR, "stat (%s): Not a directory!", dir); + ERROR ("stat (%s): Not a directory!", dir); return (-1); } } @@ -407,13 +407,13 @@ int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name) { if ((*ksp_ptr = kstat_lookup (kc, module, instance, name)) == NULL) { - syslog (LOG_ERR, "Cound not find kstat %s", ident); + ERROR ("Cound not find kstat %s", ident); return (-1); } if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED) { - syslog (LOG_WARNING, "kstat %s has wrong type", ident); + WARNING ("kstat %s has wrong type", ident); *ksp_ptr = NULL; return (-1); } @@ -426,13 +426,13 @@ int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name) if (kstat_read (kc, *ksp_ptr, NULL) == -1) { - syslog (LOG_WARNING, "kstat %s could not be read", ident); + WARNING ("kstat %s could not be read", ident); return (-1); } if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED) { - syslog (LOG_WARNING, "kstat %s has wrong type", ident); + WARNING ("kstat %s has wrong type", ident); return (-1); } @@ -472,7 +472,7 @@ long long get_kstat_value (kstat_t *ksp, char *name) else if (kn->data_type == KSTAT_DATA_UINT64) retval = (long long) kn->value.ui64; /* XXX: Might overflow! */ else - syslog (LOG_WARNING, "get_kstat_value: Not a numeric value: %s", name); + WARNING ("get_kstat_value: Not a numeric value: %s", name); return (retval); } diff --git a/src/configfile.c b/src/configfile.c index a5ae4961..3cc0379b 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -28,7 +28,6 @@ #include "plugin.h" #include "configfile.h" #include "network.h" -#include "utils_debug.h" #define ESCAPE_NULL(str) ((str) == NULL ? "(null)" : (str)) @@ -112,14 +111,14 @@ static int cf_dispatch (const char *type, const char *orig_key, int ret; int i; - DBG ("type = %s, key = %s, value = %s", + DEBUG ("type = %s, key = %s, value = %s", ESCAPE_NULL(type), ESCAPE_NULL(orig_key), ESCAPE_NULL(orig_value)); if ((cf_cb = cf_search (type)) == NULL) { - syslog (LOG_WARNING, "Plugin `%s' did not register a callback.", type); + WARNING ("Plugin `%s' did not register a callback.", type); return (-1); } @@ -143,12 +142,12 @@ static int cf_dispatch (const char *type, const char *orig_key, } if (i >= cf_cb->keys_num) - syslog (LOG_WARNING, "Plugin `%s' did not register for value `%s'.", type, key); + WARNING ("Plugin `%s' did not register for value `%s'.", type, key); free (key); free (value); - DBG ("return (%i)", ret); + DEBUG ("return (%i)", ret); return (ret); } /* int cf_dispatch */ @@ -265,7 +264,7 @@ static int dispatch_block_plugin (oconfig_item_t *ci) if (ci->children[i].children == NULL) dispatch_value_plugin (name, ci->children + i); else - {DBG ("No nested config blocks allow for plugins. Yet.");} + {DEBUG ("No nested config blocks allow for plugins. Yet.");} } return (0); @@ -287,7 +286,7 @@ int global_option_set (const char *option, const char *value) { int i; - DBG ("option = %s; value = %s;", option, value); + DEBUG ("option = %s; value = %s;", option, value); for (i = 0; i < cf_global_options_num; i++) if (strcasecmp (cf_global_options[i].key, option) == 0) @@ -372,7 +371,7 @@ int cf_read (char *filename) conf = oconfig_parse_file (filename); if (conf == NULL) { - syslog (LOG_ERR, "Unable to read config file %s.", filename); + ERROR ("Unable to read config file %s.", filename); return (-1); } diff --git a/src/cpu.c b/src/cpu.c index 285841e4..6f18b4f4 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -22,7 +22,6 @@ #include "collectd.h" #include "common.h" #include "plugin.h" -#include "utils_debug.h" #ifdef HAVE_MACH_KERN_RETURN_H # include @@ -125,13 +124,13 @@ static int init (void) /* FIXME: Free `cpu_list' if it's not NULL */ if ((status = host_processors (port_host, &cpu_list, &cpu_list_len)) != KERN_SUCCESS) { - syslog (LOG_ERR, "cpu plugin: host_processors returned %i", (int) status); + ERROR ("cpu plugin: host_processors returned %i", (int) status); cpu_list_len = 0; return (-1); } - DBG ("host_processors returned %i %s", (int) cpu_list_len, cpu_list_len == 1 ? "processor" : "processors"); - syslog (LOG_INFO, "cpu plugin: Found %i processor%s.", (int) cpu_list_len, cpu_list_len == 1 ? "" : "s"); + DEBUG ("host_processors returned %i %s", (int) cpu_list_len, cpu_list_len == 1 ? "processor" : "processors"); + INFO ("cpu plugin: Found %i processor%s.", (int) cpu_list_len, cpu_list_len == 1 ? "" : "s"); collectd_step = atoi (COLLECTD_STEP); if ((collectd_step > 0) && (collectd_step <= 86400)) @@ -162,12 +161,12 @@ static int init (void) if (sysctlbyname ("hw.ncpu", &numcpu, &numcpu_size, NULL, 0) < 0) { - syslog (LOG_WARNING, "cpu: sysctlbyname: %s", strerror (errno)); + WARNING ("cpu: sysctlbyname: %s", strerror (errno)); return (-1); } if (numcpu != 1) - syslog (LOG_NOTICE, "cpu: Only one processor supported when using `sysctlbyname' (found %i)", numcpu); + NOTICE ("cpu: Only one processor supported when using `sysctlbyname' (found %i)", numcpu); #endif return (0); @@ -221,13 +220,13 @@ static int cpu_read (void) PROCESSOR_CPU_LOAD_INFO, &cpu_host, (processor_info_t) &cpu_info, &cpu_info_len)) != KERN_SUCCESS) { - syslog (LOG_ERR, "cpu plugin: processor_info failed with status %i", (int) status); + ERROR ("cpu plugin: processor_info failed with status %i", (int) status); continue; } if (cpu_info_len < CPU_STATE_MAX) { - syslog (LOG_ERR, "cpu plugin: processor_info returned only %i elements..", cpu_info_len); + ERROR ("cpu plugin: processor_info returned only %i elements..", cpu_info_len); continue; } @@ -257,7 +256,7 @@ static int cpu_read (void) cpu_temp, &cpu_temp_len); if (status != KERN_SUCCESS) { - syslog (LOG_ERR, "cpu plugin: processor_info failed: %s", + ERROR ("cpu plugin: processor_info failed: %s", mach_error_string (status)); cpu_temp_retry_counter = cpu_temp_retry_step; @@ -270,7 +269,7 @@ static int cpu_read (void) if (cpu_temp_len != 1) { - DBG ("processor_info (PROCESSOR_TEMPERATURE) returned %i elements..?", + DEBUG ("processor_info (PROCESSOR_TEMPERATURE) returned %i elements..?", (int) cpu_temp_len); continue; } @@ -278,7 +277,7 @@ static int cpu_read (void) cpu_temp_retry_counter = 0; cpu_temp_retry_step = 1; - DBG ("cpu_temp = %i", (int) cpu_temp); + DEBUG ("cpu_temp = %i", (int) cpu_temp); #endif /* PROCESSOR_TEMPERATURE */ } /* #endif PROCESSOR_CPU_LOAD_INFO */ diff --git a/src/cpufreq.c b/src/cpufreq.c index 008ef39f..46e86598 100644 --- a/src/cpufreq.c +++ b/src/cpufreq.c @@ -69,7 +69,7 @@ static int cpufreq_init (void) num_cpu++; } - syslog (LOG_INFO, "cpufreq plugin: Found %d CPU%s", num_cpu, + INFO ("cpufreq plugin: Found %d CPU%s", num_cpu, (num_cpu == 1) ? "" : "s"); if (num_cpu == 0) @@ -117,19 +117,19 @@ static int cpufreq_read (void) if ((fp = fopen (filename, "r")) == NULL) { - syslog (LOG_WARNING, "cpufreq: fopen: %s", strerror (errno)); + WARNING ("cpufreq: fopen: %s", strerror (errno)); return (-1); } if (fgets (buffer, 16, fp) == NULL) { - syslog (LOG_WARNING, "cpufreq: fgets: %s", strerror (errno)); + WARNING ("cpufreq: fgets: %s", strerror (errno)); fclose (fp); return (-1); } if (fclose (fp)) - syslog (LOG_WARNING, "cpufreq: fclose: %s", strerror (errno)); + WARNING ("cpufreq: fclose: %s", strerror (errno)); /* You're seeing correctly: The file is reporting kHz values.. */ val = atoll (buffer) * 1000; diff --git a/src/csv.c b/src/csv.c index f4b56fe0..62b6b2c7 100644 --- a/src/csv.c +++ b/src/csv.c @@ -22,7 +22,6 @@ #include "collectd.h" #include "plugin.h" #include "common.h" -#include "utils_debug.h" /* * Private variables @@ -121,7 +120,7 @@ static int value_list_to_filename (char *buffer, int buffer_len, now = time (NULL); if (localtime_r (&now, &stm) == NULL) { - syslog (LOG_ERR, "csv plugin: localtime_r failed"); + ERROR ("csv plugin: localtime_r failed"); return (1); } @@ -143,7 +142,7 @@ static int csv_create_file (const char *filename, const data_set_t *ds) csv = fopen (filename, "w"); if (csv == NULL) { - syslog (LOG_ERR, "csv plugin: fopen (%s) failed: %s", + ERROR ("csv plugin: fopen (%s) failed: %s", filename, strerror(errno)); return (-1); } @@ -200,7 +199,7 @@ static int csv_write (const data_set_t *ds, const value_list_t *vl) if (value_list_to_filename (filename, sizeof (filename), ds, vl) != 0) return (-1); - DBG ("filename = %s;", filename); + DEBUG ("filename = %s;", filename); if (value_list_to_string (values, sizeof (values), ds, vl) != 0) return (-1); @@ -214,14 +213,14 @@ static int csv_write (const data_set_t *ds, const value_list_t *vl) } else { - syslog (LOG_ERR, "stat(%s) failed: %s", + ERROR ("stat(%s) failed: %s", filename, strerror (errno)); return (-1); } } else if (!S_ISREG (statbuf.st_mode)) { - syslog (LOG_ERR, "stat(%s): Not a regular file!", + ERROR ("stat(%s): Not a regular file!", filename); return (-1); } @@ -229,7 +228,7 @@ static int csv_write (const data_set_t *ds, const value_list_t *vl) csv = fopen (filename, "a"); if (csv == NULL) { - syslog (LOG_ERR, "csv plugin: fopen (%s) failed: %s", + ERROR ("csv plugin: fopen (%s) failed: %s", filename, strerror (errno)); return (-1); } @@ -245,7 +244,7 @@ static int csv_write (const data_set_t *ds, const value_list_t *vl) status = fcntl (csv_fd, F_SETLK, &fl); if (status != 0) { - syslog (LOG_ERR, "csv plugin: flock (%s) failed: %s", + ERROR ("csv plugin: flock (%s) failed: %s", filename, strerror (errno)); fclose (csv); return (-1); diff --git a/src/df.c b/src/df.c index fde5d9ae..6ec51fe3 100644 --- a/src/df.c +++ b/src/df.c @@ -174,7 +174,7 @@ static int df_read (void) { if (STATANYFS (mnt_ptr->dir, &statbuf) < 0) { - syslog (LOG_ERR, "statv?fs failed: %s", strerror (errno)); + ERROR ("statv?fs failed: %s", strerror (errno)); continue; } diff --git a/src/disk.c b/src/disk.c index af7c01a6..36d7b4fa 100644 --- a/src/disk.c +++ b/src/disk.c @@ -22,7 +22,6 @@ #include "collectd.h" #include "common.h" #include "plugin.h" -#include "utils_debug.h" #if HAVE_MACH_MACH_TYPES_H # include @@ -152,7 +151,7 @@ static int disk_init (void) status = IOMasterPort (MACH_PORT_NULL, &io_master_port); if (status != kIOReturnSuccess) { - syslog (LOG_ERR, "IOMasterPort failed: %s", + ERROR ("IOMasterPort failed: %s", mach_error_string (status)); io_master_port = MACH_PORT_NULL; return (-1); @@ -170,7 +169,7 @@ static int disk_init (void) assert (heartbeat >= step); min_poll_count = 1 + (heartbeat / step); - DBG ("min_poll_count = %i;", min_poll_count); + DEBUG ("min_poll_count = %i;", min_poll_count); /* #endif KERNEL_LINUX */ #elif HAVE_LIBKSTAT @@ -230,7 +229,7 @@ static signed long long dict_get_value (CFDictionaryRef dict, const char *key) kCFStringEncodingASCII); if (key_obj == NULL) { - DBG ("CFStringCreateWithCString (%s) failed.", key); + DEBUG ("CFStringCreateWithCString (%s) failed.", key); return (-1LL); } @@ -241,13 +240,13 @@ static signed long long dict_get_value (CFDictionaryRef dict, const char *key) if (val_obj == NULL) { - DBG ("CFDictionaryGetValue (%s) failed.", key); + DEBUG ("CFDictionaryGetValue (%s) failed.", key); return (-1LL); } if (!CFNumberGetValue (val_obj, kCFNumberSInt64Type, &val_int)) { - DBG ("CFNumberGetValue (%s) failed.", key); + DEBUG ("CFNumberGetValue (%s) failed.", key); return (-1LL); } @@ -305,7 +304,7 @@ static int disk_read (void) != kIOReturnSuccess) { /* This fails for example for DVD/CD drives.. */ - DBG ("IORegistryEntryGetChildEntry (disk) failed: 0x%08x", status); + DEBUG ("IORegistryEntryGetChildEntry (disk) failed: 0x%08x", status); IOObjectRelease (disk); continue; } @@ -317,7 +316,7 @@ static int disk_read (void) kNilOptions) != kIOReturnSuccess) { - syslog (LOG_ERR, "disk-plugin: IORegistryEntryCreateCFProperties failed."); + ERROR ("disk-plugin: IORegistryEntryCreateCFProperties failed."); IOObjectRelease (disk_child); IOObjectRelease (disk); continue; @@ -325,7 +324,7 @@ static int disk_read (void) if (props_dict == NULL) { - DBG ("IORegistryEntryCreateCFProperties (disk) failed."); + DEBUG ("IORegistryEntryCreateCFProperties (disk) failed."); IOObjectRelease (disk_child); IOObjectRelease (disk); continue; @@ -336,7 +335,7 @@ static int disk_read (void) if (stats_dict == NULL) { - DBG ("CFDictionaryGetValue (%s) failed.", + DEBUG ("CFDictionaryGetValue (%s) failed.", kIOBlockStorageDriverStatisticsKey); CFRelease (props_dict); IOObjectRelease (disk_child); @@ -350,7 +349,7 @@ static int disk_read (void) kNilOptions) != kIOReturnSuccess) { - DBG ("IORegistryEntryCreateCFProperties (disk_child) failed."); + DEBUG ("IORegistryEntryCreateCFProperties (disk_child) failed."); IOObjectRelease (disk_child); CFRelease (props_dict); IOObjectRelease (disk); @@ -382,14 +381,14 @@ static int disk_read (void) if (snprintf (disk_name, 64, "%i-%i", disk_major, disk_minor) >= 64) { - DBG ("snprintf (major, minor) failed."); + DEBUG ("snprintf (major, minor) failed."); CFRelease (child_dict); IOObjectRelease (disk_child); CFRelease (props_dict); IOObjectRelease (disk); continue; } - DBG ("disk_name = %s", disk_name); + DEBUG ("disk_name = %s", disk_name); if ((read_byt != -1LL) || (write_byt != -1LL)) disk_submit (disk_name, "disk_octets", read_byt, write_byt); @@ -516,7 +515,7 @@ static int disk_read (void) } else { - DBG ("numfields = %i; => unknown file format.", numfields); + DEBUG ("numfields = %i; => unknown file format.", numfields); continue; } @@ -540,14 +539,14 @@ static int disk_read (void) ds->poll_count++; if (ds->poll_count <= min_poll_count) { - DBG ("(ds->poll_count = %i) <= (min_poll_count = %i); => Not writing.", + DEBUG ("(ds->poll_count = %i) <= (min_poll_count = %i); => Not writing.", ds->poll_count, min_poll_count); continue; } if ((read_count == 0) && (write_count == 0)) { - DBG ("((read_count == 0) && (write_count == 0)); => Not writing."); + DEBUG ("((read_count == 0) && (write_count == 0)); => Not writing."); continue; } diff --git a/src/dns.c b/src/dns.c index 56df1845..11dc2874 100644 --- a/src/dns.c +++ b/src/dns.c @@ -23,7 +23,6 @@ #include "common.h" #include "plugin.h" #include "configfile.h" -#include "utils_debug.h" #if HAVE_LIBPCAP && HAVE_LIBPTHREAD # include "utils_dns.h" @@ -117,14 +116,14 @@ static counter_list_t *counter_list_search (counter_list_t **list, unsigned int { counter_list_t *entry; - DBG ("counter_list_search (list = %p, key = %u)", + DEBUG ("counter_list_search (list = %p, key = %u)", (void *) *list, key); for (entry = *list; entry != NULL; entry = entry->next) if (entry->key == key) break; - DBG ("return (%p)", (void *) entry); + DEBUG ("return (%p)", (void *) entry); return (entry); } @@ -133,7 +132,7 @@ static counter_list_t *counter_list_create (counter_list_t **list, { counter_list_t *entry; - DBG ("counter_list_create (list = %p, key = %u, value = %u)", + DEBUG ("counter_list_create (list = %p, key = %u, value = %u)", (void *) *list, key, value); entry = (counter_list_t *) malloc (sizeof (counter_list_t)); @@ -159,7 +158,7 @@ static counter_list_t *counter_list_create (counter_list_t **list, last->next = entry; } - DBG ("return (%p)", (void *) entry); + DEBUG ("return (%p)", (void *) entry); return (entry); } @@ -168,7 +167,7 @@ static void counter_list_add (counter_list_t **list, { counter_list_t *entry; - DBG ("counter_list_add (list = %p, key = %u, increment = %u)", + DEBUG ("counter_list_add (list = %p, key = %u, increment = %u)", (void *) *list, key, increment); entry = counter_list_search (list, key); @@ -181,7 +180,7 @@ static void counter_list_add (counter_list_t **list, { counter_list_create (list, key, increment); } - DBG ("return ()"); + DEBUG ("return ()"); } static int dns_config (const char *key, const char *value) @@ -253,7 +252,7 @@ static void *dns_child_loop (void *dummy) } /* Passing `pcap_device == NULL' is okay and the same as passign "any" */ - DBG ("Creating PCAP object.."); + DEBUG ("Creating PCAP object.."); pcap_obj = pcap_open_live (pcap_device, PCAP_SNAPLEN, 0 /* Not promiscuous */, @@ -261,7 +260,7 @@ static void *dns_child_loop (void *dummy) pcap_error); if (pcap_obj == NULL) { - syslog (LOG_ERR, "dns plugin: Opening interface `%s' " + ERROR ("dns plugin: Opening interface `%s' " "failed: %s", (pcap_device != NULL) ? pcap_device : "any", pcap_error); @@ -271,18 +270,18 @@ static void *dns_child_loop (void *dummy) memset (&fp, 0, sizeof (fp)); if (pcap_compile (pcap_obj, &fp, "udp port 53", 1, 0) < 0) { - DBG ("pcap_compile failed"); - syslog (LOG_ERR, "dns plugin: pcap_compile failed"); + DEBUG ("pcap_compile failed"); + ERROR ("dns plugin: pcap_compile failed"); return (NULL); } if (pcap_setfilter (pcap_obj, &fp) < 0) { - DBG ("pcap_setfilter failed"); - syslog (LOG_ERR, "dns plugin: pcap_setfilter failed"); + DEBUG ("pcap_setfilter failed"); + ERROR ("dns plugin: pcap_setfilter failed"); return (NULL); } - DBG ("PCAP object created."); + DEBUG ("PCAP object created."); dnstop_set_pcap_obj (pcap_obj); dnstop_set_callback (dns_child_callback); @@ -292,10 +291,10 @@ static void *dns_child_loop (void *dummy) handle_pcap /* callback */, NULL /* Whatever this means.. */); if (status < 0) - syslog (LOG_ERR, "dns plugin: Listener thread is exiting " + ERROR ("dns plugin: Listener thread is exiting " "abnormally: %s", pcap_geterr (pcap_obj)); - DBG ("child is exiting"); + DEBUG ("child is exiting"); pcap_close (pcap_obj); listen_thread_init = 0; @@ -321,7 +320,7 @@ static int dns_init (void) (void *) 0); if (status != 0) { - syslog (LOG_ERR, "dns plugin: pthread_create failed: %s", + ERROR ("dns plugin: pthread_create failed: %s", strerror (status)); return (-1); } @@ -393,7 +392,7 @@ static int dns_read (void) for (i = 0; i < len; i++) { - DBG ("qtype = %u; counter = %u;", keys[i], values[i]); + DEBUG ("qtype = %u; counter = %u;", keys[i], values[i]); submit_counter ("dns_qtype", qtype_str (keys[i]), values[i]); } @@ -409,7 +408,7 @@ static int dns_read (void) for (i = 0; i < len; i++) { - DBG ("opcode = %u; counter = %u;", keys[i], values[i]); + DEBUG ("opcode = %u; counter = %u;", keys[i], values[i]); submit_counter ("dns_opcode", opcode_str (keys[i]), values[i]); } @@ -425,7 +424,7 @@ static int dns_read (void) for (i = 0; i < len; i++) { - DBG ("rcode = %u; counter = %u;", keys[i], values[i]); + DEBUG ("rcode = %u; counter = %u;", keys[i], values[i]); submit_counter ("dns_rcode", rcode_str (keys[i]), values[i]); } diff --git a/src/email.c b/src/email.c index ed0f9a2f..a0278336 100644 --- a/src/email.c +++ b/src/email.c @@ -81,8 +81,8 @@ #define MAX_CONNS 5 #define MAX_CONNS_LIMIT 16384 -#define log_err(...) syslog (LOG_ERR, MODULE_NAME": "__VA_ARGS__) -#define log_warn(...) syslog (LOG_WARNING, MODULE_NAME": "__VA_ARGS__) +#define log_err(...) ERROR (MODULE_NAME": "__VA_ARGS__) +#define log_warn(...) WARNING (MODULE_NAME": "__VA_ARGS__) /* * Private data structures diff --git a/src/exec.c b/src/exec.c index 63401bec..fa0196b3 100644 --- a/src/exec.c +++ b/src/exec.c @@ -22,7 +22,6 @@ #include "collectd.h" #include "common.h" #include "plugin.h" -#include "utils_debug.h" #include #include @@ -129,7 +128,7 @@ static void submit_counter (const char *type_instance, counter_t value) value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - DBG ("type_instance = %s; value = %llu;", type_instance, value); + DEBUG ("type_instance = %s; value = %llu;", type_instance, value); values[0].counter = value; @@ -149,7 +148,7 @@ static void submit_gauge (const char *type_instance, gauge_t value) value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - DBG ("type_instance = %s; value = %lf;", type_instance, value); + DEBUG ("type_instance = %s; value = %lf;", type_instance, value); values[0].gauge = value; @@ -178,26 +177,26 @@ static void exec_child (program_list_t *pl) status = getpwnam_r (pl->user, &sp, pwnambuf, sizeof (pwnambuf), &sp_ptr); if (status != 0) { - syslog (LOG_ERR, "exec plugin: getpwnam_r failed: %s", strerror (status)); + ERROR ("exec plugin: getpwnam_r failed: %s", strerror (status)); exit (-1); } if (sp_ptr == NULL) { - syslog (LOG_ERR, "exec plugin: No such user: `%s'", pl->user); + ERROR ("exec plugin: No such user: `%s'", pl->user); exit (-1); } uid = sp.pw_uid; if (uid == 0) { - syslog (LOG_ERR, "exec plugin: Cowardly refusing to exec program as root."); + ERROR ("exec plugin: Cowardly refusing to exec program as root."); exit (-1); } status = setuid (uid); if (status != 0) { - syslog (LOG_ERR, "exec plugin: setuid failed: %s", strerror (errno)); + ERROR ("exec plugin: setuid failed: %s", strerror (errno)); exit (-1); } @@ -209,7 +208,7 @@ static void exec_child (program_list_t *pl) status = execlp (pl->exec, arg0, (char *) 0); - syslog (LOG_ERR, "exec plugin: exec failed: %s", strerror (errno)); + ERROR ("exec plugin: exec failed: %s", strerror (errno)); exit (-1); } /* void exec_child */ @@ -224,14 +223,14 @@ static int fork_child (program_list_t *pl) status = pipe (fd_pipe); if (status != 0) { - syslog (LOG_ERR, "exec plugin: pipe failed: %s", strerror (errno)); + ERROR ("exec plugin: pipe failed: %s", strerror (errno)); return (-1); } pl->pid = fork (); if (pl->pid < 0) { - syslog (LOG_ERR, "exec plugin: fork failed: %s", strerror (errno)); + ERROR ("exec plugin: fork failed: %s", strerror (errno)); return (-1); } else if (pl->pid == 0) @@ -270,7 +269,7 @@ static void *exec_read_one (void *arg) fh = fdopen (fd, "r"); if (fh == NULL) { - syslog (LOG_ERR, "exec plugin: fdopen (%i) failed: %s", fd, + ERROR ("exec plugin: fdopen (%i) failed: %s", fd, strerror (errno)); kill (pl->pid, SIGTERM); close (fd); @@ -284,7 +283,7 @@ static void *exec_read_one (void *arg) char *type_instance; char *value; - DBG ("buffer = %s", buffer); + DEBUG ("buffer = %s", buffer); len = strlen (buffer); if (len < 5) @@ -304,7 +303,7 @@ static void *exec_read_one (void *arg) if ((strcasecmp ("counter", type) != 0) && (strcasecmp ("gauge", type) != 0)) { - syslog (LOG_WARNING, "exec plugin: Received invalid type: %s", type); + WARNING ("exec plugin: Received invalid type: %s", type); continue; } @@ -314,7 +313,7 @@ static void *exec_read_one (void *arg) *value = '\0'; value++; - DBG ("value = %s", value); + DEBUG ("value = %s", value); if (strcasecmp ("counter", type) == 0) submit_counter (type_instance, atoll (value)); diff --git a/src/hddtemp.c b/src/hddtemp.c index 353fbe3c..c2ff19e5 100644 --- a/src/hddtemp.c +++ b/src/hddtemp.c @@ -30,7 +30,6 @@ #include "common.h" #include "plugin.h" #include "configfile.h" -#include "utils_debug.h" #if HAVE_NETDB_H && HAVE_SYS_SOCKET_H && HAVE_NETINET_IN_H \ && HAVE_NETINET_TCP_H && HAVE_LIBGEN_H @@ -134,7 +133,7 @@ static int hddtemp_query_daemon (char *buffer, int buffer_size) if ((ai_return = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0) { - syslog (LOG_ERR, "hddtemp: getaddrinfo (%s, %s): %s", + ERROR ("hddtemp: getaddrinfo (%s, %s): %s", host, port, ai_return == EAI_SYSTEM ? strerror (errno) : gai_strerror (ai_return)); return (-1); @@ -146,7 +145,7 @@ static int hddtemp_query_daemon (char *buffer, int buffer_size) /* create our socket descriptor */ if ((fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol)) < 0) { - syslog (LOG_ERR, "hddtemp: socket: %s", + ERROR ("hddtemp: socket: %s", strerror (errno)); continue; } @@ -154,7 +153,7 @@ static int hddtemp_query_daemon (char *buffer, int buffer_size) /* connect to the hddtemp daemon */ if (connect (fd, (struct sockaddr *) ai_ptr->ai_addr, ai_ptr->ai_addrlen)) { - DBG ("hddtemp: connect (%s, %s): %s", host, port, + DEBUG ("hddtemp: connect (%s, %s): %s", host, port, strerror (errno)); close (fd); fd = -1; @@ -170,7 +169,7 @@ static int hddtemp_query_daemon (char *buffer, int buffer_size) if (fd < 0) { - syslog (LOG_ERR, "hddtemp: Could not connect to daemon."); + ERROR ("hddtemp: Could not connect to daemon."); return (-1); } @@ -185,7 +184,7 @@ static int hddtemp_query_daemon (char *buffer, int buffer_size) if ((errno == EAGAIN) || (errno == EINTR)) continue; - syslog (LOG_ERR, "hddtemp: Error reading from socket: %s", + ERROR ("hddtemp: Error reading from socket: %s", strerror (errno)); close (fd); return (-1); @@ -199,11 +198,11 @@ static int hddtemp_query_daemon (char *buffer, int buffer_size) if (buffer_fill >= buffer_size) { buffer[buffer_size - 1] = '\0'; - syslog (LOG_WARNING, "hddtemp: Message from hddtemp has been truncated."); + WARNING ("hddtemp: Message from hddtemp has been truncated."); } else if (buffer_fill == 0) { - syslog (LOG_WARNING, "hddtemp: Peer has unexpectedly shut down the socket. " + WARNING ("hddtemp: Peer has unexpectedly shut down the socket. " "Buffer: `%s'", buffer); close (fd); return (-1); @@ -267,7 +266,7 @@ static int hddtemp_init (void) if ((fh = fopen ("/proc/partitions", "r")) != NULL) { - DBG ("Looking at /proc/partitions..."); + DEBUG ("Looking at /proc/partitions..."); while (fgets (buf, sizeof (buf), fh) != NULL) { @@ -341,25 +340,25 @@ static int hddtemp_init (void) /* Skip all other majors. */ default: - DBG ("Skipping unknown major %i", major); + DEBUG ("Skipping unknown major %i", major); continue; } /* switch (major) */ if ((name = strdup (fields[3])) == NULL) { - syslog (LOG_ERR, "hddtemp: strdup(%s) == NULL", fields[3]); + ERROR ("hddtemp: strdup(%s) == NULL", fields[3]); continue; } if ((entry = (hddname_t *) malloc (sizeof (hddname_t))) == NULL) { - syslog (LOG_ERR, "hddtemp: malloc (%u) == NULL", + ERROR ("hddtemp: malloc (%u) == NULL", (unsigned int) sizeof (hddname_t)); free (name); continue; } - DBG ("Found disk: %s (%u:%u).", name, major, minor); + DEBUG ("Found disk: %s (%u:%u).", name, major, minor); entry->major = major; entry->minor = minor; @@ -379,7 +378,7 @@ static int hddtemp_init (void) fclose (fh); } else - DBG ("Could not open /proc/partitions: %s", + DEBUG ("Could not open /proc/partitions: %s", strerror (errno)); #endif /* KERNEL_LINUX */ @@ -405,7 +404,7 @@ static char *hddtemp_get_name (char *drive) if (list == NULL) { - DBG ("Don't know %s, keeping name as-is.", drive); + DEBUG ("Don't know %s, keeping name as-is.", drive); return (strdup (drive)); } diff --git a/src/iptables.c b/src/iptables.c index b6aa938e..bc155593 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -24,7 +24,6 @@ #include "common.h" #include "plugin.h" #include "configfile.h" -#include "utils_debug.h" #if HAVE_LIBIPTC_LIBIPTC_H # include diff --git a/src/irq.c b/src/irq.c index 6c30e95a..d44ac0b3 100644 --- a/src/irq.c +++ b/src/irq.c @@ -78,7 +78,7 @@ static int irq_config (const char *key, const char *value) if (temp == NULL) { fprintf (stderr, "irq plugin: Cannot allocate more memory.\n"); - syslog (LOG_ERR, "irq plugin: Cannot allocate more memory."); + ERROR ("irq plugin: Cannot allocate more memory."); return (1); } irq_list = temp; @@ -91,7 +91,7 @@ static int irq_config (const char *key, const char *value) { fprintf (stderr, "irq plugin: Irq value is not a " "number: `%s'\n", value); - syslog (LOG_ERR, "irq plugin: Irq value is not a " + ERROR ("irq plugin: Irq value is not a " "number: `%s'", value); return (1); } @@ -178,7 +178,7 @@ static int irq_read (void) if ((fh = fopen ("/proc/interrupts", "r")) == NULL) { - syslog (LOG_WARNING, "irq plugin: fopen (/proc/interrupts): %s", + WARNING ("irq plugin: fopen (/proc/interrupts): %s", strerror (errno)); return (-1); } diff --git a/src/load.c b/src/load.c index 08766556..aaba3a5f 100644 --- a/src/load.c +++ b/src/load.c @@ -82,7 +82,7 @@ static int load_read (void) if (getloadavg (load, 3) == 3) load_submit (load[LOADAVG_1MIN], load[LOADAVG_5MIN], load[LOADAVG_15MIN]); else - syslog (LOG_WARNING, "load: getloadavg failed: %s", strerror (errno)); + WARNING ("load: getloadavg failed: %s", strerror (errno)); /* #endif HAVE_GETLOADAVG */ #elif defined(KERNEL_LINUX) @@ -95,19 +95,19 @@ static int load_read (void) if ((loadavg = fopen ("/proc/loadavg", "r")) == NULL) { - syslog (LOG_WARNING, "load: fopen: %s", strerror (errno)); + WARNING ("load: fopen: %s", strerror (errno)); return; } if (fgets (buffer, 16, loadavg) == NULL) { - syslog (LOG_WARNING, "load: fgets: %s", strerror (errno)); + WARNING ("load: fgets: %s", strerror (errno)); fclose (loadavg); return; } if (fclose (loadavg)) - syslog (LOG_WARNING, "load: fclose: %s", strerror (errno)); + WARNING ("load: fclose: %s", strerror (errno)); numfields = strsplit (buffer, fields, 8); diff --git a/src/mbmon.c b/src/mbmon.c index e03f2f9b..241d7d04 100644 --- a/src/mbmon.c +++ b/src/mbmon.c @@ -25,7 +25,6 @@ #include "common.h" #include "plugin.h" #include "configfile.h" -#include "utils_debug.h" #if HAVE_NETDB_H && HAVE_SYS_SOCKET_H && HAVE_NETINET_IN_H && HAVE_NETINET_TCP_H # include @@ -140,7 +139,7 @@ static int mbmon_query_daemon (char *buffer, int buffer_size) if ((ai_return = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0) { - syslog (LOG_ERR, "mbmon: getaddrinfo (%s, %s): %s", + ERROR ("mbmon: getaddrinfo (%s, %s): %s", host, port, ai_return == EAI_SYSTEM ? strerror (errno) : gai_strerror (ai_return)); return (-1); @@ -152,7 +151,7 @@ static int mbmon_query_daemon (char *buffer, int buffer_size) /* create our socket descriptor */ if ((fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol)) < 0) { - syslog (LOG_ERR, "mbmon: socket: %s", + ERROR ("mbmon: socket: %s", strerror (errno)); continue; } @@ -160,7 +159,7 @@ static int mbmon_query_daemon (char *buffer, int buffer_size) /* connect to the mbmon daemon */ if (connect (fd, (struct sockaddr *) ai_ptr->ai_addr, ai_ptr->ai_addrlen)) { - DBG ("mbmon: connect (%s, %s): %s", host, port, + DEBUG ("mbmon: connect (%s, %s): %s", host, port, strerror (errno)); close (fd); fd = -1; @@ -176,7 +175,7 @@ static int mbmon_query_daemon (char *buffer, int buffer_size) if (fd < 0) { - syslog (LOG_ERR, "mbmon: Could not connect to daemon."); + ERROR ("mbmon: Could not connect to daemon."); return (-1); } @@ -191,7 +190,7 @@ static int mbmon_query_daemon (char *buffer, int buffer_size) if ((errno == EAGAIN) || (errno == EINTR)) continue; - syslog (LOG_ERR, "mbmon: Error reading from socket: %s", + ERROR ("mbmon: Error reading from socket: %s", strerror (errno)); close (fd); return (-1); @@ -205,11 +204,11 @@ static int mbmon_query_daemon (char *buffer, int buffer_size) if (buffer_fill >= buffer_size) { buffer[buffer_size - 1] = '\0'; - syslog (LOG_WARNING, "mbmon: Message from mbmon has been truncated."); + WARNING ("mbmon: Message from mbmon has been truncated."); } else if (buffer_fill == 0) { - syslog (LOG_WARNING, "mbmon: Peer has unexpectedly shut down the socket. " + WARNING ("mbmon: Peer has unexpectedly shut down the socket. " "Buffer: `%s'", buffer); close (fd); return (-1); @@ -292,7 +291,7 @@ static int mbmon_read (void) value = strtod (t, &nextc); if ((*nextc != '\n') && (*nextc != '\0')) { - syslog (LOG_ERR, "mbmon: value for `%s' contains invalid characters: `%s'", s, t); + ERROR ("mbmon: value for `%s' contains invalid characters: `%s'", s, t); break; } diff --git a/src/memory.c b/src/memory.c index 38a6dc2d..91680279 100644 --- a/src/memory.c +++ b/src/memory.c @@ -22,7 +22,6 @@ #include "collectd.h" #include "common.h" #include "plugin.h" -#include "utils_debug.h" #ifdef HAVE_SYS_SYSCTL_H # include @@ -149,7 +148,7 @@ static int memory_read (void) (host_info_t) &vm_data, &vm_data_len)) != KERN_SUCCESS) { - syslog (LOG_ERR, "memory-plugin: host_statistics failed and returned the value %i", (int) status); + ERROR ("memory-plugin: host_statistics failed and returned the value %i", (int) status); return (-1); } @@ -215,11 +214,11 @@ static int memory_read (void) (void *) &sysctl_vals[i], &len, NULL, 0)) < 0) { - syslog (LOG_ERR, "memory plugin: sysctlbyname (%s): %s", + ERROR ("memory plugin: sysctlbyname (%s): %s", sysctl_keys[i], strerror (errno)); return (-1); } - DBG ("%26s: %6i", sysctl_keys[i], sysctl_vals[i]); + DEBUG ("%26s: %6i", sysctl_keys[i], sysctl_vals[i]); } /* for i */ /* multiply all all page counts with the pagesize */ @@ -246,7 +245,7 @@ static int memory_read (void) if ((fh = fopen ("/proc/meminfo", "r")) == NULL) { - syslog (LOG_WARNING, "memory: fopen: %s", strerror (errno)); + WARNING ("memory: fopen: %s", strerror (errno)); return (-1); } @@ -274,7 +273,7 @@ static int memory_read (void) } if (fclose (fh)) - syslog (LOG_WARNING, "memory: fclose: %s", strerror (errno)); + WARNING ("memory: fclose: %s", strerror (errno)); if (mem_used >= (mem_free + mem_buffered + mem_cached)) { diff --git a/src/multimeter.c b/src/multimeter.c index 8cb18c81..04196bbe 100644 --- a/src/multimeter.c +++ b/src/multimeter.c @@ -81,7 +81,7 @@ static int multimeter_read_value(double *value) if (gettimeofday (&time_end, NULL) < 0) { - syslog (LOG_ERR, "multimeter plugin: gettimeofday failed: %s", + ERROR ("multimeter plugin: gettimeofday failed: %s", strerror (errno)); return (-1); } @@ -103,7 +103,7 @@ static int multimeter_read_value(double *value) if (gettimeofday (&time_now, NULL) < 0) { - syslog (LOG_ERR, "multimeter plugin: " + ERROR ("multimeter plugin: " "gettimeofday failed: %s", strerror (errno)); return (-1); @@ -157,7 +157,7 @@ static int multimeter_read_value(double *value) } else /* status == -1 */ { - syslog (LOG_ERR, "multimeter plugin: " + ERROR ("multimeter plugin: " "select failed: %s", strerror (errno)); break; @@ -201,14 +201,14 @@ static int multimeter_init (void) } else { - syslog (LOG_INFO, "multimeter plugin: Device " + INFO ("multimeter plugin: Device " "found at %s", device); return (0); } } } - syslog (LOG_ERR, "multimeter plugin: No device found"); + ERROR ("multimeter plugin: No device found"); return (-1); } #undef LINE_LENGTH diff --git a/src/mysql.c b/src/mysql.c index a2604e40..f622d3d6 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -120,7 +120,7 @@ static MYSQL *getconnection (void) int err; if ((err = mysql_ping (con)) != 0) { - syslog (LOG_WARNING, "mysql_ping failed: %s", mysql_error (con)); + WARNING ("mysql_ping failed: %s", mysql_error (con)); state = 0; } else @@ -145,14 +145,14 @@ static MYSQL *getconnection (void) if ((con = mysql_init (con)) == NULL) { - syslog (LOG_ERR, "mysql_init failed: %s", mysql_error (con)); + ERROR ("mysql_init failed: %s", mysql_error (con)); state = 0; return (NULL); } if (mysql_real_connect (con, host, user, pass, db, 0, NULL, 0) == NULL) { - syslog (LOG_ERR, "mysql_real_connect failed: %s", mysql_error (con)); + ERROR ("mysql_real_connect failed: %s", mysql_error (con)); state = 0; return (NULL); } @@ -291,14 +291,14 @@ static int mysql_read (void) if (mysql_real_query (con, query, query_len)) { - syslog (LOG_ERR, "mysql_real_query failed: %s\n", + ERROR ("mysql_real_query failed: %s\n", mysql_error (con)); return (-1); } if ((res = mysql_store_result (con)) == NULL) { - syslog (LOG_ERR, "mysql_store_result failed: %s\n", + ERROR ("mysql_store_result failed: %s\n", mysql_error (con)); return (-1); } diff --git a/src/network.c b/src/network.c index cf2a0179..6c6e0f60 100644 --- a/src/network.c +++ b/src/network.c @@ -23,7 +23,6 @@ #include "plugin.h" #include "common.h" #include "configfile.h" -#include "utils_debug.h" #include "network.h" @@ -263,7 +262,7 @@ static int parse_part_values (void **ret_buffer, int *ret_buffer_len, if (buffer_len < (15)) { - DBG ("packet is too short: buffer_len = %i", buffer_len); + DEBUG ("packet is too short: buffer_len = %i", buffer_len); return (-1); } @@ -278,7 +277,7 @@ static int parse_part_values (void **ret_buffer, int *ret_buffer_len, if (h_num != ((h_length - 6) / 9)) { - DBG ("`length' and `num of values' don't match"); + DEBUG ("`length' and `num of values' don't match"); return (-1); } @@ -329,7 +328,7 @@ static int parse_part_string (void **ret_buffer, int *ret_buffer_len, uint16_t h_length; uint16_t h_type; - DBG ("ret_buffer = %p; ret_buffer_len = %i; output = %p; output_len = %i;", + DEBUG ("ret_buffer = %p; ret_buffer_len = %i; output = %p; output_len = %i;", *ret_buffer, *ret_buffer_len, (void *) output, output_len); @@ -338,11 +337,11 @@ static int parse_part_string (void **ret_buffer, int *ret_buffer_len, h_length = ntohs (ps.head->length); h_type = ntohs (ps.head->type); - DBG ("length = %hu; type = %hu;", h_length, h_type); + DEBUG ("length = %hu; type = %hu;", h_length, h_type); if (buffer_len < h_length) { - DBG ("packet is too short"); + DEBUG ("packet is too short"); return (-1); } assert ((h_type == TYPE_HOST) @@ -354,18 +353,18 @@ static int parse_part_string (void **ret_buffer, int *ret_buffer_len, ps.value = buffer + 4; if (ps.value[h_length - 5] != '\0') { - DBG ("String does not end with a nullbyte"); + DEBUG ("String does not end with a nullbyte"); return (-1); } if (output_len < (h_length - 4)) { - DBG ("output buffer is too small"); + DEBUG ("output buffer is too small"); return (-1); } strcpy (output, ps.value); - DBG ("output = %s", output); + DEBUG ("output = %s", output); *ret_buffer = (void *) (buffer + h_length); *ret_buffer_len = buffer_len - h_length; @@ -381,7 +380,7 @@ static int parse_packet (void *buffer, int buffer_len) value_list_t vl = VALUE_LIST_INIT; char type[DATA_MAX_NAME_LEN]; - DBG ("buffer = %p; buffer_len = %i;", buffer, buffer_len); + DEBUG ("buffer = %p; buffer_len = %i;", buffer, buffer_len); memset (&vl, '\0', sizeof (vl)); memset (&type, '\0', sizeof (type)); @@ -401,7 +400,7 @@ static int parse_packet (void *buffer, int buffer_len) if (status != 0) { - DBG ("parse_part_values failed."); + DEBUG ("parse_part_values failed."); break; } @@ -410,12 +409,12 @@ static int parse_packet (void *buffer, int buffer_len) && (strlen (vl.plugin) > 0) && (strlen (type) > 0)) { - DBG ("dispatching values"); + DEBUG ("dispatching values"); plugin_dispatch_values (type, &vl); } else { - DBG ("NOT dispatching values"); + DEBUG ("NOT dispatching values"); } } else if (header->type == ntohs (TYPE_TIME)) @@ -452,7 +451,7 @@ static int parse_packet (void *buffer, int buffer_len) } else { - DBG ("Unknown part type: 0x%0hx", header->type); + DEBUG ("Unknown part type: 0x%0hx", header->type); buffer = ((char *) buffer) + header->length; } } /* while (buffer_len > sizeof (part_header_t)) */ @@ -486,7 +485,7 @@ static int network_set_ttl (const sockent_t *se, const struct addrinfo *ai) if ((network_config_ttl < 1) || (network_config_ttl > 255)) return (-1); - DBG ("ttl = %i", network_config_ttl); + DEBUG ("ttl = %i", network_config_ttl); if (ai->ai_family == AF_INET) { @@ -502,7 +501,7 @@ static int network_set_ttl (const sockent_t *se, const struct addrinfo *ai) &network_config_ttl, sizeof (network_config_ttl)) == -1) { - syslog (LOG_ERR, "setsockopt: %s", strerror (errno)); + ERROR ("setsockopt: %s", strerror (errno)); return (-1); } } @@ -521,7 +520,7 @@ static int network_set_ttl (const sockent_t *se, const struct addrinfo *ai) &network_config_ttl, sizeof (network_config_ttl)) == -1) { - syslog (LOG_ERR, "setsockopt: %s", strerror (errno)); + ERROR ("setsockopt: %s", strerror (errno)); return (-1); } } @@ -533,11 +532,11 @@ static int network_bind_socket (const sockent_t *se, const struct addrinfo *ai) { int loop = 1; - DBG ("fd = %i; calling `bind'", se->fd); + DEBUG ("fd = %i; calling `bind'", se->fd); if (bind (se->fd, ai->ai_addr, ai->ai_addrlen) == -1) { - syslog (LOG_ERR, "bind: %s", strerror (errno)); + ERROR ("bind: %s", strerror (errno)); return (-1); } @@ -548,7 +547,7 @@ static int network_bind_socket (const sockent_t *se, const struct addrinfo *ai) { struct ip_mreq mreq; - DBG ("fd = %i; IPv4 multicast address found", se->fd); + DEBUG ("fd = %i; IPv4 multicast address found", se->fd); mreq.imr_multiaddr.s_addr = addr->sin_addr.s_addr; mreq.imr_interface.s_addr = htonl (INADDR_ANY); @@ -556,14 +555,14 @@ static int network_bind_socket (const sockent_t *se, const struct addrinfo *ai) if (setsockopt (se->fd, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof (loop)) == -1) { - syslog (LOG_ERR, "setsockopt: %s", strerror (errno)); + ERROR ("setsockopt: %s", strerror (errno)); return (-1); } if (setsockopt (se->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof (mreq)) == -1) { - syslog (LOG_ERR, "setsockopt: %s", strerror (errno)); + ERROR ("setsockopt: %s", strerror (errno)); return (-1); } } @@ -576,7 +575,7 @@ static int network_bind_socket (const sockent_t *se, const struct addrinfo *ai) { struct ipv6_mreq mreq; - DBG ("fd = %i; IPv6 multicast address found", se->fd); + DEBUG ("fd = %i; IPv6 multicast address found", se->fd); memcpy (&mreq.ipv6mr_multiaddr, &addr->sin6_addr, @@ -596,14 +595,14 @@ static int network_bind_socket (const sockent_t *se, const struct addrinfo *ai) if (setsockopt (se->fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &loop, sizeof (loop)) == -1) { - syslog (LOG_ERR, "setsockopt: %s", strerror (errno)); + ERROR ("setsockopt: %s", strerror (errno)); return (-1); } if (setsockopt (se->fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof (mreq)) == -1) { - syslog (LOG_ERR, "setsockopt: %s", strerror (errno)); + ERROR ("setsockopt: %s", strerror (errno)); return (-1); } } @@ -623,7 +622,7 @@ static sockent_t *network_create_socket (const char *node, sockent_t *se_head = NULL; sockent_t *se_tail = NULL; - DBG ("node = %s, service = %s", node, service); + DEBUG ("node = %s, service = %s", node, service); memset (&ai_hints, '\0', sizeof (ai_hints)); ai_hints.ai_flags = 0; @@ -640,7 +639,7 @@ static sockent_t *network_create_socket (const char *node, ai_return = getaddrinfo (node, service, &ai_hints, &ai_list); if (ai_return != 0) { - syslog (LOG_ERR, "getaddrinfo (%s, %s): %s", + ERROR ("getaddrinfo (%s, %s): %s", (node == NULL) ? "(null)" : node, (service == NULL) ? "(null)" : service, (ai_return == EAI_SYSTEM) @@ -655,13 +654,13 @@ static sockent_t *network_create_socket (const char *node, if ((se = (sockent_t *) malloc (sizeof (sockent_t))) == NULL) { - syslog (LOG_EMERG, "malloc: %s", strerror (errno)); + ERROR ("malloc: %s", strerror (errno)); continue; } if ((se->addr = (struct sockaddr_storage *) malloc (sizeof (struct sockaddr_storage))) == NULL) { - syslog (LOG_EMERG, "malloc: %s", strerror (errno)); + ERROR ("malloc: %s", strerror (errno)); free (se); continue; } @@ -678,7 +677,7 @@ static sockent_t *network_create_socket (const char *node, if (se->fd == -1) { - syslog (LOG_ERR, "socket: %s", strerror (errno)); + ERROR ("socket: %s", strerror (errno)); free (se->addr); free (se); continue; @@ -828,7 +827,7 @@ int network_receive (void) if (listen_sockets_num == 0) { - syslog (LOG_ERR, "network: Failed to open a listening socket."); + ERROR ("network: Failed to open a listening socket."); return (-1); } @@ -840,7 +839,7 @@ int network_receive (void) { if (errno == EINTR) continue; - syslog (LOG_ERR, "poll failed: %s", + ERROR ("poll failed: %s", strerror (errno)); return (-1); } @@ -856,7 +855,7 @@ int network_receive (void) 0 /* no flags */); if (buffer_len < 0) { - syslog (LOG_ERR, "recv failed: %s", strerror (errno)); + ERROR ("recv failed: %s", strerror (errno)); return (-1); } @@ -877,7 +876,7 @@ static void network_send_buffer (const char *buffer, int buffer_len) sockent_t *se; int status; - DBG ("buffer_len = %i", buffer_len); + DEBUG ("buffer_len = %i", buffer_len); for (se = sending_sockets; se != NULL; se = se->next) { @@ -889,7 +888,7 @@ static void network_send_buffer (const char *buffer, int buffer_len) { if (errno == EINTR) continue; - syslog (LOG_ERR, "network plugin: sendto failed: %s", + ERROR ("network plugin: sendto failed: %s", strerror (errno)); break; } @@ -909,7 +908,7 @@ static int add_to_buffer (char *buffer, int buffer_size, vl->host, strlen (vl->host)) != 0) return (-1); strcpy (vl_def->host, vl->host); - DBG ("host = %s", vl->host); + DEBUG ("host = %s", vl->host); } if (vl_def->time != vl->time) @@ -918,7 +917,7 @@ static int add_to_buffer (char *buffer, int buffer_size, (uint64_t) vl->time)) return (-1); vl_def->time = vl->time; - DBG ("time = %u", (unsigned int) vl->time); + DEBUG ("time = %u", (unsigned int) vl->time); } if (strcmp (vl_def->plugin, vl->plugin) != 0) @@ -927,7 +926,7 @@ static int add_to_buffer (char *buffer, int buffer_size, vl->plugin, strlen (vl->plugin)) != 0) return (-1); strcpy (vl_def->plugin, vl->plugin); - DBG ("plugin = %s", vl->plugin); + DEBUG ("plugin = %s", vl->plugin); } if (strcmp (vl_def->plugin_instance, vl->plugin_instance) != 0) @@ -937,7 +936,7 @@ static int add_to_buffer (char *buffer, int buffer_size, strlen (vl->plugin_instance)) != 0) return (-1); strcpy (vl_def->plugin_instance, vl->plugin_instance); - DBG ("plugin_instance = %s", vl->plugin_instance); + DEBUG ("plugin_instance = %s", vl->plugin_instance); } if (strcmp (type_def, ds->type) != 0) @@ -946,7 +945,7 @@ static int add_to_buffer (char *buffer, int buffer_size, ds->type, strlen (ds->type)) != 0) return (-1); strcpy (type_def, ds->type); - DBG ("type = %s", ds->type); + DEBUG ("type = %s", ds->type); } if (strcmp (vl_def->type_instance, vl->type_instance) != 0) @@ -956,7 +955,7 @@ static int add_to_buffer (char *buffer, int buffer_size, strlen (vl->type_instance)) != 0) return (-1); strcpy (vl_def->type_instance, vl->type_instance); - DBG ("type_instance = %s", vl->type_instance); + DEBUG ("type_instance = %s", vl->type_instance); } if (write_part_values (&buffer, &buffer_size, ds, vl) != 0) @@ -1005,7 +1004,7 @@ static int network_write (const data_set_t *ds, const value_list_t *vl) if (status < 0) { - syslog (LOG_ERR, "network plugin: Unable to append to the " + ERROR ("network plugin: Unable to append to the " "buffer for some weird reason"); } else if ((sizeof (send_buffer) - send_buffer_fill) < 15) @@ -1063,7 +1062,7 @@ static int network_config (const char *key, const char *val) static int network_shutdown (void) { - DBG ("Shutting down."); + DEBUG ("Shutting down."); listen_loop++; @@ -1096,7 +1095,7 @@ static int network_init (void) receive_thread, NULL /* no argument */); if (status != 0) - syslog (LOG_ERR, "network: pthread_create failed: %s", + ERROR ("network: pthread_create failed: %s", strerror (errno)); } return (0); diff --git a/src/nfs.c b/src/nfs.c index 004c8f5e..81f07937 100644 --- a/src/nfs.c +++ b/src/nfs.c @@ -23,7 +23,6 @@ #include "collectd.h" #include "common.h" #include "plugin.h" -#include "utils_debug.h" #define MODULE_NAME "nfs" @@ -215,7 +214,7 @@ static void nfs_procedures_submit (const char *plugin_instance, values[0].counter = val[i]; strncpy (vl.type_instance, names[i], sizeof (vl.type_instance)); - DBG ("%s-%s/nfs_procedure-%s = %llu", + DEBUG ("%s-%s/nfs_procedure-%s = %llu", vl.plugin, vl.plugin_instance, vl.type_instance, val[i]); plugin_dispatch_values ("nfs_procedure", &vl); @@ -251,7 +250,7 @@ static void nfs_read_stats_file (FILE *fh, char *inst) if ((numfields - 2) != nfs2_procedures_names_num) { - syslog (LOG_WARNING, "nfs plugin: Wrong " + WARNING ("nfs plugin: Wrong " "number of fields (= %i) " "for NFSv2 statistics.", numfields - 2); @@ -265,7 +264,7 @@ static void nfs_read_stats_file (FILE *fh, char *inst) values = (unsigned long long *) malloc (nfs2_procedures_names_num * sizeof (unsigned long long)); if (values == NULL) { - syslog (LOG_ERR, "nfs plugin: malloc " + ERROR ("nfs plugin: malloc " "failed: %s", strerror (errno)); continue; @@ -287,7 +286,7 @@ static void nfs_read_stats_file (FILE *fh, char *inst) if ((numfields - 2) != nfs3_procedures_names_num) { - syslog (LOG_WARNING, "nfs plugin: Wrong " + WARNING ("nfs plugin: Wrong " "number of fields (= %i) " "for NFSv3 statistics.", numfields - 2); @@ -301,7 +300,7 @@ static void nfs_read_stats_file (FILE *fh, char *inst) values = (unsigned long long *) malloc (nfs3_procedures_names_num * sizeof (unsigned long long)); if (values == NULL) { - syslog (LOG_ERR, "nfs plugin: malloc " + ERROR ("nfs plugin: malloc " "failed: %s", strerror (errno)); continue; diff --git a/src/ntpd.c b/src/ntpd.c index e4a230b3..668e302d 100644 --- a/src/ntpd.c +++ b/src/ntpd.c @@ -23,7 +23,6 @@ #include "common.h" #include "plugin.h" #include "configfile.h" -#include "utils_debug.h" #if HAVE_SYS_SOCKET_H # define NTPD_HAVE_READ 1 @@ -372,7 +371,7 @@ static int ntpd_connect (void) if (sock_descr >= 0) return (sock_descr); - DBG ("Opening a new socket"); + DEBUG ("Opening a new socket"); host = ntpd_host; if (host == NULL) @@ -390,10 +389,10 @@ static int ntpd_connect (void) if ((status = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0) { - DBG ("getaddrinfo (%s, %s): %s", + DEBUG ("getaddrinfo (%s, %s): %s", host, port, status == EAI_SYSTEM ? strerror (errno) : gai_strerror (status)); - syslog (LOG_ERR, "ntpd plugin: getaddrinfo (%s, %s): %s", + ERROR ("ntpd plugin: getaddrinfo (%s, %s): %s", host, port, status == EAI_SYSTEM ? strerror (errno) : gai_strerror (status)); return (-1); @@ -422,8 +421,8 @@ static int ntpd_connect (void) if (sock_descr < 0) { - DBG ("Unable to connect to server."); - syslog (LOG_ERR, "ntpd plugin: Unable to connect to server."); + DEBUG ("Unable to connect to server."); + ERROR ("ntpd plugin: Unable to connect to server."); } return (sock_descr); @@ -471,7 +470,7 @@ static int ntpd_receive_response (int req_code, int *res_items, int *res_size, if (gettimeofday (&time_end, NULL) < 0) { - syslog (LOG_ERR, "ntpd plugin: gettimeofday failed: %s", + ERROR ("ntpd plugin: gettimeofday failed: %s", strerror (errno)); return (-1); } @@ -482,7 +481,7 @@ static int ntpd_receive_response (int req_code, int *res_items, int *res_size, { if (gettimeofday (&time_now, NULL) < 0) { - syslog (LOG_ERR, "ntpd plugin: gettimeofday failed: %s", + ERROR ("ntpd plugin: gettimeofday failed: %s", strerror (errno)); return (-1); } @@ -495,7 +494,7 @@ static int ntpd_receive_response (int req_code, int *res_items, int *res_size, poll_s.events = POLLIN | POLLPRI; poll_s.revents = 0; - DBG ("Polling for %ims", timeout); + DEBUG ("Polling for %ims", timeout); status = poll (&poll_s, 1, timeout); if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR))) @@ -503,15 +502,15 @@ static int ntpd_receive_response (int req_code, int *res_items, int *res_size, if (status < 0) { - DBG ("poll failed: %s", strerror (errno)); - syslog (LOG_ERR, "ntpd plugin: poll failed: %s", + DEBUG ("poll failed: %s", strerror (errno)); + ERROR ("ntpd plugin: poll failed: %s", strerror (errno)); return (-1); } if (status == 0) /* timeout */ { - DBG ("timeout reached."); + DEBUG ("timeout reached."); break; } @@ -523,50 +522,50 @@ static int ntpd_receive_response (int req_code, int *res_items, int *res_size, if (status < 0) { - DBG ("recv(2) failed: %s", strerror (errno)); - DBG ("Closing socket #%i", sd); + DEBUG ("recv(2) failed: %s", strerror (errno)); + DEBUG ("Closing socket #%i", sd); close (sd); sock_descr = sd = -1; return (-1); } - DBG ("recv'd %i bytes", status); + DEBUG ("recv'd %i bytes", status); /* * Do some sanity checks first */ if (status < RESP_HEADER_SIZE) { - syslog (LOG_WARNING, "ntpd plugin: Short (%i bytes) packet received", + WARNING ("ntpd plugin: Short (%i bytes) packet received", (int) status); continue; } if (INFO_MODE (res.rm_vn_mode) != MODE_PRIVATE) { - syslog (LOG_NOTICE, "ntpd plugin: Packet received with mode %i", + NOTICE ("ntpd plugin: Packet received with mode %i", INFO_MODE (res.rm_vn_mode)); continue; } if (INFO_IS_AUTH (res.auth_seq)) { - syslog (LOG_NOTICE, "ntpd plugin: Encrypted packet received"); + NOTICE ("ntpd plugin: Encrypted packet received"); continue; } if (!ISRESPONSE (res.rm_vn_mode)) { - syslog (LOG_NOTICE, "ntpd plugin: Received request packet, " + NOTICE ("ntpd plugin: Received request packet, " "wanted response"); continue; } if (INFO_MBZ (res.mbz_itemsize)) { - syslog (LOG_WARNING, "ntpd plugin: Received packet with nonzero " + WARNING ("ntpd plugin: Received packet with nonzero " "MBZ field!"); continue; } if (res.implementation != IMPL_XNTPD) { - syslog (LOG_WARNING, "ntpd plugin: Asked for request of type %i, " + WARNING ("ntpd plugin: Asked for request of type %i, " "got %i", (int) IMPL_XNTPD, (int) res.implementation); continue; } @@ -574,7 +573,7 @@ static int ntpd_receive_response (int req_code, int *res_items, int *res_size, /* Check for error code */ if (INFO_ERR (res.err_nitems) != 0) { - syslog (LOG_ERR, "ntpd plugin: Received error code %i", + ERROR ("ntpd plugin: Received error code %i", (int) INFO_ERR(res.err_nitems)); return ((int) INFO_ERR (res.err_nitems)); } @@ -582,13 +581,13 @@ static int ntpd_receive_response (int req_code, int *res_items, int *res_size, /* extract number of items in this packet and the size of these items */ pkt_item_num = INFO_NITEMS (res.err_nitems); pkt_item_len = INFO_ITEMSIZE (res.mbz_itemsize); - DBG ("pkt_item_num = %i; pkt_item_len = %i;", + DEBUG ("pkt_item_num = %i; pkt_item_len = %i;", pkt_item_num, pkt_item_len); /* Check if the reported items fit in the packet */ if ((pkt_item_num * pkt_item_len) > (status - RESP_HEADER_SIZE)) { - syslog (LOG_ERR, "ntpd plugin: %i items * %i bytes > " + ERROR ("ntpd plugin: %i items * %i bytes > " "%i bytes - %i bytes header", (int) pkt_item_num, (int) pkt_item_len, (int) status, (int) RESP_HEADER_SIZE); @@ -600,14 +599,14 @@ static int ntpd_receive_response (int req_code, int *res_items, int *res_size, * items have the same size. Discard invalid packets. */ if (items_num == 0) /* first packet */ { - DBG ("*res_size = %i", pkt_item_len); + DEBUG ("*res_size = %i", pkt_item_len); *res_size = pkt_item_len; } else if (*res_size != pkt_item_len) { - DBG ("Error: *res_size = %i; pkt_item_len = %i;", + DEBUG ("Error: *res_size = %i; pkt_item_len = %i;", *res_size, pkt_item_len); - syslog (LOG_ERR, "Item sizes differ."); + ERROR ("Item sizes differ."); continue; } @@ -615,14 +614,14 @@ static int ntpd_receive_response (int req_code, int *res_items, int *res_size, pkt_padding = 0; if (res_item_size > pkt_item_len) pkt_padding = res_item_size - pkt_item_len; - DBG ("res_item_size = %i; pkt_padding = %i;", + DEBUG ("res_item_size = %i; pkt_padding = %i;", res_item_size, pkt_padding); /* Extract the sequence number */ pkt_sequence = INFO_SEQ (res.auth_seq); if ((pkt_sequence < 0) || (pkt_sequence > MAXSEQ)) { - syslog (LOG_ERR, "ntpd plugin: Received packet with sequence %i", + ERROR ("ntpd plugin: Received packet with sequence %i", pkt_sequence); continue; } @@ -630,7 +629,7 @@ static int ntpd_receive_response (int req_code, int *res_items, int *res_size, /* Check if this sequence has been received before. If so, discard it. */ if (pkt_recvd[pkt_sequence] != '\0') { - syslog (LOG_NOTICE, "ntpd plugin: Sequence %i received twice", + NOTICE ("ntpd plugin: Sequence %i received twice", pkt_sequence); continue; } @@ -641,20 +640,20 @@ static int ntpd_receive_response (int req_code, int *res_items, int *res_size, { if (pkt_lastseq != -1) { - syslog (LOG_ERR, "ntpd plugin: Two packets which both " + ERROR ("ntpd plugin: Two packets which both " "claim to be the last one in the " "sequence have been received."); continue; } pkt_lastseq = pkt_sequence; - DBG ("Last sequence = %i;", pkt_lastseq); + DEBUG ("Last sequence = %i;", pkt_lastseq); } /* * Enough with the checks. Copy the data now. * We start by allocating some more memory. */ - DBG ("realloc (%p, %i)", (void *) *res_data, + DEBUG ("realloc (%p, %i)", (void *) *res_data, (items_num + pkt_item_num) * res_item_size); items = realloc ((void *) *res_data, (items_num + pkt_item_num) * res_item_size); @@ -662,7 +661,7 @@ static int ntpd_receive_response (int req_code, int *res_items, int *res_size, if (items == NULL) { items = *res_data; - syslog (LOG_ERR, "ntpd plugin: realloc failed."); + ERROR ("ntpd plugin: realloc failed."); continue; } *res_data = items; @@ -721,13 +720,13 @@ static int ntpd_send_request (int req_code, int req_items, int req_size, char *r if (req_data != NULL) memcpy ((void *) req.data, (const void *) req_data, req_data_len); - DBG ("req_items = %i; req_size = %i; req_data = %p;", + DEBUG ("req_items = %i; req_size = %i; req_data = %p;", req_items, req_size, (void *) req_data); status = swrite (sd, (const char *) &req, REQ_LEN_NOMAC); if (status < 0) { - DBG ("`swrite' failed. Closing socket #%i", sd); + DEBUG ("`swrite' failed. Closing socket #%i", sd); close (sd); sock_descr = sd = -1; return (status); @@ -798,19 +797,19 @@ static int ntpd_read (void) if (status != 0) { - DBG ("ntpd_do_query failed with status %i", status); + DEBUG ("ntpd_do_query failed with status %i", status); return (-1); } if ((ik == NULL) || (ik_num == 0) || (ik_size == 0)) { - DBG ("ntpd_do_query returned: ik = %p; ik_num = %i; ik_size = %i;", + DEBUG ("ntpd_do_query returned: ik = %p; ik_num = %i; ik_size = %i;", (void *) ik, ik_num, ik_size); return (-1); } /* kerninfo -> estimated error */ - DBG ("info_kernel:\n" + DEBUG ("info_kernel:\n" " pll offset = %.8f\n" " pll frequency = %.8f\n" /* drift compensation */ " est error = %.8f\n", @@ -831,12 +830,12 @@ static int ntpd_read (void) sizeof (struct info_peer_summary)); if (status != 0) { - DBG ("ntpd_do_query failed with status %i", status); + DEBUG ("ntpd_do_query failed with status %i", status); return (-1); } if ((ps == NULL) || (ps_num == 0) || (ps_size == 0)) { - DBG ("ntpd_do_query returned: ps = %p; ps_num = %i; ps_size = %i;", + DEBUG ("ntpd_do_query returned: ps = %p; ps_num = %i; ps_size = %i;", (void *) ps, ps_num, ps_size); return (-1); } @@ -875,7 +874,7 @@ static int ntpd_read (void) NULL, 0, 0 /* no flags */); if (status != 0) { - syslog (LOG_ERR, "ntpd plugin: getnameinfo failed: %s", + ERROR ("ntpd plugin: getnameinfo failed: %s", status == EAI_SYSTEM ? strerror (errno) : gai_strerror (status)); @@ -925,7 +924,7 @@ static int ntpd_read (void) } } - DBG ("peer %i:\n" + DEBUG ("peer %i:\n" " peername = %s\n" " srcadr = 0x%08x\n" " delay = %f\n" diff --git a/src/ping.c b/src/ping.c index 48cea55c..48a0ac87 100644 --- a/src/ping.c +++ b/src/ping.c @@ -23,7 +23,6 @@ #include "common.h" #include "plugin.h" #include "configfile.h" -#include "utils_debug.h" #include #include "liboping/oping.h" @@ -78,14 +77,14 @@ static void add_hosts (void) hl_prev = NULL; while (hl_this != NULL) { - DBG ("host = %s, wait_left = %i, wait_time = %i, next = %p", + DEBUG ("host = %s, wait_left = %i, wait_time = %i, next = %p", hl_this->host, hl_this->wait_left, hl_this->wait_time, (void *) hl_this->next); if (hl_this->wait_left <= 0) { if (ping_host_add (pingobj, hl_this->host) == 0) { - DBG ("Successfully added host %s", hl_this->host); + DEBUG ("Successfully added host %s", hl_this->host); /* Remove the host from the linked list */ if (hl_prev != NULL) hl_prev->next = hl_this->next; @@ -130,7 +129,7 @@ static int ping_config (const char *key, const char *value) { if ((pingobj = ping_construct ()) == NULL) { - syslog (LOG_ERR, "ping: `ping_construct' failed: %s", + ERROR ("ping: `ping_construct' failed: %s", ping_get_error (pingobj)); return (1); } @@ -144,14 +143,14 @@ static int ping_config (const char *key, const char *value) if ((hl = (hostlist_t *) malloc (sizeof (hostlist_t))) == NULL) { - syslog (LOG_ERR, "ping plugin: malloc failed: %s", + ERROR ("ping plugin: malloc failed: %s", strerror (errno)); return (1); } if ((host = strdup (value)) == NULL) { free (hl); - syslog (LOG_ERR, "ping plugin: strdup failed: %s", + ERROR ("ping plugin: strdup failed: %s", strerror (errno)); return (1); } @@ -167,7 +166,7 @@ static int ping_config (const char *key, const char *value) int ttl = atoi (value); if (ping_setopt (pingobj, PING_DEF_TIMEOUT, (void *) &ttl)) { - syslog (LOG_WARNING, "ping: liboping did not accept the TTL value %i", ttl); + WARNING ("ping: liboping did not accept the TTL value %i", ttl); return (1); } } @@ -213,7 +212,7 @@ static int ping_read (void) if (ping_send (pingobj) < 0) { - syslog (LOG_ERR, "ping: `ping_send' failed: %s", + ERROR ("ping: `ping_send' failed: %s", ping_get_error (pingobj)); return (-1); } @@ -232,7 +231,7 @@ static int ping_read (void) &latency, &buf_len)) continue; - DBG ("host = %s, latency = %f", host, latency); + DEBUG ("host = %s, latency = %f", host, latency); ping_submit (host, latency); } diff --git a/src/plugin.c b/src/plugin.c index f2e205af..87fdcce6 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -26,7 +26,6 @@ #include "plugin.h" #include "configfile.h" #include "utils_llist.h" -#include "utils_debug.h" /* * Private structures @@ -112,7 +111,7 @@ static int plugin_load_file (char *file) lt_dlhandle dlh; void (*reg_handle) (void); - DBG ("file = %s", file); + DEBUG ("file = %s", file); lt_dlinit (); lt_dlerror (); /* clear errors */ @@ -121,14 +120,14 @@ static int plugin_load_file (char *file) { const char *error = lt_dlerror (); - syslog (LOG_ERR, "lt_dlopen failed: %s", error); - DBG ("lt_dlopen failed: %s", error); + ERROR ("lt_dlopen failed: %s", error); + DEBUG ("lt_dlopen failed: %s", error); return (1); } if ((reg_handle = (void (*) (void)) lt_dlsym (dlh, "module_register")) == NULL) { - syslog (LOG_WARNING, "Couldn't find symbol ``module_register'' in ``%s'': %s\n", + WARNING ("Couldn't find symbol ``module_register'' in ``%s'': %s\n", file, lt_dlerror ()); lt_dlclose (dlh); return (-1); @@ -150,7 +149,7 @@ void plugin_set_dir (const char *dir) if (dir == NULL) plugindir = NULL; else if ((plugindir = strdup (dir)) == NULL) - syslog (LOG_ERR, "strdup failed: %s", strerror (errno)); + ERROR ("strdup failed: %s", strerror (errno)); } #define BUFSIZE 512 @@ -165,7 +164,7 @@ int plugin_load (const char *type) struct stat statbuf; struct dirent *de; - DBG ("type = %s", type); + DEBUG ("type = %s", type); dir = plugin_get_dir (); ret = 1; @@ -174,14 +173,14 @@ int plugin_load (const char *type) * type when matching the filename */ if (snprintf (typename, BUFSIZE, "%s.so", type) >= BUFSIZE) { - syslog (LOG_WARNING, "snprintf: truncated: `%s.so'", type); + WARNING ("snprintf: truncated: `%s.so'", type); return (-1); } typename_len = strlen (typename); if ((dh = opendir (dir)) == NULL) { - syslog (LOG_ERR, "opendir (%s): %s", dir, strerror (errno)); + ERROR ("opendir (%s): %s", dir, strerror (errno)); return (-1); } @@ -192,13 +191,13 @@ int plugin_load (const char *type) if (snprintf (filename, BUFSIZE, "%s/%s", dir, de->d_name) >= BUFSIZE) { - syslog (LOG_WARNING, "snprintf: truncated: `%s/%s'", dir, de->d_name); + WARNING ("snprintf: truncated: `%s/%s'", dir, de->d_name); continue; } if (lstat (filename, &statbuf) == -1) { - syslog (LOG_WARNING, "stat %s: %s", filename, strerror (errno)); + WARNING ("stat %s: %s", filename, strerror (errno)); continue; } else if (!S_ISREG (statbuf.st_mode)) @@ -245,7 +244,7 @@ int plugin_register_read (const char *name, rf = (read_func_t *) malloc (sizeof (read_func_t)); if (rf == NULL) { - syslog (LOG_ERR, "plugin_register_read: malloc failed: %s", + ERROR ("plugin_register_read: malloc failed: %s", strerror (errno)); return (-1); } @@ -340,7 +339,7 @@ void plugin_init_all (void) if (status != 0) { - syslog (LOG_ERR, "Initialization of plugin `%s' " + ERROR ("Initialization of plugin `%s' " "failed with status %i. " "Plugin will be unloaded. TODO!", le->key, status); @@ -384,7 +383,7 @@ void plugin_read_all (const int *loop) if (rf->wait_time > 86400) rf->wait_time = 86400; - syslog (LOG_NOTICE, "read-function of plugin `%s' " + NOTICE ("read-function of plugin `%s' " "failed. Will syspend it for %i " "seconds.", le->key, rf->wait_left); } @@ -428,13 +427,13 @@ int plugin_dispatch_values (const char *name, const value_list_t *vl) le = llist_search (list_data_set, name); if (le == NULL) { - DBG ("No such dataset registered: %s", name); + DEBUG ("No such dataset registered: %s", name); return (-1); } ds = (data_set_t *) le->value; - DBG ("time = %u; host = %s; " + DEBUG ("time = %u; host = %s; " "plugin = %s; plugin_instance = %s; " "type = %s; type_instance = %s;", (unsigned int) vl->time, vl->host, @@ -511,7 +510,7 @@ void plugin_complain (int level, complain_t *c, const char *format, ...) message[511] = '\0'; va_end (ap); - syslog (level, message); + plugin_log (level, message); } void plugin_relief (int level, complain_t *c, const char *format, ...) @@ -529,5 +528,5 @@ void plugin_relief (int level, complain_t *c, const char *format, ...) message[511] = '\0'; va_end (ap); - syslog (level, message); + plugin_log (level, message); } diff --git a/src/processes.c b/src/processes.c index 37d0a75e..e5c25126 100644 --- a/src/processes.c +++ b/src/processes.c @@ -25,7 +25,6 @@ #include "collectd.h" #include "common.h" #include "plugin.h" -#include "utils_debug.h" #include "configfile.h" /* Include header files for the mach system, if they exist.. */ @@ -388,7 +387,7 @@ static void ps_list_reset (void) { if (pse->age > 10) { - DBG ("Removing this procstat entry cause it's too old: " + DEBUG ("Removing this procstat entry cause it's too old: " "id = %lu; name = %s;", pse->id, ps->name); @@ -451,7 +450,7 @@ static int ps_init (void) &pset_list, &pset_list_len)) != KERN_SUCCESS) { - syslog (LOG_ERR, "host_processor_sets failed: %s\n", + ERROR ("host_processor_sets failed: %s\n", mach_error_string (status)); pset_list = NULL; pset_list_len = 0; @@ -461,7 +460,7 @@ static int ps_init (void) #elif KERNEL_LINUX pagesize_g = sysconf(_SC_PAGESIZE); - DBG ("pagesize_g = %li; CONFIG_HZ = %i;", + DEBUG ("pagesize_g = %li; CONFIG_HZ = %i;", pagesize_g, CONFIG_HZ); #endif /* KERNEL_LINUX */ @@ -517,7 +516,7 @@ static void ps_submit_proc_list (procstat_t *ps) vl.values_len = 2; plugin_dispatch_values ("ps_pagefaults", &vl); - DBG ("name = %s; num_proc = %lu; num_lwp = %lu; vmem_rss = %lu; " + DEBUG ("name = %s; num_proc = %lu; num_lwp = %lu; vmem_rss = %lu; " "vmem_minflt_counter = %lu; vmem_majflt_counter = %lu; " "cpu_user_counter = %lu; cpu_system_counter = %lu;", ps->name, ps->num_proc, ps->num_lwp, ps->vmem_rss, @@ -541,7 +540,7 @@ static int *ps_read_tasks (int pid) if ((dh = opendir (dirname)) == NULL) { - DBG ("Failed to open directory `%s'", dirname); + DEBUG ("Failed to open directory `%s'", dirname); return (NULL); } @@ -561,7 +560,7 @@ static int *ps_read_tasks (int pid) { if (list != NULL) free (list); - syslog (LOG_ERR, "processes plugin: " + ERROR ("processes plugin: " "Failed to allocate more memory."); return (NULL); } @@ -623,20 +622,20 @@ int ps_read_process (int pid, procstat_t *ps, char *state) fields_len = strsplit (buffer, fields, 64); if (fields_len < 24) { - DBG ("`%s' has only %i fields..", + DEBUG ("`%s' has only %i fields..", filename, fields_len); return (-1); } else if (fields_len != 41) { - DBG ("WARNING: (fields_len = %i) != 41", fields_len); + DEBUG ("WARNING: (fields_len = %i) != 41", fields_len); } /* copy the name, strip brackets in the process */ name_len = strlen (fields[1]) - 2; if ((fields[1][0] != '(') || (fields[1][name_len + 1] != ')')) { - DBG ("No brackets found in process name: `%s'", fields[1]); + DEBUG ("No brackets found in process name: `%s'", fields[1]); return (-1); } fields[1] = fields[1] + 1; @@ -648,7 +647,7 @@ int ps_read_process (int pid, procstat_t *ps, char *state) if ((tasks = ps_read_tasks (pid)) == NULL) { /* This happends for zombied, e.g. */ - DBG ("ps_read_tasks (%i) failed.", pid); + DEBUG ("ps_read_tasks (%i) failed.", pid); *state = 'Z'; ps->num_lwp = 0; ps->num_proc = 0; @@ -668,7 +667,7 @@ int ps_read_process (int pid, procstat_t *ps, char *state) /* Leave the rest at zero if this is only an LWP */ if (ps->num_proc == 0) { - DBG ("This is only an LWP: pid = %i; name = %s;", + DEBUG ("This is only an LWP: pid = %i; name = %s;", pid, ps->name); return (0); } @@ -721,7 +720,7 @@ static int mach_get_task_name (task_t t, int *pid, char *name, size_t name_max_l strncpy (name, kp.kp_proc.p_comm, name_max_len - 1); name[name_max_len - 1] = '\0'; - DBG ("pid = %i; name = %s;", *pid, name); + DEBUG ("pid = %i; name = %s;", *pid, name); /* We don't do the special handling for `p_comm == "LaunchCFMApp"' as * `top' does it, because it is a lot of work and only used when @@ -777,7 +776,7 @@ static int ps_read (void) pset_list[pset], &port_pset_priv)) != KERN_SUCCESS) { - syslog (LOG_ERR, "host_processor_set_priv failed: %s\n", + ERROR ("host_processor_set_priv failed: %s\n", mach_error_string (status)); continue; } @@ -786,7 +785,7 @@ static int ps_read (void) &task_list, &task_list_len)) != KERN_SUCCESS) { - syslog (LOG_ERR, "processor_set_tasks failed: %s\n", + ERROR ("processor_set_tasks failed: %s\n", mach_error_string (status)); mach_port_deallocate (port_task_self, port_pset_priv); continue; @@ -820,7 +819,7 @@ static int ps_read (void) &task_basic_info_len); if (status != KERN_SUCCESS) { - syslog (LOG_ERR, "task_info failed: %s", + ERROR ("task_info failed: %s", mach_error_string (status)); continue; /* with next thread_list */ } @@ -832,7 +831,7 @@ static int ps_read (void) &task_events_info_len); if (status != KERN_SUCCESS) { - syslog (LOG_ERR, "task_info failed: %s", + ERROR ("task_info failed: %s", mach_error_string (status)); continue; /* with next thread_list */ } @@ -844,7 +843,7 @@ static int ps_read (void) &task_absolutetime_info_len); if (status != KERN_SUCCESS) { - syslog (LOG_ERR, "task_info failed: %s", + ERROR ("task_info failed: %s", mach_error_string (status)); continue; /* with next thread_list */ } @@ -868,7 +867,7 @@ static int ps_read (void) * thread is nonsense, since the task/process * is dead. */ zombies++; - DBG ("task_threads failed: %s", + DEBUG ("task_threads failed: %s", mach_error_string (status)); if (task_list[task] != port_task_self) mach_port_deallocate (port_task_self, @@ -885,7 +884,7 @@ static int ps_read (void) &thread_data_len); if (status != KERN_SUCCESS) { - syslog (LOG_ERR, "thread_info failed: %s", + ERROR ("thread_info failed: %s", mach_error_string (status)); if (task_list[task] != port_task_self) mach_port_deallocate (port_task_self, @@ -917,8 +916,7 @@ static int ps_read (void) * There's only zombie tasks, which are * handled above. */ default: - syslog (LOG_WARNING, - "Unknown thread status: %s", + WARNING ("Unknown thread status: %s", thread_data.run_state); break; } /* switch (thread_data.run_state) */ @@ -928,7 +926,7 @@ static int ps_read (void) status = mach_port_deallocate (port_task_self, thread_list[thread]); if (status != KERN_SUCCESS) - syslog (LOG_ERR, "mach_port_deallocate failed: %s", + ERROR ("mach_port_deallocate failed: %s", mach_error_string (status)); } } /* for (thread_list) */ @@ -938,7 +936,7 @@ static int ps_read (void) thread_list_len * sizeof (thread_act_t))) != KERN_SUCCESS) { - syslog (LOG_ERR, "vm_deallocate failed: %s", + ERROR ("vm_deallocate failed: %s", mach_error_string (status)); } thread_list = NULL; @@ -952,7 +950,7 @@ static int ps_read (void) status = mach_port_deallocate (port_task_self, task_list[task]); if (status != KERN_SUCCESS) - syslog (LOG_ERR, "mach_port_deallocate failed: %s", + ERROR ("mach_port_deallocate failed: %s", mach_error_string (status)); } @@ -964,7 +962,7 @@ static int ps_read (void) (vm_address_t) task_list, task_list_len * sizeof (task_t))) != KERN_SUCCESS) { - syslog (LOG_ERR, "vm_deallocate failed: %s", + ERROR ("vm_deallocate failed: %s", mach_error_string (status)); } task_list = NULL; @@ -973,7 +971,7 @@ static int ps_read (void) if ((status = mach_port_deallocate (port_task_self, port_pset_priv)) != KERN_SUCCESS) { - syslog (LOG_ERR, "mach_port_deallocate failed: %s", + ERROR ("mach_port_deallocate failed: %s", mach_error_string (status)); } } /* for (pset_list) */ @@ -1012,7 +1010,7 @@ static int ps_read (void) if ((proc = opendir ("/proc")) == NULL) { - syslog (LOG_ERR, "Cannot open `/proc': %s", strerror (errno)); + ERROR ("Cannot open `/proc': %s", strerror (errno)); return (-1); } @@ -1027,7 +1025,7 @@ static int ps_read (void) status = ps_read_process (pid, &ps, &state); if (status != 0) { - DBG ("ps_read_process failed: %i", status); + DEBUG ("ps_read_process failed: %i", status); continue; } diff --git a/src/rrdtool.c b/src/rrdtool.c index f19f2693..ec04642c 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -23,7 +23,6 @@ #include "plugin.h" #include "common.h" #include "utils_avltree.h" -#include "utils_debug.h" /* * Private types @@ -140,7 +139,7 @@ static int rra_get (char ***ret) rra_types[j], xff, cdp_len, cdp_num) >= sizeof (buffer)) { - syslog (LOG_ERR, "rra_get: Buffer would have been truncated."); + ERROR ("rra_get: Buffer would have been truncated."); continue; } @@ -149,9 +148,9 @@ static int rra_get (char ***ret) } #if COLLECT_DEBUG - DBG ("rra_num = %i", rra_num); + DEBUG ("rra_num = %i", rra_num); for (i = 0; i < rra_num; i++) - DBG (" %s", rra_def[i]); + DEBUG (" %s", rra_def[i]); #endif *ret = rra_def; @@ -177,12 +176,12 @@ static int ds_get (char ***ret, const data_set_t *ds) char max[32]; char buffer[128]; - DBG ("ds->ds_num = %i", ds->ds_num); + DEBUG ("ds->ds_num = %i", ds->ds_num); ds_def = (char **) malloc (ds->ds_num * sizeof (char *)); if (ds_def == NULL) { - syslog (LOG_ERR, "rrdtool plugin: malloc failed: %s", + ERROR ("rrdtool plugin: malloc failed: %s", strerror (errno)); return (-1); } @@ -202,7 +201,7 @@ static int ds_get (char ***ret, const data_set_t *ds) type = "GAUGE"; else { - syslog (LOG_ERR, "rrdtool plugin: Unknown DS type: %i", + ERROR ("rrdtool plugin: Unknown DS type: %i", d->type); break; } @@ -240,9 +239,9 @@ static int ds_get (char ***ret, const data_set_t *ds) #if COLLECT_DEBUG { int i; - DBG ("ds_num = %i", ds_num); + DEBUG ("ds_num = %i", ds_num); for (i = 0; i < ds_num; i++) - DBG (" %s", ds_def[i]); + DEBUG (" %s", ds_def[i]); } #endif @@ -273,13 +272,13 @@ static int rrd_create_file (char *filename, const data_set_t *ds) if ((rra_num = rra_get (&rra_def)) < 1) { - syslog (LOG_ERR, "rrd_create_file failed: Could not calculate RRAs"); + ERROR ("rrd_create_file failed: Could not calculate RRAs"); return (-1); } if ((ds_num = ds_get (&ds_def, ds)) < 1) { - syslog (LOG_ERR, "rrd_create_file failed: Could not calculate DSes"); + ERROR ("rrd_create_file failed: Could not calculate DSes"); return (-1); } @@ -287,7 +286,7 @@ static int rrd_create_file (char *filename, const data_set_t *ds) if ((argv = (char **) malloc (sizeof (char *) * (argc + 1))) == NULL) { - syslog (LOG_ERR, "rrd_create failed: %s", strerror (errno)); + ERROR ("rrd_create failed: %s", strerror (errno)); return (-1); } @@ -295,7 +294,7 @@ static int rrd_create_file (char *filename, const data_set_t *ds) "%i", stepsize); if ((status < 1) || (status >= sizeof (stepsize_str))) { - syslog (LOG_ERR, "rrdtool plugin: snprintf failed."); + ERROR ("rrdtool plugin: snprintf failed."); return (-1); } @@ -315,7 +314,7 @@ static int rrd_create_file (char *filename, const data_set_t *ds) rrd_clear_error (); if (rrd_create (argc, argv) == -1) { - syslog (LOG_ERR, "rrd_create failed: %s: %s", filename, rrd_get_error ()); + ERROR ("rrd_create failed: %s: %s", filename, rrd_get_error ()); status = -1; } @@ -429,7 +428,7 @@ static rrd_cache_t *rrd_cache_insert (const char *filename, (rc->values_num + 1) * sizeof (char *)); if (rc->values == NULL) { - syslog (LOG_ERR, "rrdtool plugin: realloc failed: %s", + ERROR ("rrdtool plugin: realloc failed: %s", strerror (errno)); if (cache != NULL) { @@ -455,7 +454,7 @@ static rrd_cache_t *rrd_cache_insert (const char *filename, if (cache_key == NULL) { - syslog (LOG_ERR, "rrdtool plugin: strdup failed: %s", + ERROR ("rrdtool plugin: strdup failed: %s", strerror (errno)); sfree (rc->values[0]); sfree (rc->values); @@ -466,7 +465,7 @@ static rrd_cache_t *rrd_cache_insert (const char *filename, avl_insert (cache, cache_key, rc); } - DBG ("rrd_cache_insert (%s, %s) = %p", filename, value, (void *) rc); + DEBUG ("rrd_cache_insert (%s, %s) = %p", filename, value, (void *) rc); return (rc); } /* rrd_cache_t *rrd_cache_insert */ @@ -498,7 +497,7 @@ static int rrd_write_cache_entry (const char *filename, rrd_cache_t *rc) memcpy (argv + 2, rc->values, rc->values_num * sizeof (char *)); argv[argc] = NULL; - DBG ("rrd_update (argc = %i, argv = %p)", argc, (void *) argv); + DEBUG ("rrd_update (argc = %i, argv = %p)", argc, (void *) argv); optind = 0; /* bug in librrd? */ rrd_clear_error (); @@ -516,7 +515,7 @@ static int rrd_write_cache_entry (const char *filename, rrd_cache_t *rc) if (status != 0) { - syslog (LOG_WARNING, "rrd_update failed: %s: %s", + WARNING ("rrd_update failed: %s: %s", filename, rrd_get_error ()); return (-1); } @@ -539,7 +538,7 @@ static void rrd_cache_flush (int timeout) if (cache == NULL) return; - DBG ("Flushing cache, timeout = %i", timeout); + DEBUG ("Flushing cache, timeout = %i", timeout); now = time (NULL); @@ -547,15 +546,15 @@ static void rrd_cache_flush (int timeout) iter = avl_get_iterator (cache); while (avl_iterator_next (iter, (void *) &key, (void *) &rc) == 0) { - DBG ("key = %s; age = %i;", key, now - rc->first_value); + DEBUG ("key = %s; age = %i;", key, now - rc->first_value); if ((now - rc->first_value) >= timeout) { keys = (char **) realloc ((void *) keys, (keys_num + 1) * sizeof (char *)); if (keys == NULL) { - DBG ("realloc failed: %s", strerror (errno)); - syslog (LOG_ERR, "rrdtool plugin: " + DEBUG ("realloc failed: %s", strerror (errno)); + ERROR ("rrdtool plugin: " "realloc failed: %s", strerror (errno)); avl_iterator_destroy (iter); @@ -571,7 +570,7 @@ static void rrd_cache_flush (int timeout) { if (avl_remove (cache, keys[i], (void *) &key, (void *) &rc) != 0) { - DBG ("avl_remove (%s) failed.", keys[i]); + DEBUG ("avl_remove (%s) failed.", keys[i]); continue; } @@ -583,7 +582,7 @@ static void rrd_cache_flush (int timeout) } /* for (i = 0..keys_num) */ free (keys); - DBG ("Flushed %i value(s)", keys_num); + DEBUG ("Flushed %i value(s)", keys_num); cache_flush_last = now; } /* void rrd_cache_flush */ @@ -611,14 +610,14 @@ static int rrd_write (const data_set_t *ds, const value_list_t *vl) } else { - syslog (LOG_ERR, "stat(%s) failed: %s", + ERROR ("stat(%s) failed: %s", filename, strerror (errno)); return (-1); } } else if (!S_ISREG (statbuf.st_mode)) { - syslog (LOG_ERR, "stat(%s): Not a regular file!", + ERROR ("stat(%s): Not a regular file!", filename); return (-1); } @@ -637,7 +636,7 @@ static int rrd_write (const data_set_t *ds, const value_list_t *vl) now = time (NULL); - DBG ("age (%s) = %i", filename, now - rc->first_value); + DEBUG ("age (%s) = %i", filename, now - rc->first_value); /* `rc' is not free'd here, because we'll likely reuse it. If not, then * the next flush will remove this entry. */ @@ -763,11 +762,11 @@ static int rrd_init (void) heartbeat = 2 * interval_g; if (heartbeat < interval_g) - syslog (LOG_WARNING, "rrdtool plugin: Your `heartbeat' is " + WARNING ("rrdtool plugin: Your `heartbeat' is " "smaller than your `interval'. This will " "likely cause problems."); else if (stepsize < interval_g) - syslog (LOG_WARNING, "rrdtool plugin: Your `stepsize' is " + WARNING ("rrdtool plugin: Your `stepsize' is " "smaller than your `interval'. This will " "create needlessly big RRD-files."); @@ -786,7 +785,7 @@ static int rrd_init (void) plugin_register_shutdown ("rrdtool", rrd_shutdown); } - DBG ("datadir = %s; stepsize = %i; heartbeat = %i; rrarows = %i; xff = %lf;", + DEBUG ("datadir = %s; stepsize = %i; heartbeat = %i; rrarows = %i; xff = %lf;", (datadir == NULL) ? "(null)" : datadir, stepsize, heartbeat, rrarows, xff); diff --git a/src/sensors.c b/src/sensors.c index b1454a6e..4bb544d5 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -33,7 +33,6 @@ #include "plugin.h" #include "configfile.h" #include "utils_ignorelist.h" -#include "utils_debug.h" #if defined(HAVE_SENSORS_SENSORS_H) # include @@ -200,7 +199,7 @@ static int sensors_config (const char *key, const char *value) { if (ignorelist_add (sensor_list, value)) { - syslog (LOG_ERR, "sensors plugin: " + ERROR ("sensors plugin: " "Cannot add value to ignorelist."); return (1); } @@ -257,7 +256,7 @@ static void sensors_load_conf (void) status = stat (conffile, &statbuf); if (status != 0) { - syslog (LOG_ERR, "sensors plugin: stat (%s) failed: %s", + ERROR ("sensors plugin: stat (%s) failed: %s", conffile, strerror (errno)); sensors_config_mtime = 0; } @@ -268,7 +267,7 @@ static void sensors_load_conf (void) if (sensors_config_mtime != 0) { - syslog (LOG_NOTICE, "sensors plugin: Reloading config from %s", + NOTICE ("sensors plugin: Reloading config from %s", conffile); sensors_free_features (); sensors_config_mtime = 0; @@ -277,7 +276,7 @@ static void sensors_load_conf (void) fh = fopen (conffile, "r"); if (fh == NULL) { - syslog (LOG_ERR, "sensors plugin: fopen(%s) failed: %s", + ERROR ("sensors plugin: fopen(%s) failed: %s", conffile, strerror(errno)); return; } @@ -286,7 +285,7 @@ static void sensors_load_conf (void) fclose (fh); if (status != 0) { - syslog (LOG_ERR, "sensors plugin: Cannot initialize sensors. " + ERROR ("sensors plugin: Cannot initialize sensors. " "Data will not be collected."); return; } @@ -318,15 +317,15 @@ static void sensors_load_conf (void) if (sensors_get_ignored (*chip, data->number) == 0) break; - DBG ("Adding feature: %s-%s-%s", + DEBUG ("Adding feature: %s-%s-%s", chip->prefix, sensor_to_type[known_features[i].type], data->name); if ((new_feature = (featurelist_t *) malloc (sizeof (featurelist_t))) == NULL) { - DBG ("malloc: %s", strerror (errno)); - syslog (LOG_ERR, "sensors plugin: malloc: %s", + DEBUG ("malloc: %s", strerror (errno)); + ERROR ("sensors plugin: malloc: %s", strerror (errno)); break; } @@ -356,7 +355,7 @@ static void sensors_load_conf (void) if (first_feature == NULL) { sensors_cleanup (); - syslog (LOG_INFO, "sensors plugin: lm_sensors reports no " + INFO ("sensors plugin: lm_sensors reports no " "features. Data will not be collected."); } } /* void sensors_load_conf */ diff --git a/src/serial.c b/src/serial.c index 8f8e433b..0cfa3823 100644 --- a/src/serial.c +++ b/src/serial.c @@ -80,7 +80,7 @@ static int serial_read (void) if ((fh = fopen ("/proc/tty/driver/serial", "r")) == NULL && (fh = fopen ("/proc/tty/driver/ttyS", "r")) == NULL) { - syslog (LOG_WARNING, "serial: fopen: %s", strerror (errno)); + WARNING ("serial: fopen: %s", strerror (errno)); return (-1); } diff --git a/src/swap.c b/src/swap.c index 8e040443..945c7580 100644 --- a/src/swap.c +++ b/src/swap.c @@ -111,7 +111,7 @@ static int swap_init (void) NULL)) /* errstr */ == NULL) { - syslog (LOG_ERR, "swap plugin: kvm_open failed."); + ERROR ("swap plugin: kvm_open failed."); return (-1); } /* #endif HAVE_LIBKVM */ @@ -156,7 +156,7 @@ static int swap_read (void) if ((fh = fopen ("/proc/meminfo", "r")) == NULL) { - syslog (LOG_WARNING, "memory: fopen: %s", strerror (errno)); + WARNING ("memory: fopen: %s", strerror (errno)); return (-1); } @@ -182,7 +182,7 @@ static int swap_read (void) } if (fclose (fh)) - syslog (LOG_WARNING, "memory: fclose: %s", strerror (errno)); + WARNING ("memory: fclose: %s", strerror (errno)); if ((swap_total == 0LL) || ((swap_free + swap_cached) > swap_total)) return (-1); @@ -203,7 +203,7 @@ static int swap_read (void) if (swapctl (SC_AINFO, &ai) == -1) { - syslog (LOG_ERR, "swap plugin: swapctl failed: %s", + ERROR ("swap plugin: swapctl failed: %s", strerror (errno)); return (-1); } diff --git a/src/traffic.c b/src/traffic.c index 619208c8..7f624502 100644 --- a/src/traffic.c +++ b/src/traffic.c @@ -134,14 +134,14 @@ static int interface_config (const char *key, const char *value) temp = (char **) realloc (if_list, (if_list_num + 1) * sizeof (char *)); if (temp == NULL) { - syslog (LOG_EMERG, "Cannot allocate more memory."); + ERROR ("Cannot allocate more memory."); return (1); } if_list = temp; if ((if_list[if_list_num] = strdup (value)) == NULL) { - syslog (LOG_EMERG, "Cannot allocate memory."); + ERROR ("Cannot allocate memory."); return (1); } if_list_num++; @@ -304,7 +304,7 @@ static int traffic_read (void) if ((fh = fopen ("/proc/net/dev", "r")) == NULL) { - syslog (LOG_WARNING, "traffic: fopen: %s", strerror (errno)); + WARNING ("traffic: fopen: %s", strerror (errno)); return (-1); } diff --git a/src/unixsock.c b/src/unixsock.c index 0008b224..17956a17 100644 --- a/src/unixsock.c +++ b/src/unixsock.c @@ -23,7 +23,6 @@ #include "common.h" #include "plugin.h" #include "configfile.h" -#include "utils_debug.h" /* Folks without pthread will need to disable this plugin. */ #include @@ -137,7 +136,7 @@ static int cache_insert (const data_set_t *ds, const value_list_t *vl) value_cache_t *vc; int i; - DBG ("ds->ds_num = %i; vl->values_len = %i;", + DEBUG ("ds->ds_num = %i; vl->values_len = %i;", ds->ds_num, vl->values_len); assert (ds->ds_num == vl->values_len); @@ -145,7 +144,7 @@ static int cache_insert (const data_set_t *ds, const value_list_t *vl) if (vc == NULL) { pthread_mutex_unlock (&cache_lock); - syslog (LOG_ERR, "unixsock plugin: malloc failed: %s", + ERROR ("unixsock plugin: malloc failed: %s", strerror (errno)); return (-1); } @@ -154,7 +153,7 @@ static int cache_insert (const data_set_t *ds, const value_list_t *vl) if (vc->gauge == NULL) { pthread_mutex_unlock (&cache_lock); - syslog (LOG_ERR, "unixsock plugin: malloc failed: %s", + ERROR ("unixsock plugin: malloc failed: %s", strerror (errno)); free (vc); return (-1); @@ -164,7 +163,7 @@ static int cache_insert (const data_set_t *ds, const value_list_t *vl) if (vc->counter == NULL) { pthread_mutex_unlock (&cache_lock); - syslog (LOG_ERR, "unixsock plugin: malloc failed: %s", + ERROR ("unixsock plugin: malloc failed: %s", strerror (errno)); free (vc->gauge); free (vc); @@ -176,7 +175,7 @@ static int cache_insert (const data_set_t *ds, const value_list_t *vl) ds->type, vl->type_instance) != 0) { pthread_mutex_unlock (&cache_lock); - syslog (LOG_ERR, "unixsock plugin: cache_alloc_name failed."); + ERROR ("unixsock plugin: cache_alloc_name failed."); free (vc->counter); free (vc->gauge); free (vc); @@ -352,7 +351,7 @@ static int us_open_socket (void) sock_fd = socket (PF_UNIX, SOCK_STREAM, 0); if (sock_fd < 0) { - syslog (LOG_ERR, "unixsock plugin: socket failed: %s", + ERROR ("unixsock plugin: socket failed: %s", strerror (errno)); return (-1); } @@ -366,9 +365,9 @@ static int us_open_socket (void) status = bind (sock_fd, (struct sockaddr *) &sa, sizeof (sa)); if (status != 0) { - DBG ("bind failed: %s; sa.sun_path = %s", + DEBUG ("bind failed: %s; sa.sun_path = %s", strerror (errno), sa.sun_path); - syslog (LOG_ERR, "unixsock plugin: bind failed: %s", + ERROR ("unixsock plugin: bind failed: %s", strerror (errno)); close (sock_fd); sock_fd = -1; @@ -378,7 +377,7 @@ static int us_open_socket (void) status = listen (sock_fd, 8); if (status != 0) { - syslog (LOG_ERR, "unixsock plugin: listen failed: %s", + ERROR ("unixsock plugin: listen failed: %s", strerror (errno)); close (sock_fd); sock_fd = -1; @@ -398,13 +397,13 @@ static int us_open_socket (void) status = getgrnam_r (grpname, &sg, grbuf, sizeof (grbuf), &g); if (status != 0) { - syslog (LOG_WARNING, "unixsock plugin: getgrnam_r (%s) failed: %s", + WARNING ("unixsock plugin: getgrnam_r (%s) failed: %s", grpname, strerror (status)); break; } if (g == NULL) { - syslog (LOG_WARNING, "unixsock plugin: No such group: `%s'", + WARNING ("unixsock plugin: No such group: `%s'", grpname); break; } @@ -412,7 +411,7 @@ static int us_open_socket (void) if (chown ((sock_file != NULL) ? sock_file : US_DEFAULT_PATH, (uid_t) -1, g->gr_gid) != 0) { - syslog (LOG_WARNING, "unixsock plugin: chown (%s, -1, %i) failed: %s", + WARNING ("unixsock plugin: chown (%s, -1, %i) failed: %s", (sock_file != NULL) ? sock_file : US_DEFAULT_PATH, (int) g->gr_gid, strerror (errno)); @@ -468,17 +467,17 @@ static int us_handle_getval (FILE *fh, char **fields, int fields_num) pthread_mutex_lock (&cache_lock); - DBG ("vc = cache_search (%s)", name); + DEBUG ("vc = cache_search (%s)", name); vc = cache_search (name); if (vc == NULL) { - DBG ("Did not find cache entry."); + DEBUG ("Did not find cache entry."); fprintf (fh, "-1 No such value"); } else { - DBG ("Found cache entry."); + DEBUG ("Found cache entry."); fprintf (fh, "%i", vc->values_num); for (i = 0; i < vc->values_num; i++) { @@ -511,12 +510,12 @@ static void *us_handle_client (void *arg) free (arg); arg = NULL; - DBG ("Reading from fd #%i", fd); + DEBUG ("Reading from fd #%i", fd); fh = fdopen (fd, "r+"); if (fh == NULL) { - syslog (LOG_ERR, "unixsock plugin: fdopen failed: %s", + ERROR ("unixsock plugin: fdopen failed: %s", strerror (errno)); close (fd); pthread_exit ((void *) 1); @@ -534,7 +533,7 @@ static void *us_handle_client (void *arg) if (len == 0) continue; - DBG ("fgets -> buffer = %s; len = %i;", buffer, len); + DEBUG ("fgets -> buffer = %s; len = %i;", buffer, len); fields_num = strsplit (buffer, fields, sizeof (fields) / sizeof (fields[0])); @@ -556,7 +555,7 @@ static void *us_handle_client (void *arg) } } /* while (fgets) */ - DBG ("Exiting.."); + DEBUG ("Exiting.."); close (fd); pthread_exit ((void *) 0); @@ -574,14 +573,14 @@ static void *us_server_thread (void *arg) while (42) { - DBG ("Calling accept.."); + DEBUG ("Calling accept.."); status = accept (sock_fd, NULL, NULL); if (status < 0) { if (errno == EINTR) continue; - syslog (LOG_ERR, "unixsock plugin: accept failed: %s", + ERROR ("unixsock plugin: accept failed: %s", strerror (errno)); close (sock_fd); sock_fd = -1; @@ -591,14 +590,14 @@ static void *us_server_thread (void *arg) remote_fd = (int *) malloc (sizeof (int)); if (remote_fd == NULL) { - syslog (LOG_WARNING, "unixsock plugin: malloc failed: %s", + WARNING ("unixsock plugin: malloc failed: %s", strerror (errno)); close (status); continue; } *remote_fd = status; - DBG ("Spawning child to handle connection on fd #%i", *remote_fd); + DEBUG ("Spawning child to handle connection on fd #%i", *remote_fd); pthread_attr_init (&th_attr); pthread_attr_setdetachstate (&th_attr, PTHREAD_CREATE_DETACHED); @@ -606,7 +605,7 @@ static void *us_server_thread (void *arg) status = pthread_create (&th, &th_attr, us_handle_client, (void *) remote_fd); if (status != 0) { - syslog (LOG_WARNING, "unixsock plugin: pthread_create failed: %s", + WARNING ("unixsock plugin: pthread_create failed: %s", strerror (status)); close (*remote_fd); free (remote_fd); @@ -648,7 +647,7 @@ static int us_init (void) status = pthread_create (&listen_thread, NULL, us_server_thread, NULL); if (status != 0) { - syslog (LOG_ERR, "unixsock plugin: pthread_create failed: %s", + ERROR ("unixsock plugin: pthread_create failed: %s", strerror (status)); return (-1); } diff --git a/src/utils_debug.c b/src/utils_debug.c index 9fc9040b..cc5ca8e5 100644 --- a/src/utils_debug.c +++ b/src/utils_debug.c @@ -73,7 +73,7 @@ cu_debug_startfile(const char *file, int line, const char *func, va_list ap; if(cu_debug_file != NULL) { - DBG("Don't call this function more then once without" + DBG ("Don't call this function more then once without" " calling cu_debug_stopfile()."); return EXIT_FAILURE; } @@ -84,7 +84,7 @@ cu_debug_startfile(const char *file, int line, const char *func, cu_debug_file = fopen(cu_debug_filename, "a"); if(cu_debug_file == NULL) { - DBG("Cannot open debug file %s: %s.\n", + DEBUG("Cannot open debug file %s: %s.\n", cu_debug_filename, strerror(errno)); return EXIT_FAILURE; } @@ -108,13 +108,13 @@ cu_debug_stopfile(const char *file, int line, const char *func, va_end(ap); if(cu_debug_file == NULL) { - DBG("Don't call this function more then once or without" + DEBUG("Don't call this function more then once or without" " calling cu_debug_startfile()."); return EXIT_FAILURE; } if(fclose(cu_debug_file) != 0) { - DBG("Cannot close debug file %s: %s.\n", + DEBUG("Cannot close debug file %s: %s.\n", cu_debug_filename, strerror(errno)); return EXIT_FAILURE; } @@ -131,7 +131,7 @@ cu_debug_resetfile(const char *file, int line, const char *func, const char *filename) { if(filename == NULL) { - DBG("You have to set filename when calling this function!\n"); + DEBUG("You have to set filename when calling this function!\n"); return EXIT_FAILURE; } if(cu_debug_file != NULL) { diff --git a/src/utils_ignorelist.c b/src/utils_ignorelist.c index 532eb4b0..f71ac1d7 100644 --- a/src/utils_ignorelist.c +++ b/src/utils_ignorelist.c @@ -48,7 +48,7 @@ **/ #include "common.h" -#include "utils_debug.h" +#include "plugin.h" #include "utils_ignorelist.h" /* @@ -94,7 +94,7 @@ static int ignorelist_append_regex(ignorelist_t *il, const char *entry) /* create buffer */ if ((regtemp = malloc(sizeof(regex_t))) == NULL) { - syslog (LOG_ERR, "cannot allocate new config entry"); + ERROR ("cannot allocate new config entry"); return (1); } memset (regtemp, '\0', sizeof(regex_t)); @@ -111,14 +111,14 @@ static int ignorelist_append_regex(ignorelist_t *il, const char *entry) { fprintf (stderr, "Cannot compile regex %s: %i/%s", entry, rcompile, regerr); - syslog (LOG_ERR, "Cannot compile regex %s: %i/%s", + ERROR ("Cannot compile regex %s: %i/%s", entry, rcompile, regerr); } else { fprintf (stderr, "Cannot compile regex %s: %i", entry, rcompile); - syslog (LOG_ERR, "Cannot compile regex %s: %i", + ERROR ("Cannot compile regex %s: %i", entry, rcompile); } @@ -127,12 +127,12 @@ static int ignorelist_append_regex(ignorelist_t *il, const char *entry) regfree (regtemp); return (1); } - DBG("regex compiled: %s - %i", entry, rcompile); + DEBUG("regex compiled: %s - %i", entry, rcompile); /* create new entry */ if ((new = malloc(sizeof(ignorelist_item_t))) == NULL) { - syslog (LOG_ERR, "cannot allocate new config entry"); + ERROR ("cannot allocate new config entry"); regfree (regtemp); return (1); } @@ -153,7 +153,7 @@ static int ignorelist_append_string(ignorelist_t *il, const char *entry) /* create new entry */ if ((new = malloc(sizeof(ignorelist_item_t))) == NULL ) { - syslog (LOG_ERR, "cannot allocate new entry"); + ERROR ("cannot allocate new entry"); return (1); } memset (new, '\0', sizeof(ignorelist_item_t)); @@ -213,7 +213,7 @@ ignorelist_t *ignorelist_create (int invert) /* smalloc exits if it failes */ il = (ignorelist_t *) smalloc (sizeof (ignorelist_t)); - DBG("Ignorelist created 0x%p, default is %s", + DEBUG("Ignorelist created 0x%p, default is %s", (void *) il, invert ? "collect" : "ignore"); @@ -236,7 +236,7 @@ void ignorelist_free (ignorelist_t *il) ignorelist_item_t *this; ignorelist_item_t *next; - DBG ("(il = 0x%p)", (void *) il); + DEBUG ("(il = 0x%p)", (void *) il); if (il == NULL) return; @@ -270,7 +270,7 @@ void ignorelist_set_invert (ignorelist_t *il, int invert) { if (il == NULL) { - DBG("ignore call with ignorelist_t == NULL"); + DEBUG("ignore call with ignorelist_t == NULL"); return; } @@ -288,7 +288,7 @@ int ignorelist_add (ignorelist_t *il, const char *entry) if (il == NULL) { - DBG ("add called with ignorelist_t == NULL"); + DEBUG ("add called with ignorelist_t == NULL"); return (1); } @@ -297,7 +297,7 @@ int ignorelist_add (ignorelist_t *il, const char *entry) /* append nothing */ if (entry_len == 0) { - DBG("not appending: empty entry"); + DEBUG("not appending: empty entry"); return (1); } @@ -312,14 +312,14 @@ int ignorelist_add (ignorelist_t *il, const char *entry) memset (entry_copy, '\0', entry_len); strncpy (entry_copy, entry + 1, entry_len - 2); - DBG("I'm about to add regex entry: %s", entry_copy); + DEBUG("I'm about to add regex entry: %s", entry_copy); ret = ignorelist_append_regex(il, entry_copy); sfree (entry_copy); } else #endif { - DBG("to add entry: %s", entry); + DEBUG("to add entry: %s", entry); ret = ignorelist_append_string(il, entry); } diff --git a/src/utils_mount.c b/src/utils_mount.c index 7748c610..61eb6d1c 100644 --- a/src/utils_mount.c +++ b/src/utils_mount.c @@ -30,7 +30,7 @@ #define XFS_SUPER_MAGIC2_STR "BSFX" #endif -#include "utils_debug.h" +#include "plugin.h" #include "utils_mount.h" #if HAVE_GETVFSSTAT @@ -332,7 +332,7 @@ get_spec_by_uuid(const char *s) return get_spec_by_x(UUID, uuid); bad_uuid: - DBG("Found an invalid UUID: %s", s); + DEBUG("Found an invalid UUID: %s", s); return NULL; } @@ -351,12 +351,12 @@ static char *get_device_name(const char *optstr) } else if (strncmp (optstr, "UUID=", 5) == 0) { - DBG ("TODO: check UUID= code!"); + DEBUG ("TODO: check UUID= code!"); rc = get_spec_by_uuid (optstr + 5); } else if (strncmp (optstr, "LABEL=", 6) == 0) { - DBG ("TODO: check LABEL= code!"); + DEBUG ("TODO: check LABEL= code!"); rc = get_spec_by_volume_label (optstr + 6); } else @@ -366,7 +366,7 @@ static char *get_device_name(const char *optstr) if(!rc) { - DBG ("Error checking device name: optstr = %s", optstr); + DEBUG ("Error checking device name: optstr = %s", optstr); } return rc; } @@ -381,7 +381,7 @@ static cu_mount_t *cu_mount_listmntent (void) struct tabmntent *mntlist; if(listmntent(&mntlist, COLLECTD_MNTTAB, NULL, NULL) < 0) { - DBG("calling listmntent() failed: %s", strerror(errno)); + DEBUG("calling listmntent() failed: %s", strerror(errno)); } for(p = mntlist; p; p = p->next) { @@ -392,7 +392,7 @@ static cu_mount_t *cu_mount_listmntent (void) if(loop == NULL) { /* no loop= mount */ device = get_device_name(mnt->mnt_fsname); if(device == NULL) { - DBG("can't get devicename for fs (%s) %s (%s)" + DEBUG("can't get devicename for fs (%s) %s (%s)" ": ignored", mnt->mnt_type, mnt->mnt_dir, mnt->mnt_fsname); continue; @@ -450,7 +450,7 @@ static cu_mount_t *cu_mount_getfsstat (void) /* Get the number of mounted file systems */ if ((bufsize = CMD_STATFS (NULL, 0, FLAGS_STATFS)) < 1) { - DBG ("getv?fsstat failed: %s", strerror (errno)); + DEBUG ("getv?fsstat failed: %s", strerror (errno)); return (NULL); } @@ -463,7 +463,7 @@ static cu_mount_t *cu_mount_getfsstat (void) * manpage.. -octo */ if ((num = CMD_STATFS (buf, bufsize * sizeof (STRUCT_STATFS), FLAGS_STATFS)) < 1) { - DBG ("getv?fsstat failed: %s", strerror (errno)); + DEBUG ("getv?fsstat failed: %s", strerror (errno)); free (buf); return (NULL); } @@ -512,11 +512,11 @@ static cu_mount_t *cu_mount_gen_getmntent (void) cu_mount_t *last = NULL; cu_mount_t *new = NULL; - DBG ("(void); COLLECTD_MNTTAB = %s", COLLECTD_MNTTAB); + DEBUG ("(void); COLLECTD_MNTTAB = %s", COLLECTD_MNTTAB); if ((fp = fopen (COLLECTD_MNTTAB, "r")) == NULL) { - syslog (LOG_ERR, "fopen (%s): %s", COLLECTD_MNTTAB, strerror (errno)); + ERROR ("fopen (%s): %s", COLLECTD_MNTTAB, strerror (errno)); return (NULL); } @@ -567,11 +567,11 @@ static cu_mount_t *cu_mount_getmntent (void) cu_mount_t *last = NULL; cu_mount_t *new = NULL; - DBG ("(void); COLLECTD_MNTTAB = %s", COLLECTD_MNTTAB); + DEBUG ("(void); COLLECTD_MNTTAB = %s", COLLECTD_MNTTAB); if ((fp = setmntent (COLLECTD_MNTTAB, "r")) == NULL) { - syslog (LOG_ERR, "setmntent (%s): %s", COLLECTD_MNTTAB, strerror (errno)); + ERROR ("setmntent (%s): %s", COLLECTD_MNTTAB, strerror (errno)); return (NULL); } @@ -589,7 +589,7 @@ static cu_mount_t *cu_mount_getmntent (void) new->device = get_device_name (new->options); new->next = NULL; - DBG ("new = {dir = %s, spec_device = %s, type = %s, options = %s, device = %s}", + DEBUG ("new = {dir = %s, spec_device = %s, type = %s, options = %s, device = %s}", new->dir, new->spec_device, new->type, new->options, new->device); /* Append to list */ @@ -607,7 +607,7 @@ static cu_mount_t *cu_mount_getmntent (void) endmntent (fp); - DBG ("return (0x%p)", (void *) first); + DEBUG ("return (0x%p)", (void *) first); return (first); } @@ -670,7 +670,7 @@ void cu_mount_freelist (cu_mount_t *list) cu_mount_t *this; cu_mount_t *next; - DBG ("(list = 0x%p)", (void *) list); + DEBUG ("(list = 0x%p)", (void *) list); for (this = list; this != NULL; this = next) { diff --git a/src/vserver.c b/src/vserver.c index 00a1e6ad..fef45587 100644 --- a/src/vserver.c +++ b/src/vserver.c @@ -25,12 +25,7 @@ #include "plugin.h" #include -#include -#include -#include -#include #include -#include #define BUFSIZE 512 @@ -218,7 +213,7 @@ static int vserver_read (void) continue; if (NULL == (fh = fopen (file, "r"))) - syslog (LOG_ERR, "Cannot open '%s': %s", file, strerror (errno)); + ERROR ("Cannot open '%s': %s", file, strerror (errno)); while ((fh != NULL) && (NULL != fgets (buffer, BUFSIZE, fh))) { @@ -261,7 +256,7 @@ static int vserver_read (void) continue; if (NULL == (fh = fopen (file, "r"))) - syslog (LOG_ERR, "Cannot open '%s': %s", file, strerror (errno)); + ERROR ("Cannot open '%s': %s", file, strerror (errno)); while ((fh != NULL) && (NULL != fgets (buffer, BUFSIZE, fh))) { @@ -309,7 +304,7 @@ static int vserver_read (void) continue; if (NULL == (fh = fopen (file, "r"))) - syslog (LOG_ERR, "Cannot open '%s': %s", file, strerror (errno)); + ERROR ("Cannot open '%s': %s", file, strerror (errno)); while ((fh != NULL) && (NULL != fgets (buffer, BUFSIZE, fh))) { diff --git a/src/wireless.c b/src/wireless.c index 10414531..a7040475 100644 --- a/src/wireless.c +++ b/src/wireless.c @@ -112,7 +112,7 @@ static int wireless_read (void) /* there are a variety of names for the wireless device */ if ((fh = fopen (WIRELESS_PROC_FILE, "r")) == NULL) { - syslog (LOG_WARNING, "wireless: fopen: %s", strerror (errno)); + WARNING ("wireless: fopen: %s", strerror (errno)); return (-1); }