diff --git a/lib/access.c b/lib/access.c index 7d77702c..c4156eb0 100644 --- a/lib/access.c +++ b/lib/access.c @@ -116,7 +116,6 @@ sensors_chip_feature *sensors_lookup_feature_name(const char *prefix, int sensors_chip_name_has_wildcards(sensors_chip_name chip) { if ((chip.prefix == SENSORS_CHIP_NAME_PREFIX_ANY) || - (chip.bus == SENSORS_CHIP_NAME_BUS_ISA) || (chip.bus == SENSORS_CHIP_NAME_BUS_ANY) || (chip.bus == SENSORS_CHIP_NAME_BUS_ANY_I2C) || (chip.bus == SENSORS_CHIP_NAME_ADDR_ANY)) diff --git a/lib/conf-lex.l b/lib/conf-lex.l index 02866d75..0fda30d1 100644 --- a/lib/conf-lex.l +++ b/lib/conf-lex.l @@ -96,26 +96,31 @@ OCTESC (1[0-7]{0,2})|([2-7][0-7]?)|(0[1-7][0-7]?)|(00[1-7]) /* Some keywords at the beginning of lines */ "label" { + sensors_yylval.line = sensors_yylineno; BEGIN(MIDDLE); return LABEL; } "set" { + sensors_yylval.line = sensors_yylineno; BEGIN(MIDDLE); return SET; } "compute" { + sensors_yylval.line = sensors_yylineno; BEGIN(MIDDLE); return COMPUTE; } "bus" { + sensors_yylval.line = sensors_yylineno; BEGIN(MIDDLE); return BUS; } "chip" { + sensors_yylval.line = sensors_yylineno; BEGIN(MIDDLE); return CHIP; } diff --git a/lib/conf-parse.y b/lib/conf-parse.y index 2ee5f935..4122a8c5 100644 --- a/lib/conf-parse.y +++ b/lib/conf-parse.y @@ -89,6 +89,7 @@ static sensors_chip *current_chip = NULL; sensors_expr *expr; int bus; sensors_chip_name chip; + int line; } %left '-' '+' @@ -97,11 +98,11 @@ static sensors_chip *current_chip = NULL; %token ',' %token EOL -%token BUS -%token LABEL -%token SET -%token CHIP -%token COMPUTE +%token BUS +%token LABEL +%token SET +%token CHIP +%token COMPUTE %token FLOAT %token NAME %token ERROR @@ -133,6 +134,7 @@ line: bus_statement EOL bus_statement: BUS i2cbus_name adapter_name algorithm_name { sensors_bus new_el; + new_el.lineno = $1; new_el.number = $2; new_el.adapter = $3; new_el.algorithm = $4; @@ -143,6 +145,7 @@ bus_statement: BUS i2cbus_name adapter_name algorithm_name label_statement: LABEL function_name string { sensors_label new_el; check_current_chip(); + new_el.lineno = $1; new_el.name = $2; new_el.value = $3; label_add_el(&new_el); @@ -152,6 +155,7 @@ label_statement: LABEL function_name string set_statement: SET function_name expression { sensors_set new_el; check_current_chip(); + new_el.lineno = $1; new_el.name = $2; new_el.value = $3; set_add_el(&new_el); @@ -161,6 +165,7 @@ set_statement: SET function_name expression compute_statement: COMPUTE function_name expression ',' expression { sensors_compute new_el; check_current_chip(); + new_el.lineno = $1; new_el.name = $2; new_el.from_proc = $3; new_el.to_proc = $5; @@ -170,6 +175,7 @@ compute_statement: COMPUTE function_name expression ',' expression chip_statement: CHIP chip_name_list { sensors_chip new_el; + new_el.lineno = $1; new_el.labels = NULL; new_el.sets = NULL; new_el.computes = NULL; diff --git a/lib/data.c b/lib/data.c index 50c8543b..9cb92d75 100644 --- a/lib/data.c +++ b/lib/data.c @@ -198,6 +198,7 @@ int sensors_parse_i2cbus_name(const char *name, int *res) } } + int sensors_eval_expr(sensors_expr *expr, double val, double *result) { double res1,res2; diff --git a/lib/data.h b/lib/data.h index 02f88343..3c96f45b 100644 --- a/lib/data.h +++ b/lib/data.h @@ -54,17 +54,20 @@ typedef struct sensors_expr { typedef struct sensors_label { char *name; char *value; + int lineno; } sensors_label; typedef struct sensors_set { char *name; sensors_expr *value; + int lineno; } sensors_set; typedef struct sensors_compute { char *name; sensors_expr *from_proc; sensors_expr *to_proc; + int lineno; } sensors_compute; typedef struct sensors_chip_name_list { @@ -84,6 +87,7 @@ typedef struct sensors_chip { sensors_compute *computes; int computes_count; int computes_max; + int lineno; } sensors_chip; typedef enum sensors_bus_type {sensors_i2c, sensors_isa, @@ -93,6 +97,7 @@ typedef struct sensors_bus { int number; char *adapter; char *algorithm; + int lineno; } sensors_bus; typedef struct sensors_proc_chips_entry { @@ -100,6 +105,7 @@ typedef struct sensors_proc_chips_entry { sensors_chip_name name; } sensors_proc_chips_entry; + extern sensors_chip *sensors_config_chips; extern int sensors_config_chips_count; extern int sensors_config_chips_max; @@ -112,6 +118,10 @@ extern sensors_proc_chips_entry *sensors_proc_chips; extern int sensors_proc_chips_count; extern int sensors_proc_chips_max; +extern sensors_bus *sensors_proc_bus; +extern int sensors_proc_bus_count; +extern int sensors_proc_bus_max; + /* Parse an i2c bus name into its components. Returns 0 on succes, a value from error.h on failure. */ extern int sensors_parse_i2cbus_name(const char *name, int *res); diff --git a/lib/init.c b/lib/init.c index 431c424c..bf3574e7 100644 --- a/lib/init.c +++ b/lib/init.c @@ -18,12 +18,14 @@ */ #include +#include #include "sensors.h" #include "data.h" #include "proc.h" #include "error.h" extern int sensors_yyparse(void); +extern FILE *sensors_yyin; static void free_proc_chips_entry(sensors_proc_chips_entry entry); static void free_chip_name(sensors_chip_name name); @@ -34,12 +36,15 @@ static void free_set(sensors_set set); static void free_compute(sensors_compute compute); static void free_expr(sensors_expr *expr); -int sensors_init(void) +int sensors_init(FILE *input) { int res; sensors_cleanup(); if ((res = sensors_read_proc_chips())) return res; + if ((res = sensors_read_proc_bus())) + return res; + sensors_yyin = input; if ((res = sensors_yyparse())) return SENSORS_ERR_PARSE; return 0; @@ -66,6 +71,12 @@ void sensors_cleanup(void) free(sensors_config_chips); sensors_config_chips = NULL; sensors_config_chips_count = sensors_config_chips_max = 0; + + for (i = 0; i < sensors_proc_bus_count; i++) + free_bus(sensors_proc_bus[i]); + free(sensors_proc_bus); + sensors_proc_bus = NULL; + sensors_proc_bus_count = sensors_proc_bus_max = 0; } void free_proc_chips_entry(sensors_proc_chips_entry entry) diff --git a/lib/proc.c b/lib/proc.c index faac3c23..f01c1fb6 100644 --- a/lib/proc.c +++ b/lib/proc.c @@ -18,6 +18,8 @@ */ #include +#include +#include #include #include #include "src/sensors.h" @@ -36,6 +38,14 @@ static char buf[BUF_LEN]; +sensors_proc_chips_entry *sensors_proc_chips; +int sensors_proc_chips_count; +int sensors_proc_chips_max; + +sensors_bus *sensors_proc_bus; +int sensors_proc_bus_count; +int sensors_proc_bus_max; + static int sensors_get_chip_id(sensors_chip_name name); #define add_proc_chips(el) sensors_add_array_el(el,\ @@ -44,6 +54,12 @@ static int sensors_get_chip_id(sensors_chip_name name); &sensors_proc_chips_max,\ sizeof(struct sensors_proc_chips_entry)) +#define add_bus(el) sensors_add_array_el(el,\ + (void **) &sensors_proc_bus,\ + &sensors_proc_bus_count,\ + &sensors_proc_bus_max,\ + sizeof(struct sensors_bus)) + /* This reads /proc/sys/dev/sensors/chips into memory */ int sensors_read_proc_chips(void) { @@ -69,6 +85,45 @@ int sensors_read_proc_chips(void) return 0; } +int sensors_read_proc_bus(void) +{ + FILE *f; + char line[255]; + char *border; + sensors_bus entry; + f = fopen("/proc/bus/i2c","r"); + if (!f) + return -SENSORS_ERR_PROC; + while (fgets(line,255,f)) { + if (! (border = rindex(line,'\t'))) + goto ERROR; + if (! (entry.algorithm = strdup(border+1))) + goto FAT_ERROR; + *border='\0'; + if (! (border = rindex(line,'\t'))) + goto ERROR; + if (! (entry.adapter = strdup(border + 1))) + goto FAT_ERROR; + *border='\0'; + if (! (border = rindex(line,'\t'))) + goto ERROR; + *border='\0'; + if (strncmp(line,"i2c-",4)) + goto ERROR; + if (sensors_parse_i2cbus_name(line,&entry.number)) + goto ERROR; + add_bus(&entry); + } + fclose(f); + return 0; +FAT_ERROR: + sensors_fatal_error("sensors_read_proc_bus","Allocating entry"); +ERROR: + fclose(f); + return -SENSORS_ERR_PROC; +} + + /* This returns the first detected chip which matches the name */ int sensors_get_chip_id(sensors_chip_name name) { diff --git a/lib/sensors.h b/lib/sensors.h index 04d2b108..aa7171bf 100644 --- a/lib/sensors.h +++ b/lib/sensors.h @@ -20,6 +20,8 @@ #ifndef LIB_SENSORS_SENSORS_H #define LIB_SENSORS_SENSORS_H +#include + /* Publicly accessible library functions */ #define SENSORS_CHIP_NAME_PREFIX_ANY NULL @@ -35,13 +37,12 @@ typedef struct sensors_chip_name { } sensors_chip_name; /* (Re)load the configuration file and the detected chips list. */ -extern int sensors_init(void); +extern int sensors_init(FILE *input); /* Strictly optional clean-up function: You can't access anything after this, until the next sensors_init() call! */ extern void sensors_cleanup(void); - /* Parse a chip name to the internal representation. Return 0 on succes, <0 on error. */ extern int sensors_parse_chip_name(const char *orig_name,