net-snmp/debian/patches/60_libsensors_api.patch

219 lines
9.0 KiB
Diff

From: Net-SNMP Packaging Team <pkg-net-snmp-devel@lists.alioth.debian.org>
Date: Thu, 18 Jun 2015 06:12:05 +0900
Subject: _libsensors_api
Patch from Jonathan Nieder <jrnieder@gmail.com> to update lmsensors API to libsensors4.
---
agent/mibgroup/ucd-snmp/lmSensors.c | 162 +++++++++++++++++-------------------
1 file changed, 78 insertions(+), 84 deletions(-)
diff --git a/agent/mibgroup/ucd-snmp/lmSensors.c b/agent/mibgroup/ucd-snmp/lmSensors.c
index 05c60b7..888731f 100644
--- a/agent/mibgroup/ucd-snmp/lmSensors.c
+++ b/agent/mibgroup/ucd-snmp/lmSensors.c
@@ -94,7 +94,6 @@ netsnmp_feature_require(table_container)
#endif
#else
#include <sensors/sensors.h>
- #define CONFIG_FILE_NAME "/etc/sensors.conf"
#endif
#include "lmSensors.h"
@@ -357,9 +356,7 @@ sensor_init(void)
{
int res;
#ifndef solaris2
- char filename[] = CONFIG_FILE_NAME;
time_t t = time(NULL);
- FILE *fp = fopen(filename, "r");
int i = 0;
DEBUGMSG(("ucd-snmp/lmSensors", "=> sensor_init\n"));
@@ -371,13 +368,7 @@ sensor_init(void)
sensor_array[i].sensor = NULL;
}
- if (!fp)
- {
- res = 1;
- goto leaving;
- }
-
- if (sensors_init(fp))
+ if (sensors_init(NULL))
{
res = 2;
goto leaving;
@@ -395,7 +386,7 @@ static int
sensor_load(void)
{
int rc = 0;
- time_t t = time(NULL);
+ time_t t = time(NULL);
if (t > timestamp + 7) /* this may require some tuning - currently 7 seconds*/
{
@@ -947,7 +938,8 @@ else{
#else /* end solaris2 only ie. ifdef everything else */
const sensors_chip_name *chip;
- const sensors_feature_data *data;
+ const sensors_feature *feature;
+ const sensors_subfeature *subfeature;
int chip_nr = 0;
unsigned int i = 0;
@@ -969,78 +961,80 @@ else{
sensor_array[i].current_len = DEFAULT_SENSORS;
} /* end for */
- while ((chip = sensors_get_detected_chips(&chip_nr))) {
- int a = 0;
- int b = 0;
-
- while ((data = sensors_get_all_features(*chip, &a, &b))) {
- char *label = NULL;
- double val;
-
- if ((data->mode & SENSORS_MODE_R) &&
- (data->mapping == SENSORS_NO_MAPPING) &&
- !sensors_get_label(*chip, data->number, &label) &&
- !sensors_get_feature(*chip, data->number, &val)) {
- int type = -1;
- float mul = 0;
- _sensor_array *array;
-
- /* The label, as determined for a given chip in sensors.conf,
- * is used to place each sensor in the appropriate bucket.
- * Volt, Fan, Temp, and Misc. If the text being looked for below
- * is not in the label of a given sensor (e.g., the temp1 sensor
- * has been labeled 'CPU' and not 'CPU temp') it will end up being
- * lumped in the MISC bucket. */
-
- if (strstr(label, "V")) {
- type = VOLT_TYPE;
- mul = 1000.0;
- }
- if (strstr(label, "fan") || strstr(label, "Fan")) {
- type = FAN_TYPE;
- mul = 1.0;
- }
- if (strstr(label, "temp") || strstr(label, "Temp")) {
- type = TEMP_TYPE;
- mul = 1000.0;
- }
- if (type == -1) {
- type = MISC_TYPE;
- mul = 1000.0;
- }
-
- array = &sensor_array[type];
- if ( array->current_len <= array->n) {
- _sensor* old_buffer = array->sensor;
- size_t new_size = (sizeof(_sensor) * array->current_len) + (sizeof(_sensor) * DEFAULT_SENSORS);
- array->sensor = (_sensor*)realloc(array->sensor, new_size);
- if (array->sensor == NULL)
- {
- /* Continuing would be unsafe */
- snmp_log(LOG_ERR, "too many sensors to fit, and failed to alloc more, failing on %s\n", label);
- free(old_buffer);
- old_buffer = NULL;
- if (label) {
- free(label);
- label = NULL;
- } /* end if label */
- return 1;
- } /* end if array->sensor */
- array->current_len = new_size / sizeof(_sensor);
- DEBUGMSG(("ucd-snmp/lmSensors", "type #%d increased to %d elements\n", type, (int)array->current_len));
- } /* end if array->current */
- strlcpy(array->sensor[array->n].name, label, MAX_NAME);
- array->sensor[array->n].value = (int) (val * mul);
- DEBUGMSGTL(("sensors","sensor %s, value %d\n",
- array->sensor[array->n].name,
- array->sensor[array->n].value));
- array->n++;
- } /* end if data-mode */
- if (label) {
- free(label);
- label = NULL;
- } /* end if label */
- } /* end while data */
+ while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
+ int a = 0;
+ while ((feature = sensors_get_features(chip, &a))) {
+ int b = 0;
+ while ((subfeature = sensors_get_all_subfeatures(chip,
+ feature, &b))) {
+ char *label = NULL;
+ double val;
+
+ if ((subfeature->flags & SENSORS_MODE_R) &&
+ (label = sensors_get_label(chip, feature)) &&
+ !sensors_get_value(chip, subfeature->number, &val)) {
+ int type = -1;
+ float mul;
+ _sensor_array *array;
+
+ /* The label, as determined for a given chip in
+ * sensors.conf, is used to place each sensor in the
+ * appropriate bucket. Volt, Fan, Temp, and Misc.
+ * If the text being looked for below is not in the
+ * label of a given sensor (e.g., the temp1 sensor
+ * has been labeled 'CPU' and not 'CPU temp') it
+ * will end up being lumped in the MISC bucket. */
+
+ if (strstr(label, "V")) {
+ type = VOLT_TYPE;
+ mul = 1000.0;
+ }
+ if (strstr(label, "fan") || strstr(label, "Fan")) {
+ type = FAN_TYPE;
+ mul = 1.0;
+ }
+ if (strstr(label, "temp") || strstr(label, "Temp")) {
+ type = TEMP_TYPE;
+ mul = 1000.0;
+ }
+ if (type == -1) {
+ type = MISC_TYPE;
+ mul = 1000.0;
+ }
+
+ array = &sensor_array[type];
+ if ( array->current_len <= array->n) {
+ _sensor* old_buffer = array->sensor;
+ size_t new_size = (sizeof(_sensor) * array->current_len) + (sizeof(_sensor) * DEFAULT_SENSORS);
+ array->sensor = (_sensor*)realloc(array->sensor, new_size);
+ if (array->sensor == NULL)
+ {
+ /* Continuing would be unsafe */
+ snmp_log(LOG_ERR, "too many sensors to fit, and failed to alloc more, failing on %s\n", label);
+ free(old_buffer);
+ old_buffer = NULL;
+ if (label) {
+ free(label);
+ label = NULL;
+ } /* end if label */
+ return (rc=1);
+ } /* end if array->sensor */
+ array->current_len = new_size / sizeof(_sensor);
+ DEBUGMSG(("ucd-snmp/lmSensors", "type #%d increased to %d elements\n", type, array->current_len));
+ } /* end if array->current */
+ strncpy(array->sensor[array->n].name, label, MAX_NAME);
+ array->sensor[array->n].value = (int) (val * mul);
+ DEBUGMSGTL(("sensors","sensor %d, value %d\n",
+ array->sensor[array->n].name,
+ array->sensor[array->n].value));
+ array->n++;
+ } /* end if data-mode */
+ if (label) {
+ free(label);
+ label = NULL;
+ } /* end if label */
+ } /* end while subfeature */
+ } /* end while feature */
} /* end while chip */
DEBUGMSG(("ucd-snmp/lmSensors", "<= sensor_load\n"));
#endif /* end else ie. ifdef everything else */