Changeset 3094
- Timestamp:
- 09/18/05 22:37:42 (8 years ago)
- Location:
- lm-sensors/trunk/lib
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/lib/init.c
r3093 r3094 42 42 int res; 43 43 sensors_cleanup(); 44 sensors_init_sysfs();45 44 if ((res = sensors_read_proc_chips())) 46 45 return res; 47 if ((res = sensors_read_proc_bus())) 48 return res; 46 if (sensors_init_sysfs()) { 47 if ((res = sensors_read_sysfs_bus())) 48 return res; 49 } else { 50 if ((res = sensors_read_proc_bus())) 51 return res; 52 } 49 53 sensors_yyin = input; 50 54 if ((res = sensors_yyparse())) -
lm-sensors/trunk/lib/proc.c
r3093 r3094 215 215 int sensors_read_proc_bus(void) 216 216 { 217 struct dirent *de; 218 DIR *dir; 219 FILE *f; 220 char line[255]; 221 char *border; 222 sensors_bus entry; 223 int lineno; 224 char sysfs[NAME_MAX], n[NAME_MAX]; 225 char dirname[NAME_MAX]; 226 227 if (sensors_found_sysfs) { 228 strncpy(sysfs, sensors_sysfs_mount, sizeof(sysfs) - 1); 229 sysfs[sizeof(sysfs) - 1] = 0; 230 strncat(sysfs, "/class/i2c-adapter", 231 sizeof(sysfs) - strlen(sysfs) - 1); 232 233 /* Then read from it */ 234 dir = opendir(sysfs); 235 if (! dir) 236 goto proc; 237 238 while ((de = readdir(dir)) != NULL) { 239 if (!strcmp(de->d_name, ".")) 240 continue; 241 if (!strcmp(de->d_name, "..")) 242 continue; 243 244 strcpy(n, sysfs); 245 strcat(n, "/"); 246 strcat(n, de->d_name); 247 strcpy(dirname, n); 248 strcat(n, "/device/name"); 249 250 if ((f = fopen(n, "r")) != NULL) { 251 char x[120]; 252 fgets(x, 120, f); 253 fclose(f); 254 if((border = index(x, '\n')) != NULL) 255 *border = 0; 256 entry.adapter=strdup(x); 257 if(!strncmp(x, "ISA ", 4)) { 258 entry.number = SENSORS_CHIP_NAME_BUS_ISA; 259 entry.algorithm = strdup("ISA bus algorithm"); 260 } else if(!sscanf(de->d_name, "i2c-%d", &entry.number)) { 261 entry.number = SENSORS_CHIP_NAME_BUS_DUMMY; 262 entry.algorithm = strdup("Dummy bus algorithm"); 263 } else 264 entry.algorithm = strdup("Unavailable from sysfs"); 265 if (entry.algorithm == NULL) 266 goto FAT_ERROR_SYS; 267 sensors_add_proc_bus(&entry); 268 } 269 } 270 closedir(dir); 271 return 0; 272 FAT_ERROR_SYS: 273 sensors_fatal_error("sensors_read_proc_bus", "Allocating entry"); 274 closedir(dir); 275 return -SENSORS_ERR_PROC; 276 } 277 278 proc: 217 FILE *f; 218 char line[255]; 219 char *border; 220 sensors_bus entry; 221 int lineno; 279 222 280 223 f = fopen("/proc/bus/i2c","r"); -
lm-sensors/trunk/lib/sysfs.c
r3093 r3094 21 21 #include <limits.h> 22 22 #include <sysfs/libsysfs.h> 23 #include "data.h" 24 #include "error.h" 25 #include "access.h" 26 #include "general.h" 23 27 #include "sysfs.h" 24 28 … … 35 39 return sensors_found_sysfs; 36 40 } 41 42 /* returns 0 if successful, !0 otherwise */ 43 int sensors_read_sysfs_bus(void) 44 { 45 struct sysfs_class *cls; 46 struct dlist *clsdevs; 47 struct sysfs_class_device *clsdev; 48 sensors_bus entry; 49 int ret = 0; 50 51 if (!(cls = sysfs_open_class("i2c-adapter"))) { 52 ret = -SENSORS_ERR_PROC; 53 goto exit0; 54 } 55 56 if (!(clsdevs = sysfs_get_class_devices(cls))) { 57 ret = -SENSORS_ERR_PROC; 58 goto exit1; 59 } 60 61 dlist_for_each_data(clsdevs, clsdev, struct sysfs_class_device) { 62 struct sysfs_device *dev; 63 struct sysfs_attribute *attr; 64 65 if (!(dev = sysfs_get_classdev_device(clsdev))) 66 continue; 67 if (!(attr = sysfs_get_device_attr(dev, "name"))) 68 continue; 69 70 entry.adapter = strdup(attr->value); 71 if (!entry.adapter) 72 sensors_fatal_error(__FUNCTION__, "out of memory"); 73 74 if (!strncmp(entry.adapter, "ISA ", 4)) { 75 entry.number = SENSORS_CHIP_NAME_BUS_ISA; 76 entry.algorithm = strdup("ISA bus algorithm"); 77 } else if (sscanf(clsdev->name, "i2c-%d", &entry.number) != 1) { 78 entry.number = SENSORS_CHIP_NAME_BUS_DUMMY; 79 entry.algorithm = strdup("Dummy bus algorithm"); 80 } else 81 entry.algorithm = strdup("Unavailable from sysfs"); 82 83 if (!entry.algorithm) 84 sensors_fatal_error(__FUNCTION__, "out of memory"); 85 86 sensors_add_proc_bus(&entry); 87 } 88 89 exit1: 90 /* this frees *cls _and_ *clsdevs */ 91 sysfs_close_class(cls); 92 93 exit0: 94 return ret; 95 } 96 -
lm-sensors/trunk/lib/sysfs.h
r3093 r3094 27 27 extern int sensors_init_sysfs(void); 28 28 29 extern int sensors_read_sysfs_bus(void); 30 29 31 #endif /* !SENSORS_LIB_SYSFS_H */
