Skip to contentSkip to conversation

libsensors4: No longer allow reloading

PATCH In review Jean Delvare 2 participants 2 messages Aug 21, 2007 – Aug 22, 2007 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 libsensors4: No longer allow reloading

Drop support for reloading the configuration with sensors_init(). Instead, the application will have to call sensors_exit() explicitly before calling sensors_init() again. Most applications don't offer any way to reload the configuration file, so better optimize for the initial load.

---
 lib/init.c         |    2 +-
 lib/libsensors.3   |    5 ++++-
 lib/sensors.h      |    8 +++++---
 prog/sensord/lib.c |    4 +++-
 4 files changed, 13 insertions(+), 6 deletions(-)
lib/init.c +1 -1
@@ -40,7 +40,7 @@ static void free_expr(sensors_expr *expr
 int sensors_init(FILE *input)
 {
   int res;
-  sensors_cleanup();
+
   if (!sensors_init_sysfs())
     return -SENSORS_ERR_PROC;
   if ((res = sensors_read_sysfs_bus()) || (res = sensors_read_sysfs_chips()))
lib/libsensors.3 +4 -1
@@ -53,7 +53,10 @@ libsensors \- publicly accessible functi
 .SH DESCRIPTION
 .B int sensors_init(FILE *input);
 .br
-(Re)load the configuration file and the detected chips list. If this returns a value unequal to zero, you are in trouble; you can not assume anything will be initialized properly.
+Load the configuration file and the detected chips list. If this returns a
+value unequal to zero, you are in trouble; you can not assume anything will
+be initialized properly. If you want to reload the configuration file, call
+sensors_cleanup() below before calling sensors_init() again.
 
 .B void sensors_cleanup(void);
 .br
lib/sensors.h +5 -3
@@ -56,9 +56,11 @@ typedef struct sensors_chip_name {
 	char *path;
 } sensors_chip_name;
 
-/* (Re)load the configuration file and the detected chips list. If this
-    returns a value unequal to zero, you are in trouble; you can not
-    assume anything will be initialized properly. */
+/* Load the configuration file and the detected chips list. If this
+   returns a value unequal to zero, you are in trouble; you can not
+   assume anything will be initialized properly. If you want to
+   reload the configuration file, call sensors_cleanup() below before
+   calling sensors_init() again. */
 int sensors_init(FILE *input);
 
 /* Clean-up function: You can't access anything after
prog/sensord/lib.c +3 -1
@@ -90,8 +90,10 @@ loadConfig
     sensorLog (LOG_ERR, "Error stating sensors configuration file: %s", cfgPath);
     ret = 10;
   } else if (!reload || (difftime (stats.st_mtime, cfgLastModified) > 0.0)) {
-    if (reload)
+    if (reload) {
       sensorLog (LOG_INFO, "configuration reloading");
+      sensors_cleanup ();
+    }
     if (!(cfg = fopen (cfgPath, "r"))) {
       sensorLog (LOG_ERR, "Error opening sensors configuration file: %s", cfgPath);
       ret = 11;
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw
Quoted 6 lines · Jean Delvare

Drop support for reloading the configuration with sensors_init(). Instead, the application will have to call sensors_exit() explicitly before calling sensors_init() again. Most applications don't offer any way to reload the configuration file, so better optimize for the initial load.

Looks good to me. This reminds me I still need to test current svn, but I'm awefully busy atm (back at work from vacation), I'll give svn a spin when I find the time.

Regards,

Hans

Quoted 54 lines
---
 lib/init.c         |    2 +-
 lib/libsensors.3   |    5 ++++-
 lib/sensors.h      |    8 +++++---
 prog/sensord/lib.c |    4 +++-
 4 files changed, 13 insertions(+), 6 deletions(-)
lib/init.c +1 -1
@@ -40,7 +40,7 @@ static void free_expr(sensors_expr *expr
 int sensors_init(FILE *input)
 {
   int res;
-  sensors_cleanup();
+
   if (!sensors_init_sysfs())
     return -SENSORS_ERR_PROC;
   if ((res = sensors_read_sysfs_bus()) || (res = sensors_read_sysfs_chips()))
lib/libsensors.3 +4 -1
@@ -53,7 +53,10 @@ libsensors \- publicly accessible functi
 .SH DESCRIPTION
 .B int sensors_init(FILE *input);
 .br
-(Re)load the configuration file and the detected chips list. If this returns a value unequal to zero, you are in trouble; you can not assume anything will be initialized properly.
+Load the configuration file and the detected chips list. If this returns a
+value unequal to zero, you are in trouble; you can not assume anything will
+be initialized properly. If you want to reload the configuration file, call
+sensors_cleanup() below before calling sensors_init() again.
 
 .B void sensors_cleanup(void);
 .br
lib/sensors.h +5 -3
@@ -56,9 +56,11 @@ typedef struct sensors_chip_name {
 	char *path;
 } sensors_chip_name;
 
-/* (Re)load the configuration file and the detected chips list. If this
-    returns a value unequal to zero, you are in trouble; you can not
-    assume anything will be initialized properly. */
+/* Load the configuration file and the detected chips list. If this
+   returns a value unequal to zero, you are in trouble; you can not
+   assume anything will be initialized properly. If you want to
+   reload the configuration file, call sensors_cleanup() below before
+   calling sensors_init() again. */
 int sensors_init(FILE *input);
 
 /* Clean-up function: You can't access anything after
prog/sensord/lib.c +0 -0
@@ -90,8 +90,10 @@ loadConfig
     sensorLog (LOG_ERR, "Error stating sensors configuration file: %s", cfgPath);

prog/sensord/lib.c loadConfig · line 99

Quoted 10 lines
prog/sensord/lib.c +3 -1
     ret = 10;
   } else if (!reload || (difftime (stats.st_mtime, cfgLastModified) > 0.0)) {
-    if (reload)
+    if (reload) {
       sensorLog (LOG_INFO, "configuration reloading");
+      sensors_cleanup ();
+    }
     if (!(cfg = fopen (cfgPath, "r"))) {
       sensorLog (LOG_ERR, "Error opening sensors configuration file: %s", cfgPath);
       ret = 11;

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