~ubuntu-branches/ubuntu/wily/net-snmp/wily-proposed

« back to all changes in this revision

Viewing changes to agent/mibgroup/ucd-snmp/lmSensors.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-06-28 14:59:36 UTC
  • mfrom: (1.2.3 upstream) (1.1.12 sid)
  • Revision ID: james.westby@ubuntu.com-20100628145936-cbiallic69pn044g
Tags: 5.4.3~dfsg-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Set Ubuntu maintainer address.
  - net-snmp-config: Use bash. (LP: #104738)
  - Removed multiuser option when calling update-rc.d. (LP: #254261)
  - debian/snmpd.init: LSBify the init script.
  - debian/patches/52_fix_snmpcmd_1_typo.patch: Adjust a typo in snmpcmd.1
    (LP: #250459)
  - debian/snmpd.postinst: source debconf before doing work, LP: #589056
  - debian/snmp.preinst, debian/snmp.prerm: kill any/all processes owned by
    snmp user before install/uninstall, LP: #573391
  - Add apport hook (LP: #533603):
  - debian/{snmp,snmpd}.apport: Added.
  - debian/control: Build-depends on dh-apport.
  - debian/rules: 
    + Add --with apport.
    + override_dh_apport to install hook on snmpd package only.
 * Dropped patches:
   - debian/patches/99-fix-ubuntu-div0.patch: Fix dvision by zero.. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
    #include </usr/platform/sun4u/include/sys/envctrl.h>
90
90
#else
91
91
    #include <sensors/sensors.h>
92
 
    #define CONFIG_FILE_NAME "/etc/sensors.conf"
93
92
#endif
94
93
 
95
94
#include "lmSensors.h"
247
246
                   size_t * var_len, WriteMethod ** write_method)
248
247
{
249
248
    static long     long_ret;
250
 
    static unsigned char string[SPRINT_MAX_LEN];
 
249
    static char string[SPRINT_MAX_LEN];
251
250
 
252
251
    int             s_index;
253
252
    int             s_type = -1;
352
351
{
353
352
    int             res;
354
353
#ifndef solaris2
355
 
    char            filename[] = CONFIG_FILE_NAME;
356
354
    time_t          t = time(NULL);
357
 
    FILE            *fp = fopen(filename, "r");
358
355
    int             i = 0;
359
356
  
360
357
    DEBUGMSG(("ucd-snmp/lmSensors", "=> sensor_init\n"));
366
363
        sensor_array[i].sensor = NULL;
367
364
    }
368
365
 
369
 
    if (!fp)
370
 
    {
371
 
        res = 1;
372
 
        goto leaving;
373
 
    }
374
 
 
375
 
    if (sensors_init(fp))
 
366
    if (sensors_init(NULL))
376
367
    {
377
368
        res = 2;
378
369
        goto leaving;
390
381
sensor_load(void)
391
382
{
392
383
    int rc = 0;
393
 
    time_t         t = time(NULL);
 
384
    time_t        t = time(NULL);
394
385
 
395
386
    if (t > timestamp + 7) /* this may require some tuning - currently 7 seconds*/
396
387
    {
940
931
#else /* end solaris2 only ie. ifdef everything else */
941
932
 
942
933
    const sensors_chip_name *chip;
943
 
    const sensors_feature_data *data;
 
934
    const sensors_feature *feature;
 
935
    const sensors_subfeature *subfeature;
944
936
    int             chip_nr = 0;
945
937
    int             rc = 0;
946
938
    unsigned int    i = 0;
961
953
        sensor_array[i].current_len = DEFAULT_SENSORS;
962
954
    } /* end for */
963
955
 
964
 
    while ((chip = sensors_get_detected_chips(&chip_nr))) {
965
 
        int             a = 0;
966
 
        int             b = 0;
967
 
 
968
 
        while ((data = sensors_get_all_features(*chip, &a, &b))) {
969
 
            char           *label = NULL;
970
 
            double          val;
971
 
 
972
 
            if ((data->mode & SENSORS_MODE_R) &&
973
 
                (data->mapping == SENSORS_NO_MAPPING) &&
974
 
                !sensors_get_label(*chip, data->number, &label) &&
975
 
                !sensors_get_feature(*chip, data->number, &val)) {
976
 
                int             type = -1;
977
 
                float           mul;
978
 
                _sensor_array  *array;
979
 
 
980
 
                /* The label, as determined for a given chip in sensors.conf,
981
 
                 * is used to place each sensor in the appropriate bucket.
982
 
                 * Volt, Fan, Temp, and Misc.  If the text being looked for below
983
 
                 * is not in the label of a given sensor (e.g., the temp1 sensor
984
 
                 * has been labeled 'CPU' and not 'CPU temp') it will end up being
985
 
                 * lumped in the MISC bucket. */
986
 
 
987
 
                if (strstr(label, "V")) {
988
 
                    type = VOLT_TYPE;
989
 
                    mul = 1000.0;
990
 
                }
991
 
                if (strstr(label, "fan") || strstr(label, "Fan")) {
992
 
                    type = FAN_TYPE;
993
 
                    mul = 1.0;
994
 
                }
995
 
                if (strstr(label, "temp") || strstr(label, "Temp")) {
996
 
                    type = TEMP_TYPE;
997
 
                    mul = 1000.0;
998
 
                }
999
 
                if (type == -1) {
1000
 
                    type = MISC_TYPE;
1001
 
                    mul = 1000.0;
1002
 
                }
1003
 
 
1004
 
                array = &sensor_array[type];
1005
 
                if ( array->current_len <= array->n) {
1006
 
                    _sensor* old_buffer = array->sensor;
1007
 
                    size_t new_size = (sizeof(_sensor) * array->current_len) + (sizeof(_sensor) * DEFAULT_SENSORS);
1008
 
                    array->sensor = (_sensor*)realloc(array->sensor, new_size);
1009
 
                    if (array->sensor == NULL)
1010
 
                    {
1011
 
                       /* Continuing would be unsafe */
1012
 
                       snmp_log(LOG_ERR, "too many sensors to fit, and failed to alloc more, failing on %s\n", label);
1013
 
                       free(old_buffer);
1014
 
                       old_buffer = NULL;
1015
 
                       if (label) {
1016
 
                           free(label);
1017
 
                           label = NULL;
1018
 
                       } /* end if label */
1019
 
                       return (rc=1);
1020
 
                    } /* end if array->sensor */
1021
 
                    array->current_len = new_size / sizeof(_sensor);
1022
 
                    DEBUGMSG(("ucd-snmp/lmSensors", "type #%d increased to %d elements\n", type, array->current_len));
1023
 
                } /* end if array->current */
1024
 
                strncpy(array->sensor[array->n].name, label, MAX_NAME);
1025
 
                array->sensor[array->n].value = (int) (val * mul);
1026
 
                DEBUGMSGTL(("sensors","sensor %d, value %d\n",
1027
 
                            array->sensor[array->n].name,
1028
 
                            array->sensor[array->n].value));
1029
 
                array->n++;
1030
 
            } /* end if data-mode */
1031
 
            if (label) {
1032
 
                free(label);
1033
 
                label = NULL;
1034
 
            } /* end if label */
1035
 
        } /* end while data */
 
956
    while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
 
957
        int             a = 0;
 
958
        while ((feature = sensors_get_features(chip, &a))) {
 
959
            int             b = 0;
 
960
            while ((subfeature = sensors_get_all_subfeatures(chip,
 
961
                    feature, &b))) {
 
962
                char           *label = NULL;
 
963
                double          val;
 
964
 
 
965
                if ((subfeature->flags & SENSORS_MODE_R) &&
 
966
                    (label = sensors_get_label(chip, feature)) &&
 
967
                    !sensors_get_value(chip, subfeature->number, &val)) {
 
968
                    int             type = -1;
 
969
                    float           mul;
 
970
                    _sensor_array  *array;
 
971
 
 
972
                    /* The label, as determined for a given chip in
 
973
                     * sensors.conf, is used to place each sensor in the
 
974
                     * appropriate bucket.  Volt, Fan, Temp, and Misc.
 
975
                     * If the text being looked for below is not in the
 
976
                     * label of a given sensor (e.g., the temp1 sensor
 
977
                     * has been labeled 'CPU' and not 'CPU temp') it
 
978
                     * will end up being lumped in the MISC bucket. */
 
979
 
 
980
                    if (strstr(label, "V")) {
 
981
                        type = VOLT_TYPE;
 
982
                        mul = 1000.0;
 
983
                    }
 
984
                    if (strstr(label, "fan") || strstr(label, "Fan")) {
 
985
                        type = FAN_TYPE;
 
986
                        mul = 1.0;
 
987
                    }
 
988
                    if (strstr(label, "temp") || strstr(label, "Temp")) {
 
989
                        type = TEMP_TYPE;
 
990
                        mul = 1000.0;
 
991
                    }
 
992
                    if (type == -1) {
 
993
                        type = MISC_TYPE;
 
994
                        mul = 1000.0;
 
995
                    }
 
996
 
 
997
                    array = &sensor_array[type];
 
998
                    if ( array->current_len <= array->n) {
 
999
                        _sensor* old_buffer = array->sensor;
 
1000
                        size_t new_size = (sizeof(_sensor) * array->current_len) + (sizeof(_sensor) * DEFAULT_SENSORS);
 
1001
                        array->sensor = (_sensor*)realloc(array->sensor, new_size);
 
1002
                        if (array->sensor == NULL)
 
1003
                        {
 
1004
                           /* Continuing would be unsafe */
 
1005
                           snmp_log(LOG_ERR, "too many sensors to fit, and failed to alloc more, failing on %s\n", label);
 
1006
                           free(old_buffer);
 
1007
                           old_buffer = NULL;
 
1008
                           if (label) {
 
1009
                               free(label);
 
1010
                               label = NULL;
 
1011
                           } /* end if label */
 
1012
                           return (rc=1);
 
1013
                        } /* end if array->sensor */
 
1014
                        array->current_len = new_size / sizeof(_sensor);
 
1015
                        DEBUGMSG(("ucd-snmp/lmSensors", "type #%d increased to %d elements\n", type, array->current_len));
 
1016
                    } /* end if array->current */
 
1017
                    strncpy(array->sensor[array->n].name, label, MAX_NAME);
 
1018
                    array->sensor[array->n].value = (int) (val * mul);
 
1019
                    DEBUGMSGTL(("sensors","sensor %d, value %d\n",
 
1020
                                array->sensor[array->n].name,
 
1021
                                array->sensor[array->n].value));
 
1022
                    array->n++;
 
1023
                } /* end if data-mode */
 
1024
                if (label) {
 
1025
                    free(label);
 
1026
                    label = NULL;
 
1027
                } /* end if label */
 
1028
            } /* end while subfeature */
 
1029
        } /* end while feature */
1036
1030
    } /* end while chip */
1037
1031
    return rc;
1038
1032
#endif  /* end else ie. ifdef everything else */