hal: Branch 'master'

Danny Kukawka dkukawka at kemper.freedesktop.org
Thu Dec 6 11:33:31 PST 2007


 hald/util_pm.c |   22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

New commits:
commit 06511843d74d2afa49847f6d957f86718acd6ba8
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Thu Dec 6 20:33:18 2007 +0100

    prevent flood syslog if battery remaining time is above 60 hours
    
    This prevents to get the syslog flooded with "remaining_time *very*
    high, returning -1" warning messages on some laptops. With this patch the
    message get send only the first 10 times and then only 1 message for each 100
    cases (we can changes this also to a higher number).
    
    We have this patch already since several months in the SUSE package, maybe
    it's usefull in general.

diff --git a/hald/util_pm.c b/hald/util_pm.c
index e412ec5..a5a0e12 100644
--- a/hald/util_pm.c
+++ b/hald/util_pm.c
@@ -39,6 +39,7 @@
 typedef struct {
 	int last_level;
 	int last_chargeRate;
+	int high_time_warn_count;
 	time_t last_time;
 } batteryInfo;
 
@@ -160,7 +161,8 @@ util_compute_time_remaining (const char *id,
 			battery_info->last_level = chargeLevel;
 			battery_info->last_time = cur_time;
 			battery_info->last_chargeRate = 0;
- 			return -1;
+ 			battery_info->high_time_warn_count = 0;
+			return -1;
 		}
 	} 
 
@@ -188,7 +190,23 @@ util_compute_time_remaining (const char *id,
 	}
 	/* Battery life cannot be above 60 hours */
 	else if (remaining_time > 60*60*60) {
-		HAL_WARNING (("remaining_time *very* high, returning -1"));
+		batteryInfo *battery_info;
+
+		if (!(battery_info = g_hash_table_lookup(saved_battery_info, id))) {
+			battery_info = g_new0(batteryInfo, 1);
+			g_hash_table_insert(saved_battery_info, (char*) id, battery_info);
+			battery_info->last_level = -1;
+			battery_info->last_time = -1;
+			battery_info->last_chargeRate = -1;
+			battery_info->high_time_warn_count = 0;
+		}
+
+		/* display the warning only 10 times and then ever 100 calls , should  avoid to flood syslog */
+		if (battery_info->high_time_warn_count < 10 || !(battery_info->high_time_warn_count % 100)) {
+			HAL_WARNING (("remaining_time *very* high, returning -1"));
+			battery_info->high_time_warn_count += 1;
+		}
+
 		remaining_time = -1;
 	}
 


More information about the hal-commit mailing list