Changeset 4462

Show
Ignore:
Timestamp:
06/25/07 15:32:27 (7 years ago)
Author:
khali
Message:

libsensors: Kill procfs support, part 1.

Location:
lm-sensors/branches/lm-sensors-3.0.0
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/CHANGES

    r4459 r4462  
    1515           Delete support of non-sensor drivers (ddcmon, eeprom) 
    1616           Always build with sysfs support 
     17           Delete procfs support (Linux 2.4) 
    1718  Man page sensors.conf.5: Update the chip statement section 
    1819  Programs doc/*: Delete, obsolete 
  • lm-sensors/branches/lm-sensors-3.0.0/kernel/include/sensors.h

    r4397 r4462  
    2828 * been upgraded to the new model (dynamic discovery of chip features.) 
    2929 */ 
    30  
    31  
    32 /* From linux/i2c-proc.h */ 
    33  
    34 /* Sysctl IDs */ 
    35 #ifdef DEV_HWMON 
    36 #define DEV_SENSORS DEV_HWMON 
    37 #else                           /* ndef DEV_HWMOM */ 
    38 #define DEV_SENSORS 2           /* The id of the lm_sensors directory within the 
    39                                    dev table */ 
    40 #endif                          /* def DEV_HWMON */ 
    41  
    42 /* The maximum length of the prefix */ 
    43 #define SENSORS_PREFIX_MAX 20 
    44  
    45 #define SENSORS_CHIPS 1 
    46 struct i2c_chips_data { 
    47         int sysctl_id; 
    48         char name[SENSORS_PREFIX_MAX + 13]; 
    49 }; 
    5030 
    5131 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/init.c

    r4208 r4462  
    2222#include "sensors.h" 
    2323#include "data.h" 
    24 #include "proc.h" 
    2524#include "error.h" 
    2625#include "access.h" 
     
    4342  int res; 
    4443  sensors_cleanup(); 
    45   if (sensors_init_sysfs()) { 
    46     if ((res = sensors_read_sysfs_bus()) || (res = sensors_read_sysfs_chips())) 
    47       return res; 
    48   } else { 
    49     if ((res = sensors_read_proc_bus()) || (res = sensors_read_proc_chips())) 
    50       return res; 
    51   } 
     44  if (!sensors_init_sysfs()) 
     45    return -SENSORS_ERR_PROC; 
     46  if ((res = sensors_read_sysfs_bus()) || (res = sensors_read_sysfs_chips())) 
     47    return res; 
    5248  if ((res = sensors_scanner_init(input))) 
    5349    return -SENSORS_ERR_PARSE; 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/proc.c

    r4357 r4462  
    1818*/ 
    1919 
    20 #include <sys/types.h> 
    21 #include <sys/sysctl.h> 
    22 #include <stddef.h> 
    23 #include <unistd.h> 
    2420#include <stdio.h> 
    2521#include <string.h> 
     
    2723#include <dirent.h> 
    2824 
    29 #include "kernel/include/sensors.h" 
    3025#include "data.h" 
    3126#include "error.h" 
    3227#include "access.h" 
    3328#include "general.h" 
    34 #include "sysfs.h" 
    35  
    36 /* OK, this proves one thing: if there are too many chips detected, we get in 
    37    trouble. The limit is around 4096/sizeof(struct sensors_chip_data), which 
    38    works out to about 100 entries right now. That seems sensible enough, 
    39    but if we ever get at the point where more chips can be detected, we must 
    40    enlarge buf, and check that sysctl can handle larger buffers. */ 
    41  
    42 #define BUF_LEN 4096 
    43  
    44 static char buf[BUF_LEN]; 
    4529 
    4630static int getsysname(const sensors_chip_feature *feature, char *sysname, 
    4731        int *sysmag, char *altsysname); 
    4832 
    49 /* This reads /proc/sys/dev/sensors/chips into memory */ 
    50 int sensors_read_proc_chips(void) 
    51 { 
    52   int res; 
    53  
    54   int name[3] = { CTL_DEV, DEV_SENSORS, SENSORS_CHIPS }; 
    55   size_t buflen = BUF_LEN; 
    56   char *bufptr = buf; 
    57   sensors_proc_chips_entry entry; 
    58   int lineno; 
    59  
    60   if (sysctl(name, 3, bufptr, &buflen, NULL, 0)) 
    61     return -SENSORS_ERR_PROC; 
    62  
    63   lineno = 1; 
    64   while (buflen >= sizeof(struct i2c_chips_data)) { 
    65     if ((res =  
    66           sensors_parse_chip_name(((struct i2c_chips_data *) bufptr)->name,  
    67                                    &entry.name))) { 
    68       sensors_parse_error("Parsing /proc/sys/dev/sensors/chips",lineno); 
    69       return res; 
    70     } 
    71     entry.sysctl = ((struct i2c_chips_data *) bufptr)->sysctl_id; 
    72     sensors_add_proc_chips(&entry); 
    73     bufptr += sizeof(struct i2c_chips_data); 
    74     buflen -= sizeof(struct i2c_chips_data); 
    75     lineno++; 
    76   } 
    77   return 0; 
    78 } 
    79  
    80 int sensors_read_proc_bus(void) 
    81 { 
    82   FILE *f; 
    83   char line[255]; 
    84   char *border; 
    85   sensors_bus entry; 
    86   int lineno; 
    87  
    88   f = fopen("/proc/bus/i2c","r"); 
    89   if (!f) 
    90     return -SENSORS_ERR_PROC; 
    91   lineno=1; 
    92   while (fgets(line,255,f)) { 
    93     if (strlen(line) > 0) 
    94       line[strlen(line)-1] = '\0'; 
    95     if (! (border = rindex(line,'\t'))) 
    96       goto ERROR; 
    97     /* Skip algorithm name */ 
    98     *border='\0'; 
    99     if (! (border = rindex(line,'\t'))) 
    100       goto ERROR; 
    101     if (! (entry.adapter = strdup(border + 1))) 
    102       goto FAT_ERROR; 
    103     *border='\0'; 
    104     if (! (border = rindex(line,'\t'))) 
    105       goto ERROR; 
    106     *border='\0'; 
    107     if (strncmp(line,"i2c-",4)) 
    108       goto ERROR; 
    109     if (sensors_parse_i2cbus_name(line,&entry.number)) 
    110       goto ERROR; 
    111     sensors_strip_of_spaces(entry.adapter); 
    112     sensors_add_proc_bus(&entry); 
    113     lineno++; 
    114   } 
    115   fclose(f); 
    116   return 0; 
    117 FAT_ERROR: 
    118   sensors_fatal_error("sensors_read_proc_bus","Allocating entry"); 
    119 ERROR: 
    120   sensors_parse_error("Parsing /proc/bus/i2c",lineno); 
    121   fclose(f); 
    122   return -SENSORS_ERR_PROC; 
    123 } 
    124      
    125  
    126 /* This returns the first detected chip which matches the name */ 
    127 static int sensors_get_chip_id(sensors_chip_name name) 
    128 { 
    129   int i; 
    130   for (i = 0; i < sensors_proc_chips_count; i++) 
    131     if (sensors_match_chip(name, sensors_proc_chips[i].name)) 
    132       return sensors_proc_chips[i].sysctl; 
    133   return -SENSORS_ERR_NO_ENTRY; 
    134 } 
    135    
    136 /* This reads a feature /proc or /sys file. 
     33/* This reads a feature from a sysfs file. 
    13734   Sysfs uses a one-value-per file system... 
    13835*/ 
    13936int sensors_read_proc(sensors_chip_name name, int feature, double *value) 
    14037{ 
    141         int sysctl_name[4] = { CTL_DEV, DEV_SENSORS }; 
    14238        const sensors_chip_feature *the_feature; 
    143         size_t buflen = BUF_LEN; 
    14439        int mag; 
    145  
    146         if (!sensors_found_sysfs) 
    147                 if ((sysctl_name[2] = sensors_get_chip_id(name)) < 0) 
    148                         return sysctl_name[2]; 
     40        char n[NAME_MAX], altn[NAME_MAX]; 
     41        FILE *f; 
     42 
    14943        if (! (the_feature = sensors_lookup_feature_nr(name.prefix,feature))) 
    15044                return -SENSORS_ERR_NO_ENTRY; 
    151         if (sensors_found_sysfs) { 
    152                 char n[NAME_MAX], altn[NAME_MAX]; 
    153                 FILE *f; 
    154                 strcpy(n, name.busname); 
    155                 strcat(n, "/"); 
    156                 strcpy(altn, n); 
    157                 /* use rindex to append sysname to n */ 
    158                 getsysname(the_feature, rindex(n, '\0'), &mag, rindex(altn, '\0')); 
    159                 if ((f = fopen(n, "r")) != NULL 
    160                  || (f = fopen(altn, "r")) != NULL) { 
    161                         int res = fscanf(f, "%lf", value); 
    162                         fclose(f); 
    163                         if (res != 1) 
    164                                 return -SENSORS_ERR_PROC; 
    165                         for (; mag > 0; mag --) 
    166                                 *value /= 10.0; 
    167                 } else 
     45 
     46        strcpy(n, name.busname); 
     47        strcat(n, "/"); 
     48        strcpy(altn, n); 
     49        /* use rindex to append sysname to n */ 
     50        getsysname(the_feature, rindex(n, '\0'), &mag, rindex(altn, '\0')); 
     51        if ((f = fopen(n, "r")) != NULL 
     52         || (f = fopen(altn, "r")) != NULL) { 
     53                int res = fscanf(f, "%lf", value); 
     54                fclose(f); 
     55                if (res != 1) 
    16856                        return -SENSORS_ERR_PROC; 
    169         } else { 
    170                 sysctl_name[3] = the_feature->sysctl; 
    171                 if (sysctl(sysctl_name, 4, buf, &buflen, NULL, 0)) 
    172                         return -SENSORS_ERR_PROC; 
    173                 *value = *((long *) (buf + the_feature->offset)); 
    174                 for (mag = the_feature->scaling; mag > 0; mag --) 
     57                for (; mag > 0; mag --) 
    17558                        *value /= 10.0; 
    176                 for (; mag < 0; mag ++) 
    177                         *value *= 10.0; 
    178         } 
     59        } else 
     60                return -SENSORS_ERR_PROC; 
     61 
    17962        return 0; 
    18063} 
     
    18265int sensors_write_proc(sensors_chip_name name, int feature, double value) 
    18366{ 
    184         int sysctl_name[4] = { CTL_DEV, DEV_SENSORS }; 
    18567        const sensors_chip_feature *the_feature; 
    186         size_t buflen = BUF_LEN; 
    18768        int mag; 
     69        char n[NAME_MAX], altn[NAME_MAX]; 
     70        FILE *f; 
    18871  
    189         if (!sensors_found_sysfs) 
    190                 if ((sysctl_name[2] = sensors_get_chip_id(name)) < 0) 
    191                         return sysctl_name[2]; 
    19272        if (! (the_feature = sensors_lookup_feature_nr(name.prefix,feature))) 
    19373                return -SENSORS_ERR_NO_ENTRY; 
    194         if (sensors_found_sysfs) { 
    195                 char n[NAME_MAX], altn[NAME_MAX]; 
    196                 FILE *f; 
    197                 strcpy(n, name.busname); 
    198                 strcat(n, "/"); 
    199                 strcpy(altn, n); 
    200                 /* use rindex to append sysname to n */ 
    201                 getsysname(the_feature, rindex(n, '\0'), &mag, rindex(altn, '\0')); 
    202                 if ((f = fopen(n, "w")) != NULL 
    203                  || (f = fopen(altn, "w")) != NULL) { 
    204                         for (; mag > 0; mag --) 
    205                                 value *= 10.0; 
    206                         fprintf(f, "%d", (int) value); 
    207                         fclose(f); 
    208                 } else 
    209                         return -SENSORS_ERR_PROC; 
    210         } else { 
    211                 sysctl_name[3] = the_feature->sysctl; 
    212                 if (sysctl(sysctl_name, 4, buf, &buflen, NULL, 0)) 
    213                         return -SENSORS_ERR_PROC; 
    214                 /* The following line is known to solve random problems, still it 
    215                    can't be considered a definitive solution... 
    216                 if (sysctl_name[0] != CTL_DEV) { sysctl_name[0] = CTL_DEV ; } */ 
    217                 for (mag = the_feature->scaling; mag > 0; mag --) 
     74 
     75        strcpy(n, name.busname); 
     76        strcat(n, "/"); 
     77        strcpy(altn, n); 
     78        /* use rindex to append sysname to n */ 
     79        getsysname(the_feature, rindex(n, '\0'), &mag, rindex(altn, '\0')); 
     80        if ((f = fopen(n, "w")) != NULL 
     81         || (f = fopen(altn, "w")) != NULL) { 
     82                for (; mag > 0; mag --) 
    21883                        value *= 10.0; 
    219                 for (; mag < 0; mag ++) 
    220                         value /= 10.0; 
    221                 * ((long *) (buf + the_feature->offset)) = (long) value; 
    222                 buflen = the_feature->offset + sizeof(long); 
    223 #ifdef DEBUG 
    224                 /* The following get* calls don't do anything, they are here 
    225                    for debugging purposes only. Strace will show the 
    226                    returned values. */ 
    227                 getuid(); geteuid(); 
    228                 getgid(); getegid(); 
    229 #endif 
    230                 if (sysctl(sysctl_name, 4, NULL, 0, buf, buflen)) 
    231                         return -SENSORS_ERR_PROC; 
    232         } 
     84                fprintf(f, "%d", (int) value); 
     85                fclose(f); 
     86        } else 
     87                return -SENSORS_ERR_PROC; 
     88 
    23389        return 0; 
    23490} 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/proc.h

    r3093 r4462  
    2121#define SENSORS_LIB_PROC_H 
    2222 
    23 /* Read /proc/sys/dev/sensors/chips */ 
    24 extern int sensors_read_proc_chips(void); 
    25  
    26 /* Read /proc/bus/i2c */ 
    27 extern int sensors_read_proc_bus(void); 
    28  
    2923/* Read a value out of a /proc file */ 
    3024extern int sensors_read_proc(sensors_chip_name name, int feature,  
  • lm-sensors/branches/lm-sensors-3.0.0/lib/sysfs.c

    r4420 r4462  
    3131#include "general.h" 
    3232#include "sysfs.h" 
    33  
    34 int sensors_found_sysfs = 0; 
    3533 
    3634char sensors_sysfs_mount[NAME_MAX]; 
     
    201199{ 
    202200        if (sysfs_get_mnt_path(sensors_sysfs_mount, NAME_MAX) == 0) 
    203                 sensors_found_sysfs = 1; 
    204  
    205         return sensors_found_sysfs; 
     201                return 1; 
     202 
     203        return 0; 
    206204} 
    207205 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/sysfs.h

    r4458 r4462  
    2121#define SENSORS_LIB_SYSFS_H 
    2222 
    23 extern int sensors_found_sysfs; 
    24  
    2523extern char sensors_sysfs_mount[]; 
    2624