projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'collectd-5.5'
[collectd.git]
/
src
/
sensors.c
diff --git
a/src/sensors.c
b/src/sensors.c
index
fa461a2
..
f5b09bd
100644
(file)
--- a/
src/sensors.c
+++ b/
src/sensors.c
@@
-17,7
+17,7
@@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
* 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
*
* Lubos Stanek <lubek at users.sourceforge.net> Wed Oct 27, 2006
* - config ExtendedSensorNaming option
@@
-27,6
+27,10
@@
* - honor sensors.conf's ignored
* - config Sensor option
* - config IgnoreSelected option
* - honor sensors.conf's ignored
* - config Sensor option
* - config IgnoreSelected option
+ *
+ * Henrique de Moraes Holschuh <hmh at debian.org>
+ * - use default libsensors config file on API 0x400
+ * - config SensorConfigFile option
**/
#include "collectd.h"
**/
#include "collectd.h"
@@
-58,7
+62,9
@@
static char *sensor_type_name_map[] =
"fanspeed",
# define SENSOR_TYPE_TEMPERATURE 2
"temperature",
"fanspeed",
# define SENSOR_TYPE_TEMPERATURE 2
"temperature",
-# define SENSOR_TYPE_UNKNOWN 3
+# define SENSOR_TYPE_POWER 3
+ "power",
+# define SENSOR_TYPE_UNKNOWN 4
NULL
};
NULL
};
@@
-123,7
+129,8
@@
static sensors_labeltypes_t known_features[] =
{ "3.3V", SENSOR_TYPE_VOLTAGE },
{ "2.5V", SENSOR_TYPE_VOLTAGE },
{ "2.0V", SENSOR_TYPE_VOLTAGE },
{ "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 */
};
static int known_features_num = STATIC_ARRAY_SIZE (known_features);
/* end new naming */
@@
-132,7
+139,8
@@
static int known_features_num = STATIC_ARRAY_SIZE (known_features);
static const char *config_keys[] =
{
"Sensor",
static const char *config_keys[] =
{
"Sensor",
- "IgnoreSelected"
+ "IgnoreSelected",
+ "SensorConfigFile"
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
@@
-148,6
+156,7
@@
typedef struct featurelist
# ifndef SENSORS_CONF_PATH
# define SENSORS_CONF_PATH "/etc/sensors.conf"
# endif
# ifndef SENSORS_CONF_PATH
# define SENSORS_CONF_PATH "/etc/sensors.conf"
# endif
+static char *conffile = SENSORS_CONF_PATH;
/* #endif SENSORS_API_VERSION < 0x400 */
#elif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500)
/* #endif SENSORS_API_VERSION < 0x400 */
#elif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500)
@@
-159,9
+168,7
@@
typedef struct featurelist
struct featurelist *next;
} featurelist_t;
struct featurelist *next;
} featurelist_t;
-# ifndef SENSORS_CONF_PATH
-# define SENSORS_CONF_PATH "/etc/sensors3.conf"
-# endif
+static char *conffile = NULL;
/* #endif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500) */
#else /* if SENSORS_API_VERSION >= 0x500 */
/* #endif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500) */
#else /* if SENSORS_API_VERSION >= 0x500 */
@@
-169,10
+176,8
@@
typedef struct featurelist
"as bug."
#endif
"as bug."
#endif
-static const char *conffile = SENSORS_CONF_PATH;
featurelist_t *first_feature = NULL;
static ignorelist_t *sensor_list;
featurelist_t *first_feature = NULL;
static ignorelist_t *sensor_list;
-static time_t sensors_config_mtime = 0;
#if SENSORS_API_VERSION < 0x400
/* full chip name logic borrowed from lm_sensors */
#if SENSORS_API_VERSION < 0x400
/* full chip name logic borrowed from lm_sensors */
@@
-225,7
+230,19
@@
static int sensors_config (const char *key, const char *value)
if (sensor_list == NULL)
sensor_list = ignorelist_create (1);
if (sensor_list == NULL)
sensor_list = ignorelist_create (1);
- if (strcasecmp (key, "Sensor") == 0)
+ /* 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)
+ {
+ char *tmp = strdup (value);
+ if (tmp != NULL)
+ {
+ sfree (conffile);
+ conffile = tmp;
+ }
+ }
+ else if (strcasecmp (key, "Sensor") == 0)
{
if (ignorelist_add (sensor_list, value))
{
{
if (ignorelist_add (sensor_list, value))
{
@@
-237,9
+254,7
@@
static int sensors_config (const char *key, const char *value)
else if (strcasecmp (key, "IgnoreSelected") == 0)
{
ignorelist_set_invert (sensor_list, 1);
else if (strcasecmp (key, "IgnoreSelected") == 0)
{
ignorelist_set_invert (sensor_list, 1);
- if ((strcasecmp (value, "True") == 0)
- || (strcasecmp (value, "Yes") == 0)
- || (strcasecmp (value, "On") == 0))
+ if (IS_TRUE (value))
ignorelist_set_invert (sensor_list, 0);
}
else
ignorelist_set_invert (sensor_list, 0);
}
else
@@
-270,47
+285,37
@@
void sensors_free_features (void)
static int sensors_load_conf (void)
{
static int sensors_load_conf (void)
{
- FILE *fh;
+ static int call_once = 0;
+
+ FILE *fh = NULL;
featurelist_t *last_feature = NULL;
const sensors_chip_name *chip;
int chip_num;
featurelist_t *last_feature = NULL;
const sensors_chip_name *chip;
int chip_num;
- struct stat statbuf;
int status;
int status;
-
- status = stat (conffile, &statbuf);
- if (status != 0)
- {
- char errbuf[1024];
- ERROR ("sensors plugin: stat (%s) failed: %s", conffile,
- sstrerror (errno, errbuf, sizeof (errbuf)));
- sensors_config_mtime = 0;
- }
- if ((sensors_config_mtime != 0)
- && (sensors_config_mtime == statbuf.st_mtime))
- return (0);
+ if (call_once)
+ return 0;
- if (sensors_config_mtime != 0)
- {
- NOTICE ("sensors plugin: Reloading config from %s",
- conffile);
- sensors_free_features ();
- sensors_config_mtime = 0;
- }
+ call_once = 1;
- fh = fopen (conffile, "r");
- if (fh == NULL)
+ if (conffile != NULL)
{
{
- char errbuf[1024];
- ERROR ("sensors plugin: fopen(%s) failed: %s", conffile,
- sstrerror (errno, errbuf, sizeof (errbuf)));
- return (-1);
+ fh = fopen (conffile, "r");
+ if (fh == NULL)
+ {
+ char errbuf[1024];
+ ERROR ("sensors plugin: fopen(%s) failed: %s", conffile,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return (-1);
+ }
}
status = sensors_init (fh);
}
status = sensors_init (fh);
- fclose (fh);
+ if (fh)
+ fclose (fh);
+
if (status != 0)
{
ERROR ("sensors plugin: Cannot initialize sensors. "
if (status != 0)
{
ERROR ("sensors plugin: Cannot initialize sensors. "
@@
-318,8
+323,6
@@
static int sensors_load_conf (void)
return (-1);
}
return (-1);
}
- sensors_config_mtime = statbuf.st_mtime;
-
#if SENSORS_API_VERSION < 0x400
chip_num = 0;
while ((chip = sensors_get_detected_chips (&chip_num)) != NULL)
#if SENSORS_API_VERSION < 0x400
chip_num = 0;
while ((chip = sensors_get_detected_chips (&chip_num)) != NULL)
@@
-411,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)
/* 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', "
{
DEBUG ("sensors plugin: sensors_load_conf: "
"Ignoring feature `%s', "
@@
-427,7
+431,8
@@
static int sensors_load_conf (void)
if ((subfeature->type != SENSORS_SUBFEATURE_IN_INPUT)
&& (subfeature->type != SENSORS_SUBFEATURE_FAN_INPUT)
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));
continue;
fl = (featurelist_t *) malloc (sizeof (featurelist_t));
@@
-573,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_TEMP)
type = "temperature";
+ else if (fl->feature->type
+ == SENSORS_FEATURE_POWER)
+ type = "power";
else
continue;
else
continue;