X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsensors.c;h=4b0fc3da2c695d67d0912c1b1b8d7d53097d175b;hb=0ac5ded812171ac8bec7eed1331e894a33dbe211;hp=99b925685fa755de65013176d98a6e8cdaff8926;hpb=b8be503b2b50366a9c498ba7e4ab66a228c6dfbf;p=collectd.git diff --git a/src/sensors.c b/src/sensors.c index 99b92568..4b0fc3da 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 @@ -154,9 +153,9 @@ static sensors_labeltypes_t known_features[] = { "3.3V", SENSOR_TYPE_VOLTAGE }, { "2.5V", SENSOR_TYPE_VOLTAGE }, { "2.0V", SENSOR_TYPE_VOLTAGE }, - { "12V", SENSOR_TYPE_VOLTAGE }, - { (char *) 0, SENSOR_TYPE_UNKNOWN } + { "12V", SENSOR_TYPE_VOLTAGE } }; +static int known_features_num = STATIC_ARRAY_SIZE (known_features); /* end new naming */ static const char *config_keys[] = @@ -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,8 +256,9 @@ static void sensors_load_conf (void) status = stat (conffile, &statbuf); if (status != 0) { - syslog (LOG_ERR, "sensors plugin: stat (%s) failed: %s", - conffile, strerror (errno)); + char errbuf[1024]; + ERROR ("sensors plugin: stat (%s) failed: %s", conffile, + sstrerror (errno, errbuf, sizeof (errbuf))); sensors_config_mtime = 0; } @@ -268,7 +268,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,8 +277,9 @@ static void sensors_load_conf (void) fh = fopen (conffile, "r"); if (fh == NULL) { - syslog (LOG_ERR, "sensors plugin: fopen(%s) failed: %s", - conffile, strerror(errno)); + char errbuf[1024]; + ERROR ("sensors plugin: fopen(%s) failed: %s", conffile, + sstrerror (errno, errbuf, sizeof (errbuf))); return; } @@ -286,7 +287,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; } @@ -309,7 +310,7 @@ static void sensors_load_conf (void) continue; /* Only known features */ - for (i = 0; known_features[i].type >= 0; i++) + for (i = 0; i < known_features_num; i++) { if (strcmp (data->name, known_features[i].label) != 0) continue; @@ -318,16 +319,16 @@ 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", - strerror (errno)); + char errbuf[1024]; + ERROR ("sensors plugin: malloc: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); break; } @@ -356,7 +357,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 */ @@ -376,7 +377,8 @@ static void sensors_submit (const char *plugin_instance, value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - if (ignorelist_match (sensor_list, type_instance)) + if ((sensor_list != NULL) + && (ignorelist_match (sensor_list, type_instance))) return; values[0].gauge = val; @@ -384,7 +386,7 @@ static void sensors_submit (const char *plugin_instance, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname); + strcpy (vl.host, hostname_g); strcpy (vl.plugin, "sensors"); strcpy (vl.plugin_instance, plugin_instance); strcpy (vl.type_instance, type_instance);