+#include "plugin.h"
+#include "configfile.h"
+#include "utils_ignorelist.h"
+#include "utils_debug.h"
+
+/*
+ * This weird macro cascade forces the glibc to define `NAN'. I don't know
+ * another way to solve this, so more intelligent solutions are welcome. -octo
+ */
+#ifndef __USE_ISOC99
+# define DISABLE__USE_ISOC99 1
+# define __USE_ISOC99 1
+#endif
+#include <math.h>
+#ifdef DISABLE__USE_ISOC99
+# undef DISABLE__USE_ISOC99
+# undef __USE_ISOC99
+#endif
+
+#if defined(HAVE_SENSORS_SENSORS_H)
+# include <sensors/sensors.h>
+#else
+# undef HAVE_LIBSENSORS
+#endif
+
+#if defined(HAVE_LIBSENSORS)
+# define SENSORS_HAVE_READ 1
+#else
+# define SENSORS_HAVE_READ 0
+#endif
+
+static data_source_t data_source[1] =
+{
+ {"value", DS_TYPE_GAUGE, NAN, NAN}
+};
+static data_set_t fanspeed_ds =
+{
+ "fanspeed", 1, data_source
+};
+
+static data_set_t temperature_ds =
+{
+ "temperature", 1, data_source
+};
+
+static data_set_t voltage_ds =
+{
+ "voltage", 1, data_source
+};
+
+#if SENSORS_HAVE_READ
+#define SENSOR_TYPE_VOLTAGE 0
+#define SENSOR_TYPE_FANSPEED 1
+#define SENSOR_TYPE_TEMPERATURE 2
+#define SENSOR_TYPE_UNKNOWN 3
+
+static char *sensor_to_type[] =
+{
+ "voltage",
+ "fanspeed",
+ "temperature",
+ NULL
+};
+
+struct sensors_labeltypes_s
+{
+ char *label;
+ int type;
+};
+typedef struct sensors_labeltypes_s sensors_labeltypes_t;
+
+/*
+ * finite list of known labels extracted from lm_sensors
+ */
+static sensors_labeltypes_t known_features[] =
+{
+ { "fan1", SENSOR_TYPE_FANSPEED },
+ { "fan2", SENSOR_TYPE_FANSPEED },
+ { "fan3", SENSOR_TYPE_FANSPEED },
+ { "fan4", SENSOR_TYPE_FANSPEED },
+ { "fan5", SENSOR_TYPE_FANSPEED },
+ { "fan6", SENSOR_TYPE_FANSPEED },
+ { "fan7", SENSOR_TYPE_FANSPEED },
+ { "AIN2", SENSOR_TYPE_VOLTAGE },
+ { "AIN1", SENSOR_TYPE_VOLTAGE },
+ { "in10", SENSOR_TYPE_VOLTAGE },
+ { "in9", SENSOR_TYPE_VOLTAGE },
+ { "in8", SENSOR_TYPE_VOLTAGE },
+ { "in7", SENSOR_TYPE_VOLTAGE },
+ { "in6", SENSOR_TYPE_VOLTAGE },
+ { "in5", SENSOR_TYPE_VOLTAGE },
+ { "in4", SENSOR_TYPE_VOLTAGE },
+ { "in3", SENSOR_TYPE_VOLTAGE },
+ { "in2", SENSOR_TYPE_VOLTAGE },
+ { "in0", SENSOR_TYPE_VOLTAGE },
+ { "CPU_Temp", SENSOR_TYPE_TEMPERATURE },
+ { "remote_temp", SENSOR_TYPE_TEMPERATURE },
+ { "temp1", SENSOR_TYPE_TEMPERATURE },
+ { "temp2", SENSOR_TYPE_TEMPERATURE },
+ { "temp3", SENSOR_TYPE_TEMPERATURE },
+ { "temp4", SENSOR_TYPE_TEMPERATURE },
+ { "temp5", SENSOR_TYPE_TEMPERATURE },
+ { "temp6", SENSOR_TYPE_TEMPERATURE },
+ { "temp7", SENSOR_TYPE_TEMPERATURE },
+ { "temp", SENSOR_TYPE_TEMPERATURE },
+ { "Vccp2", SENSOR_TYPE_VOLTAGE },
+ { "Vccp1", SENSOR_TYPE_VOLTAGE },
+ { "vdd", SENSOR_TYPE_VOLTAGE },
+ { "vid5", SENSOR_TYPE_VOLTAGE },
+ { "vid4", SENSOR_TYPE_VOLTAGE },
+ { "vid3", SENSOR_TYPE_VOLTAGE },
+ { "vid2", SENSOR_TYPE_VOLTAGE },
+ { "vid1", SENSOR_TYPE_VOLTAGE },
+ { "vid", SENSOR_TYPE_VOLTAGE },
+ { "vin4", SENSOR_TYPE_VOLTAGE },
+ { "vin3", SENSOR_TYPE_VOLTAGE },
+ { "vin2", SENSOR_TYPE_VOLTAGE },
+ { "vin1", SENSOR_TYPE_VOLTAGE },
+ { "voltbatt", SENSOR_TYPE_VOLTAGE },
+ { "volt12", SENSOR_TYPE_VOLTAGE },
+ { "volt5", SENSOR_TYPE_VOLTAGE },
+ { "vrm", SENSOR_TYPE_VOLTAGE },
+ { "5.0V", SENSOR_TYPE_VOLTAGE },
+ { "5V", SENSOR_TYPE_VOLTAGE },
+ { "3.3V", SENSOR_TYPE_VOLTAGE },
+ { "2.5V", SENSOR_TYPE_VOLTAGE },
+ { "2.0V", SENSOR_TYPE_VOLTAGE },
+ { "12V", SENSOR_TYPE_VOLTAGE },
+ { (char *) 0, SENSOR_TYPE_UNKNOWN }
+};
+/* end new naming */
+
+static const char *config_keys[] =
+{
+ "Sensor",
+ "IgnoreSelected",
+ NULL
+};
+static int config_keys_num = 2;
+
+static ignorelist_t *sensor_list;
+
+#ifndef SENSORS_CONF_PATH
+# define SENSORS_CONF_PATH "/etc/sensors.conf"
+#endif
+
+static const char *conffile = SENSORS_CONF_PATH;
+/* SENSORS_CONF_PATH */
+
+/*
+ * remember stat of the loaded config
+ */
+static time_t sensors_config_mtime = 0;