All of lore.kernel.org
 help / color / mirror / Atom feed
* [lm-sensors] [PATCH 1/6] libsensors: Exit the configuration file
@ 2009-02-11 16:39 Jean Delvare
  0 siblings, 0 replies; only message in thread
From: Jean Delvare @ 2009-02-11 16:39 UTC (permalink / raw)
  To: lm-sensors

Exit the configuration file parser as soon as we are done with it.

---
 lib/init.c |   31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

--- lm-sensors.orig/lib/init.c	2009-02-10 21:43:20.000000000 +0100
+++ lm-sensors/lib/init.c	2009-02-10 22:00:25.000000000 +0100
@@ -61,6 +61,20 @@ static int sensors_parse(void)
 	return res;
 }
 
+static int parse_config(FILE *input)
+{
+	int err;
+
+	if (sensors_scanner_init(input))
+		return -SENSORS_ERR_PARSE;
+	err = sensors_parse();
+	sensors_scanner_exit();
+	if (err)
+		return -SENSORS_ERR_PARSE;
+
+	return 0;
+}
+
 int sensors_init(FILE *input)
 {
 	int res;
@@ -71,10 +85,9 @@ int sensors_init(FILE *input)
 	    (res = sensors_read_sysfs_chips()))
 		goto exit_cleanup;
 
-	res = -SENSORS_ERR_PARSE;
 	if (input) {
-		if (sensors_scanner_init(input) ||
-		    sensors_parse())
+		res = parse_config(input);
+		if (res)
 			goto exit_cleanup;
 	} else {
 		/* No configuration provided, use default */
@@ -82,14 +95,14 @@ int sensors_init(FILE *input)
 		if (!input && errno = ENOENT)
 			input = fopen(ALT_CONFIG_FILE, "r");
 		if (input) {
-			if (sensors_scanner_init(input) ||
-			    sensors_parse()) {
-				fclose(input);
-				goto exit_cleanup;
-			}
+			res = parse_config(input);
 			fclose(input);
+			if (res)
+				goto exit_cleanup;
+
 		} else if (errno != ENOENT) {
 			sensors_parse_error(strerror(errno), 0);
+			res = -SENSORS_ERR_PARSE;
 			goto exit_cleanup;
 		}
 	}
@@ -197,8 +210,6 @@ void sensors_cleanup(void)
 {
 	int i;
 
-	sensors_scanner_exit();
-
 	for (i = 0; i < sensors_proc_chips_count; i++) {
 		free_chip_name(&sensors_proc_chips[i].chip);
 		free_chip_features(&sensors_proc_chips[i]);

-- 
Jean Delvare

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-02-11 16:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-11 16:39 [lm-sensors] [PATCH 1/6] libsensors: Exit the configuration file Jean Delvare

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.