write_redis: Log error message from redis command failures
[collectd.git] / src / sensors.c
index 96a54fc..f5b09bd 100644 (file)
@@ -17,7 +17,7 @@
  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  *   
  *   Lubos Stanek <lubek at users.sourceforge.net> Wed Oct 27, 2006
  *   - config ExtendedSensorNaming option
@@ -62,7 +62,9 @@ static char *sensor_type_name_map[] =
        "fanspeed",
 # define SENSOR_TYPE_TEMPERATURE 2
        "temperature",
-# define SENSOR_TYPE_UNKNOWN     3
+# define SENSOR_TYPE_POWER       3
+       "power",
+# define SENSOR_TYPE_UNKNOWN     4
        NULL
 };
 
@@ -127,7 +129,8 @@ 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 }
+       { "12V", SENSOR_TYPE_VOLTAGE },
+       { "power1", SENSOR_TYPE_POWER }
 };
 static int known_features_num = STATIC_ARRAY_SIZE (known_features);
 /* end new naming */
@@ -153,7 +156,7 @@ typedef struct featurelist
 # ifndef SENSORS_CONF_PATH
 #  define SENSORS_CONF_PATH "/etc/sensors.conf"
 # endif
-static const char *conffile = SENSORS_CONF_PATH;
+static char *conffile = SENSORS_CONF_PATH;
 /* #endif SENSORS_API_VERSION < 0x400 */
 
 #elif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500)
@@ -165,7 +168,7 @@ typedef struct featurelist
        struct featurelist         *next;
 } featurelist_t;
 
-static const char *conffile = NULL;
+static char *conffile = NULL;
 /* #endif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500) */
 
 #else /* if SENSORS_API_VERSION >= 0x500 */
@@ -227,12 +230,17 @@ static int sensors_config (const char *key, const char *value)
        if (sensor_list == NULL)
                sensor_list = ignorelist_create (1);
 
+       /* TODO: This setting exists for compatibility with old versions of
+        * lm-sensors. Remove support for those ancient versions in the next
+        * major release. */
        if (strcasecmp (key, "SensorConfigFile") == 0)
        {
-               /* we will leak memory here if SensorConfigFile is
-                  used more than once, maybe we can just drop support
-                  for broken, extremely ancient libsensors? */
-               conffile = strdup (value);
+               char *tmp = strdup (value);
+               if (tmp != NULL)
+               {
+                       sfree (conffile);
+                       conffile = tmp;
+               }
        }
        else if (strcasecmp (key, "Sensor") == 0)
        {
@@ -292,7 +300,7 @@ static int sensors_load_conf (void)
 
        call_once = 1;
 
-       if (conffile)
+       if (conffile != NULL)
        {
                fh = fopen (conffile, "r");
                if (fh == NULL)
@@ -406,7 +414,8 @@ static int sensors_load_conf (void)
                        /* Only handle voltage, fanspeeds and temperatures */
                        if ((feature->type != SENSORS_FEATURE_IN)
                                        && (feature->type != SENSORS_FEATURE_FAN)
-                                       && (feature->type != SENSORS_FEATURE_TEMP))
+                                       && (feature->type != SENSORS_FEATURE_TEMP)
+                                       && (feature->type != SENSORS_FEATURE_POWER))
                        {
                                DEBUG ("sensors plugin: sensors_load_conf: "
                                                "Ignoring feature `%s', "
@@ -422,7 +431,8 @@ static int sensors_load_conf (void)
 
                                if ((subfeature->type != SENSORS_SUBFEATURE_IN_INPUT)
                                                && (subfeature->type != SENSORS_SUBFEATURE_FAN_INPUT)
-                                               && (subfeature->type != SENSORS_SUBFEATURE_TEMP_INPUT))
+                                               && (subfeature->type != SENSORS_SUBFEATURE_TEMP_INPUT)
+                                               && (subfeature->type != SENSORS_SUBFEATURE_POWER_INPUT))
                                        continue;
 
                                fl = (featurelist_t *) malloc (sizeof (featurelist_t));
@@ -568,6 +578,9 @@ static int sensors_read (void)
                else if (fl->feature->type
                                == SENSORS_FEATURE_TEMP)
                        type = "temperature";
+               else if (fl->feature->type
+                               == SENSORS_FEATURE_POWER)
+                       type = "power";
                else
                        continue;