Changeset 4550

Show
Ignore:
Timestamp:
07/04/07 09:54:37 (6 years ago)
Author:
jwrdegoede
Message:

Add support for foo#_label sysfs files

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/lib/access.c

    r4545 r4550  
    152152        const sensors_chip *chip; 
    153153        const sensors_chip_feature *featureptr; 
     154        char buf[128], path[PATH_MAX]; 
     155        FILE *f; 
    154156        int i; 
    155157 
     
    163165                for (i = 0; i < chip->labels_count; i++) 
    164166                        if (!strcasecmp(featureptr->data.name,chip->labels[i].name)){ 
    165                                 if (*result) 
    166                                         free(*result); 
    167                                 if (!(*result = strdup(chip->labels[i].value))) 
    168                                         sensors_fatal_error("sensors_get_label", 
    169                                                             "Allocating label text"); 
    170                                 return 0; 
     167                                *result = strdup(chip->labels[i].value); 
     168                                goto sensors_get_label_exit; 
    171169                        } 
    172170 
     171        /* No user specified label, check for a _label sysfs file */ 
     172        snprintf(path, PATH_MAX, "%s/%s_label", name.busname, 
     173                featureptr->data.name); 
     174         
     175        if ((f = fopen(path, "r"))) { 
     176                i = fread(buf, 1, sizeof(buf) - 1, f); 
     177                fclose(f); 
     178                if (i > 0) { 
     179                        /* i - 1 to strip the '\n' at the end */ 
     180                        buf[i - 1] = 0; 
     181                        *result = strdup(buf); 
     182                        goto sensors_get_label_exit; 
     183                } 
     184        } 
     185 
    173186        /* No label, return the feature name instead */ 
    174         if (!(*result = strdup(featureptr->data.name))) 
     187        *result = strdup(featureptr->data.name); 
     188         
     189sensors_get_label_exit: 
     190        if (*result == NULL) 
    175191                sensors_fatal_error("sensors_get_label", 
    176192                                    "Allocating label text");