Removed the `XXX_HAVE_READ' defines from all plugins.
[collectd.git] / src / sensors.c
index 551d267..3e1d4f9 100644 (file)
 
 #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_fanspeed[1] =
-{
-       {"value", DS_TYPE_GAUGE, 0, NAN}
-};
-
-static data_set_t fanspeed_ds =
-{
-       "fanspeed", 1, data_source_fanspeed
-};
-
-static data_source_t data_source_temperature[1] =
-{
-       {"value", DS_TYPE_GAUGE, -273.15, NAN}
-};
-
-static data_set_t temperature_ds =
-{
-       "temperature", 1, data_source_temperature
-};
-
-static data_source_t data_source_voltage[1] =
-{
-       {"value", DS_TYPE_GAUGE, NAN, NAN}
-};
-
-static data_set_t voltage_ds =
-{
-       "voltage", 1, data_source_voltage
-};
-
-#if SENSORS_HAVE_READ
 #define SENSOR_TYPE_VOLTAGE     0
 #define SENSOR_TYPE_FANSPEED    1
 #define SENSOR_TYPE_TEMPERATURE 2
@@ -238,7 +199,7 @@ void sensors_free_features (void)
        first_feature = NULL;
 }
 
-static void sensors_load_conf (void)
+static int sensors_load_conf (void)
 {
        FILE *fh;
        featurelist_t *last_feature = NULL;
@@ -264,7 +225,7 @@ static void sensors_load_conf (void)
 
        if ((sensors_config_mtime != 0)
                        && (sensors_config_mtime == statbuf.st_mtime))
-               return;
+               return (0);
 
        if (sensors_config_mtime != 0)
        {
@@ -280,7 +241,7 @@ static void sensors_load_conf (void)
                char errbuf[1024];
                ERROR ("sensors plugin: fopen(%s) failed: %s", conffile,
                                sstrerror (errno, errbuf, sizeof (errbuf)));
-               return;
+               return (-1);
        }
 
        status = sensors_init (fh);
@@ -289,7 +250,7 @@ static void sensors_load_conf (void)
        {
                ERROR ("sensors plugin: Cannot initialize sensors. "
                                "Data will not be collected.");
-               return;
+               return (-1);
        }
 
        sensors_config_mtime = statbuf.st_mtime;
@@ -359,8 +320,11 @@ static void sensors_load_conf (void)
                sensors_cleanup ();
                INFO ("sensors plugin: lm_sensors reports no "
                                "features. Data will not be collected.");
+               return (-1);
        }
-} /* void sensors_load_conf */
+
+       return (0);
+} /* int sensors_load_conf */
 
 static int sensors_shutdown (void)
 {
@@ -402,7 +366,8 @@ static int sensors_read (void)
        char plugin_instance[DATA_MAX_NAME_LEN];
        char type_instance[DATA_MAX_NAME_LEN];
 
-       sensors_load_conf ();
+       if (sensors_load_conf () != 0)
+               return (-1);
 
        for (feature = first_feature; feature != NULL; feature = feature->next)
        {
@@ -447,24 +412,11 @@ static int sensors_read (void)
 
        return (0);
 } /* int sensors_read */
-#endif /* SENSORS_HAVE_READ */
 
-void module_register (modreg_e load)
+void module_register (void)
 {
-       if (load & MR_DATASETS)
-       {
-               plugin_register_data_set (&fanspeed_ds);
-               plugin_register_data_set (&temperature_ds);
-               plugin_register_data_set (&voltage_ds);
-       }
-
-#if SENSORS_HAVE_READ
-       if (load & MR_READ)
-       {
-               plugin_register_config ("sensors", sensors_config,
-                               config_keys, config_keys_num);
-               plugin_register_read ("sensors", sensors_read);
-               plugin_register_shutdown ("sensors", sensors_shutdown);
-       }
-#endif
+       plugin_register_config ("sensors", sensors_config,
+                       config_keys, config_keys_num);
+       plugin_register_read ("sensors", sensors_read);
+       plugin_register_shutdown ("sensors", sensors_shutdown);
 } /* void module_register */