Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 35670 Details for
Bug 57450
Patch and ebuild to add lm_sensors support to net-snmp
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch to include lm_sensors support
sensors.patch (text/plain), 13.37 KB, created by
Joshua Gerrish
on 2004-07-17 23:10:44 UTC
(
hide
)
Description:
Patch to include lm_sensors support
Filename:
MIME Type:
Creator:
Joshua Gerrish
Created:
2004-07-17 23:10:44 UTC
Size:
13.37 KB
patch
obsolete
>diff -Naur net-snmp-5.1.1.old/agent/mibgroup/host/hr_sensor.c net-snmp-5.1.1/agent/mibgroup/host/hr_sensor.c >--- net-snmp-5.1.1.old/agent/mibgroup/host/hr_sensor.c 1970-01-01 02:00:00.000000000 +0200 >+++ net-snmp-5.1.1/agent/mibgroup/host/hr_sensor.c 2003-10-21 12:49:57.000000000 +0300 >@@ -0,0 +1,322 @@ >+/* This file was generated by mib2c and is intended for use as a mib module >+ for the ucd-snmp snmpd agent. */ >+ >+#include <net-snmp/net-snmp-config.h> >+ >+#include <stdio.h> >+#if HAVE_STDLIB_H >+#include <stdlib.h> >+#endif >+#if HAVE_STRING_H >+#include <string.h> >+#else >+#include <strings.h> >+#endif >+ >+#include <getopt.h> >+#include <errno.h> >+#include <dlfcn.h> >+ >+#include "sensors/sensors.h" >+#include "sensors/error.h" >+ >+#include "host_res.h" >+#include "hr_sensor.h" >+ >+ >+/* >+ * hr_sensor_variables_oid: >+ * this is the top level oid that we want to register under. This >+ * is essentially a prefix, with the suffix appearing in the >+ * variable below. >+ */ >+ >+ >+oid hr_sensor_variables_oid[] = { 1,3,6,1,2,1,25,8 }; >+ >+ >+/* >+ * variable2 hr_sensor_variables: >+ * this variable defines function callbacks and type return information >+ * for the hr_sensor mib section >+ */ >+ >+ >+struct variable2 hr_sensor_variables[] = { >+ /* magic number , variable type , ro/rw , callback fn , L, oidsuffix */ >+#define HRSENSORMAPPING 2 >+ { HRSENSORMAPPING, ASN_INTEGER , RONLY , var_hr_sensor, 2, { 1,1 } }, >+#define HRSENSORNUMBER 3 >+ { HRSENSORNUMBER, ASN_INTEGER , RONLY , var_hr_sensor, 2, { 1,2 } }, >+#define HRSENSORNAME 4 >+ { HRSENSORNAME , ASN_OCTET_STR , RONLY , var_hr_sensor, 2, { 1,3 } }, >+#define HRSENSORLABEL 5 >+ { HRSENSORLABEL , ASN_OCTET_STR , RONLY , var_hr_sensor, 2, { 1,4 } }, >+#define HRSENSORVALUE 6 >+ { HRSENSORVALUE , ASN_OCTET_STR , RONLY , var_hr_sensor, 2, { 1,5 } }, >+ >+}; >+/* (L = length of the oidsuffix) */ >+ >+ >+#define DEFAULT_CONFIG_FILE_NAME "sensors.conf" >+ >+static char *config_file_name; >+FILE *config_file; >+static const char *config_file_path[] = >+{ "/etc", "/usr/lib/sensors", "/usr/local/lib/sensors", "/usr/lib", >+ "/usr/local/lib", ".", 0 }; >+ >+static void open_config_file(void); >+static int open_this_config_file(char *filename); >+ >+ >+/* >+ * functions that are dynamically loaded if the lm_sensors library is >+ * installed. >+ */ >+static int (*sensors_get_label_dl)(sensors_chip_name name, int feature, >+ char **result); >+static int (*sensors_init_dl)(FILE *input); >+static int (*sensors_get_feature_dl)(sensors_chip_name name, int feature, >+ double *result); >+static const sensors_feature_data *(*sensors_get_all_features_dl) >+ (sensors_chip_name name, int *nr1,int *nr2); >+static const sensors_chip_name *(*sensors_get_detected_chips_dl)(int *nr); >+ >+#define CHIPS_MAX 20 >+static sensors_chip_name chips[CHIPS_MAX]; >+static int chips_count=0; >+static int do_sets; >+ >+/* This examines global var config_file, and leaves the name there too. >+ It also opens config_file. */ >+static void open_config_file(void) >+{ >+#define MAX_FILENAME_LEN 1024 >+ char *filename; >+ char buffer[MAX_FILENAME_LEN]; >+ int res,i; >+ >+ if (config_file_name && !strcmp(config_file_name,"-")) { >+ config_file = stdin; >+ return; >+ } else if (config_file_name && index(config_file_name,'/')) { >+ if ((res = open_this_config_file(config_file_name))) { >+ fprintf(stderr,"Could not locate or open config file\n"); >+ fprintf(stderr,"%s: %s\n",config_file_name,strerror(res)); >+ exit(1); >+ } >+ } >+ else { >+ if (config_file_name) >+ filename = config_file_name; >+ else >+ filename = strdup(DEFAULT_CONFIG_FILE_NAME); >+ for (i = 0; config_file_path[i]; i++) { >+ if ((snprintf(buffer,MAX_FILENAME_LEN, >+ "%s/%s",config_file_path[i],filename)) < 1) { >+ fprintf(stderr, >+ "open_config_file: ridiculous long config file name!\n"); >+ exit(1); >+ } >+ if (!open_this_config_file(buffer)) { >+ free(config_file_name); >+ config_file_name = strdup(buffer); >+ return; >+ } >+ } >+ fprintf(stderr,"Could not locate or open config file!\n"); >+ exit(1); >+ } >+} >+ >+static int open_this_config_file(char *filename) >+{ >+ config_file = fopen(filename,"r"); >+ if (! config_file) >+ return -errno; >+ return 0; >+} >+ >+static long *sensor_tbl = 0; >+sensors_chip_name *chip_tbl = 0; >+static int sensor_maxnum = 0; >+ >+static void do_register(sensors_chip_name name) >+{ >+ const char *algo,*adap; >+ >+ { >+ const sensors_feature_data *sensor; >+ const char *map=0; >+ int index0 = 0, index1 = 0; >+ >+ printf("%s\n", name); >+ >+ while ((sensor = sensors_get_all_features_dl (name, &index0, &index1)) >+ != NULL) { >+ if(sensor_tbl = realloc(sensor_tbl, sizeof(long) * (sensor_maxnum+2))) >+ sensor_tbl[sensor_maxnum] = sensor->number; >+ if (chip_tbl = realloc(chip_tbl, sizeof(sensors_chip_name) * (sensor_maxnum+2))) >+ chip_tbl[sensor_maxnum] = name; >+ sensor_maxnum++; >+ } >+ } >+} >+ >+/* >+ * init_hr_sensor(): >+ * Initialization routine. This is called when the agent starts up. >+ * At a minimum, registration of your variables should take place here. >+ */ >+void init_hr_sensor(void) { >+ >+ const sensors_chip_name *chip; >+ int chip_nr,i; >+ int c,res; >+ void *sensors_library; >+ >+ /* This could probably due with a bit more error reporting. */ >+ sensors_library=dlopen("libsensors.so.2",RTLD_LAZY); >+ if(sensors_library==NULL) >+ return; // return before anything is registered >+ >+ sensors_get_label_dl=dlsym(sensors_library,"sensors_get_label"); >+ sensors_init_dl=dlsym(sensors_library,"sensors_init"); >+ sensors_get_feature_dl=dlsym(sensors_library,"sensors_get_feature"); >+ sensors_get_all_features_dl=dlsym(sensors_library, >+ "sensors_get_all_features"); >+ sensors_get_detected_chips_dl=dlsym(sensors_library, >+ "sensors_get_detected_chips"); >+ if(sensors_get_label_dl==NULL || sensors_init_dl==NULL || >+ sensors_get_feature_dl==NULL || sensors_get_all_features_dl==NULL || >+ sensors_get_detected_chips_dl==NULL) >+ return; // return before anything is registered >+ >+ /* register ourselves with the agent to handle our mib tree */ >+ REGISTER_MIB("hr_sensor", hr_sensor_variables, variable2, >+ hr_sensor_variables_oid); >+ >+ >+ /* place any other initialization junk you need here */ >+ >+ >+ chips[0].prefix = SENSORS_CHIP_NAME_PREFIX_ANY; >+ chips[0].bus = SENSORS_CHIP_NAME_BUS_ANY; >+ chips[0].addr = SENSORS_CHIP_NAME_ADDR_ANY; >+ chips_count = 1; >+ >+ open_config_file(); >+ >+ if ((res = sensors_init_dl(config_file))) { >+ return; >+ } >+ >+ for (chip_nr = 0; (chip = sensors_get_detected_chips_dl(&chip_nr));) >+ do_register (*chip); >+} >+ >+ >+/* >+ * var_hr_sensor(): >+ * This function is called every time the agent gets a request for >+ * a scalar variable that might be found within your mib section >+ * registered above. It is up to you to do the right thing and >+ * return the correct value. >+ * You should also correct the value of "var_len" if necessary. >+ * >+ * Please see the documentation for more information about writing >+ * module extensions, and check out the examples in the examples >+ * and mibII directories. >+ */ >+unsigned char * >+var_hr_sensor(struct variable *vp, >+ oid *name, >+ size_t *length, >+ int exact, >+ size_t *var_len, >+ WriteMethod **write_method) >+{ >+ /* variables we may use later */ >+ static long long_ret; >+ static char *string = 0; >+ static oid objid[MAX_OID_LEN]; >+ static struct counter64 c64; >+ >+ const sensors_feature_data *sensor; >+ const char *map=0; >+ int index0 = 0, index1 = 0; >+ int sensor_idx = 0, sensor_num = 0; >+ sensors_chip_name chip_name; >+ double value; >+ >+ >+ if (header_simple_table(vp,name,length,exact,var_len,write_method,sensor_maxnum) >+ == MATCH_FAILED ) >+ return NULL; >+ >+ sensor_idx = name[*length - 1] - 1; >+ sensor_num = sensor_tbl[sensor_idx]; >+ chip_name = chip_tbl[sensor_idx]; >+ >+ while ((sensor = sensors_get_all_features_dl (chip_name, &index0, &index1)) >+ != NULL) { >+ if(sensor_num == sensor->number) { >+ /* >+ * this is where we do the value assignments for the mib results. >+ */ >+ switch(vp->magic) { >+ >+ >+ case HRSENSORMAPPING: >+ >+ long_ret = sensor->mapping; >+ return (unsigned char *) &long_ret; >+ >+ case HRSENSORNUMBER: >+ >+ long_ret = sensor_num; >+ return (unsigned char *) &long_ret; >+ >+ case HRSENSORNAME: >+ >+ string = malloc(SPRINT_MAX_LEN); >+ strncpy(string, sensor->name, SPRINT_MAX_LEN); >+ *var_len = strlen(string); >+ return (unsigned char *) string; >+ >+ case HRSENSORLABEL: >+ >+ string = malloc(SPRINT_MAX_LEN); >+ >+ if (sensors_get_label_dl (chip_name, sensor->number, &string)) { >+ return 0; >+ } >+ >+ *var_len = strlen(string); >+ return (unsigned char *) string; >+ >+ case HRSENSORVALUE: >+ >+ if (!(sensor->mode & SENSORS_MODE_R)) { >+ return 0; >+ } else if (!(sensor->mode & SENSORS_MODE_R)) { >+ return 0; >+ } else if (sensors_get_feature_dl (chip_name, sensor->number, &value)){ >+ return 0; >+ } >+ string = malloc(SPRINT_MAX_LEN); >+ snprintf(string, SPRINT_MAX_LEN, "%f", value); >+ *var_len = strlen(string); >+ return (unsigned char *) string; >+ >+ default: >+ ERROR_MSG(""); >+ return NULL; >+ } >+ } >+ } >+ return NULL; >+} >+ >diff -Naur net-snmp-5.1.1.old/agent/mibgroup/host/hr_sensor.h net-snmp-5.1.1/agent/mibgroup/host/hr_sensor.h >--- net-snmp-5.1.1.old/agent/mibgroup/host/hr_sensor.h 1970-01-01 02:00:00.000000000 +0200 >+++ net-snmp-5.1.1/agent/mibgroup/host/hr_sensor.h 2003-10-21 12:47:04.000000000 +0300 >@@ -0,0 +1,24 @@ >+/* This file was generated by mib2c and is intended for use as a mib module >+ for the ucd-snmp snmpd agent. */ >+ >+ >+#ifndef _MIBGROUP_HRSENSOR_H >+#define _MIBGROUP_HRSENSOR_H >+ >+ >+/* we may use header_generic and header_simple_table from the util_funcs module */ >+ >+ >+config_require(util_funcs) >+ >+ >+/* function prototypes */ >+ >+ >+extern void init_hr_sensor(void); >+extern FindVarMethod var_hr_sensor; >+ >+ >+ >+ >+#endif /* _MIBGROUP_HRSENSOR_H */ >diff -Naur net-snmp-5.1.1.old/agent/mibgroup/host.h net-snmp-5.1.1/agent/mibgroup/host.h >--- net-snmp-5.1.1.old/agent/mibgroup/host.h 2002-04-20 10:30:00.000000000 +0300 >+++ net-snmp-5.1.1/agent/mibgroup/host.h 2003-10-21 12:47:04.000000000 +0300 >@@ -15,6 +15,7 @@ > config_require(host/hr_filesys) > config_require(host/hr_swrun) > config_require(host/hr_swinst) >+ config_require(host/hr_sensor) > > /* add the host resources mib to the default mibs to load */ > config_add_mib(HOST-RESOURCES-MIB) >diff -Naur net-snmp-5.1.1.old/mibs/HOST-RESOURCES-MIB.txt net-snmp-5.1.1/mibs/HOST-RESOURCES-MIB.txt >--- net-snmp-5.1.1.old/mibs/HOST-RESOURCES-MIB.txt 2002-04-20 10:30:15.000000000 +0300 >+++ net-snmp-5.1.1/mibs/HOST-RESOURCES-MIB.txt 2003-10-21 12:47:04.000000000 +0300 >@@ -106,6 +106,7 @@ > hrSWRunPerf OBJECT IDENTIFIER ::= { host 5 } > hrSWInstalled OBJECT IDENTIFIER ::= { host 6 } > hrMIBAdminInfo OBJECT IDENTIFIER ::= { host 7 } >+hrSensor OBJECT IDENTIFIER ::= { host 8 } > > -- textual conventions > >@@ -1390,6 +1391,66 @@ > (hex)'00 00 01 01 00 00 00 00'." > ::= { hrSWInstalledEntry 5 } > >+ >+hrSensorEntry OBJECT-TYPE >+ SYNTAX hrSensorEntry >+ MAX-ACCESS not-accessible >+ STATUS current >+ DESCRIPTION >+ "The CPU temperature sensor settings." >+ INDEX { hrSensor } >+ ::= { hrSensor 1 } >+ >+hrSensorEntry ::= SEQUENCE { >+ hrSensorNumber Integer32, >+ hrSensorMapping Integer32, >+ hrSensorName DisplayString, >+ hrSensorLabel DisplayString, >+ hrSensorValue DisplayString >+ } >+ >+ >+ >+hrSensorMapping OBJECT-TYPE >+ SYNTAX Integer32 (1..2147483647) >+ MAX-ACCESS read-only >+ STATUS current >+ DESCRIPTION >+ "The mapping" >+ ::= { hrSensorEntry 1 } >+ >+hrSensorNumber OBJECT-TYPE >+ SYNTAX Integer32 (1..2147483647) >+ MAX-ACCESS read-only >+ STATUS current >+ DESCRIPTION >+ "The Number" >+ ::= { hrSensorEntry 2 } >+ >+hrSensorName OBJECT-TYPE >+ SYNTAX DisplayString >+ MAX-ACCESS read-only >+ STATUS current >+ DESCRIPTION >+ "The name of the sensor." >+ ::= { hrSensorEntry 3 } >+ >+hrSensorLabel OBJECT-TYPE >+ SYNTAX DisplayString >+ MAX-ACCESS read-only >+ STATUS current >+ DESCRIPTION >+ "The label of the sensor." >+ ::= { hrSensorEntry 4 } >+ >+hrSensorValue OBJECT-TYPE >+ SYNTAX DisplayString >+ MAX-ACCESS read-only >+ STATUS current >+ DESCRIPTION >+ "The value of the sensor" >+ ::= { hrSensorEntry 5 } >+ > -- Conformance information > > hrMIBCompliances OBJECT IDENTIFIER ::= { hrMIBAdminInfo 2 } >@@ -1456,6 +1517,13 @@ > "The Installed Software Group. > Implementation of this group is at the discretion > of the implementor." >+ >+ GROUP hrSensorGroup >+ DESCRIPTION >+ "The Sensors Group. >+ Implementation of this group is at the discretion >+ of the implementor." >+ > ::= { hrMIBCompliances 1 } > > hrSystemGroup OBJECT-GROUP >@@ -1537,4 +1605,17 @@ > "The Host Resources Installed Software Group." > ::= { hrMIBGroups 6 } > >+ hrSensorGroup OBJECT-GROUP >+ OBJECTS { >+ hrSensorEntry, >+ hrSensorNumber, >+ hrSensorMapping, >+ hrSensorName, >+ hrSensorLabel, >+ hrSensorValue >+ } >+ STATUS current >+ DESCRIPTION >+ "The Sensor Resources Group." >+ ::= { hrMIBGroups 7 } > END
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 57450
:
35669
| 35670 |
35899
|
35900