X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsensors.c;h=fa461a2f6bffd7db8b3dca5dcca02a23e542dc53;hb=0a73779531039d715e8ca405658c65ba03fad408;hp=1289d4b68177b1f75483712146591854168f92b0;hpb=1a8ae6734a9351097943dd1ce019a8d95b72c3d1;p=collectd.git diff --git a/src/sensors.c b/src/sensors.c index 1289d4b6..fa461a2f 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -1,6 +1,7 @@ /** * collectd - src/sensors.c - * Copyright (C) 2005-2007 Florian octo Forster + * Copyright (C) 2005-2008 Florian octo Forster + * Copyright (C) 2006 Luboš Staněk * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -182,21 +183,21 @@ static int sensors_snprintf_chip_name (char *buf, size_t buf_size, if (chip->bus == SENSORS_CHIP_NAME_BUS_ISA) { - status = snprintf (buf, buf_size, + status = ssnprintf (buf, buf_size, "%s-isa-%04x", chip->prefix, chip->addr); } else if (chip->bus == SENSORS_CHIP_NAME_BUS_DUMMY) { - snprintf (buf, buf_size, "%s-%s-%04x", + status = snprintf (buf, buf_size, "%s-%s-%04x", chip->prefix, chip->busname, chip->addr); } else { - snprintf (buf, buf_size, "%s-i2c-%d-%02x", + status = snprintf (buf, buf_size, "%s-i2c-%d-%02x", chip->prefix, chip->bus, chip->addr); @@ -341,16 +342,38 @@ static int sensors_load_conf (void) /* "master features" only */ if (feature->mapping != SENSORS_NO_MAPPING) + { + DEBUG ("sensors plugin: sensors_load_conf: " + "Ignoring subfeature `%s', " + "because (feature->mapping " + "!= SENSORS_NO_MAPPING).", + feature->name); continue; + } /* skip ignored in sensors.conf */ if (sensors_get_ignored (*chip, feature->number) == 0) - break; + { + DEBUG ("sensors plugin: sensors_load_conf: " + "Ignoring subfeature `%s', " + "because " + "`sensors_get_ignored' told " + "me so.", + feature->name); + continue; + } feature_type = sensors_feature_name_to_type ( feature->name); if (feature_type == SENSOR_TYPE_UNKNOWN) + { + DEBUG ("sensors plugin: sensors_load_conf: " + "Ignoring subfeature `%s', " + "because its type is " + "unknown.", + feature->name); continue; + } fl = (featurelist_t *) malloc (sizeof (featurelist_t)); if (fl == NULL) @@ -389,7 +412,13 @@ static int sensors_load_conf (void) if ((feature->type != SENSORS_FEATURE_IN) && (feature->type != SENSORS_FEATURE_FAN) && (feature->type != SENSORS_FEATURE_TEMP)) + { + DEBUG ("sensors plugin: sensors_load_conf: " + "Ignoring feature `%s', " + "because its type is not " + "supported.", feature->name); continue; + } while ((subfeature = sensors_get_all_subfeatures (chip, feature, &subfeature_num)) != NULL) @@ -452,11 +481,10 @@ static void sensors_submit (const char *plugin_instance, value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - status = snprintf (match_key, sizeof (match_key), "%s/%s-%s", + status = ssnprintf (match_key, sizeof (match_key), "%s/%s-%s", plugin_instance, type, type_instance); if (status < 1) return; - match_key[sizeof (match_key) - 1] = '\0'; if (sensor_list != NULL) { @@ -469,19 +497,15 @@ static void sensors_submit (const char *plugin_instance, vl.values = values; vl.values_len = 1; - vl.time = time (NULL); - strncpy (vl.host, hostname_g, sizeof (vl.host)); - vl.host[sizeof (vl.host) - 1] = '\0'; - strncpy (vl.plugin, "sensors", sizeof (vl.plugin)); - vl.plugin[sizeof (vl.plugin) - 1] = '\0'; - strncpy (vl.plugin_instance, plugin_instance, + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "sensors", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - vl.plugin_instance[sizeof (vl.plugin_instance) - 1] = '\0'; - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void sensors_submit */ static int sensors_read (void) @@ -508,11 +532,9 @@ static int sensors_read (void) sizeof (plugin_instance), fl->chip); if (status < 0) continue; - plugin_instance[sizeof (plugin_instance) - 1] = '\0'; - strncpy (type_instance, fl->data->name, + sstrncpy (type_instance, fl->data->name, sizeof (type_instance)); - type_instance[sizeof (type_instance) - 1] = '\0'; sensors_submit (plugin_instance, sensor_type_name_map[fl->type], @@ -539,11 +561,9 @@ static int sensors_read (void) sizeof (plugin_instance), fl->chip); if (status < 0) continue; - plugin_instance[sizeof (plugin_instance) - 1] = '\0'; - strncpy (type_instance, fl->feature->name, + sstrncpy (type_instance, fl->feature->name, sizeof (type_instance)); - type_instance[sizeof (type_instance) - 1] = '\0'; if (fl->feature->type == SENSORS_FEATURE_IN) type = "voltage"; @@ -552,7 +572,7 @@ static int sensors_read (void) type = "fanspeed"; else if (fl->feature->type == SENSORS_FEATURE_TEMP) - type = "input"; + type = "temperature"; else continue;