Skip to contentSkip to conversation

libsensors: Make

PATCH In review Jean Delvare 1 participant 2 messages Feb 4, 2009 – Feb 6, 2009 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 3/4 libsensors: Make

Make it possible to only substitute the bus number of a subset of the chip entries. This is a prerequisite to add support for multiple configuration files. Each configuration file can come with its own bus statements and the bus number substitution should only affect chip entries from the same configuration file.

---
 lib/data.c |    5 +++--
 lib/data.h |    4 ++--
 lib/init.c |    3 ++-
 3 files changed, 7 insertions(+), 5 deletions(-)
lib/data.c +3 -2
@@ -226,13 +226,13 @@ static int sensors_substitute_chip(senso
 	return 0;
 }
 
-int sensors_substitute_busses(void)
+int sensors_substitute_busses(int *from)
 {
 	int err, i, j, lineno;
 	sensors_chip_name_list *chips;
 	int res = 0;
 
-	for (i = 0; i < sensors_config_chips_count; i++) {
+	for (i = *from; i < sensors_config_chips_count; i++) {
 		lineno = sensors_config_chips[i].lineno;
 		chips = &sensors_config_chips[i].chips;
 		for (j = 0; j < chips->fits_count; j++) {
@@ -246,5 +246,6 @@ int sensors_substitute_busses(void)
 				res = err;
 		}
 	}
+	*from = sensors_config_chips_count;
 	return res;
 }
lib/data.h +2 -2
@@ -157,8 +157,8 @@ extern int sensors_proc_bus_max;
 	&sensors_proc_bus_max, sizeof(struct sensors_bus))
 
 /* Substitute configuration bus numbers with real-world bus numbers
-   in the chips lists */
-int sensors_substitute_busses(void);
+   in the chips lists, starting from the given chip entry number */
+int sensors_substitute_busses(int *from);
 
 
 /* Parse a bus id into its components. Returns 0 on succes, a value from
lib/init.c +2 -1
@@ -80,6 +80,7 @@ static void free_config_busses(void)
 static int parse_config(FILE *input)
 {
 	int err;
+	static int from = 0;
 
 	if (sensors_scanner_init(input)) {
 		err = -SENSORS_ERR_PARSE;
@@ -92,7 +93,7 @@ static int parse_config(FILE *input)
 		goto exit_cleanup;
 	}
 
-	err = sensors_substitute_busses();
+	err = sensors_substitute_busses(&from);
 
 exit_cleanup:
 	free_config_busses();
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw

Reviewing my own patch...

Quoted 53 lines · Jean Delvare

Make it possible to only substitute the bus number of a subset of the chip entries. This is a prerequisite to add support for multiple configuration files. Each configuration file can come with its own bus statements and the bus number substitution should only affect chip entries from the same configuration file.

---
 lib/data.c |    5 +++--
 lib/data.h |    4 ++--
 lib/init.c |    3 ++-
 3 files changed, 7 insertions(+), 5 deletions(-)
lib/data.c +3 -2
@@ -226,13 +226,13 @@ static int sensors_substitute_chip(senso
 	return 0;
 }
 
-int sensors_substitute_busses(void)
+int sensors_substitute_busses(int *from)
 {
 	int err, i, j, lineno;
 	sensors_chip_name_list *chips;
 	int res = 0;
 
-	for (i = 0; i < sensors_config_chips_count; i++) {
+	for (i = *from; i < sensors_config_chips_count; i++) {
 		lineno = sensors_config_chips[i].lineno;
 		chips = &sensors_config_chips[i].chips;
 		for (j = 0; j < chips->fits_count; j++) {
@@ -246,5 +246,6 @@ int sensors_substitute_busses(void)
 				res = err;
 		}
 	}
+	*from = sensors_config_chips_count;
 	return res;
 }
lib/data.h +2 -2
@@ -157,8 +157,8 @@ extern int sensors_proc_bus_max;
 	&sensors_proc_bus_max, sizeof(struct sensors_bus))
 
 /* Substitute configuration bus numbers with real-world bus numbers
-   in the chips lists */
-int sensors_substitute_busses(void);
+   in the chips lists, starting from the given chip entry number */
+int sensors_substitute_busses(int *from);
 
 
 /* Parse a bus id into its components. Returns 0 on succes, a value from

lib/init.c static void free_config_busses(void) · line 83

Quoted 4 lines
lib/init.c +1 -0
@@ -80,6 +80,7 @@ static void free_config_busses(void)
 static int parse_config(FILE *input)
 {
 	int err;
+	static int from = 0;

This breaks if the application is ever reloading the configuration file using sensors_cleanup() and sensors_init() again. I'll have to come up with a different approach, most likely involving a global variable that can be reset in sensors_cleanup().

Quoted 13 lines
lib/init.c +1 -1
 	if (sensors_scanner_init(input)) {
 		err = -SENSORS_ERR_PARSE;
@@ -92,7 +93,7 @@ static int parse_config(FILE *input)
 		goto exit_cleanup;
 	}
 
-	err = sensors_substitute_busses();
+	err = sensors_substitute_busses(&from);
 
 exit_cleanup:
 	free_config_busses();
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors