From 8da58cadf841e67ef2a474de37054109267f2b64 Mon Sep 17 00:00:00 2001 From: Danny Kukawka Date: Thu, 6 Dec 2007 20:33:18 +0100 Subject: [PATCH] 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. --- hald/util_pm.c | 22 ++++++++++++++++++++-- 1 files changed, 20 insertions(+), 2 deletions(-) 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; } -- 1.5.3.7