Magellan Linux

Contents of /trunk/hal/patches/hal-0.5.10-prevent-flood-syslog-if-battery-remaining-time-is-ab.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 597 - (show annotations) (download)
Mon May 19 19:05:19 2008 UTC (16 years ago) by niro
File size: 2198 byte(s)
-gentoo patches

1 From 8da58cadf841e67ef2a474de37054109267f2b64 Mon Sep 17 00:00:00 2001
2 From: Danny Kukawka <danny.kukawka@web.de>
3 Date: Thu, 6 Dec 2007 20:33:18 +0100
4 Subject: [PATCH] prevent flood syslog if battery remaining time is above 60 hours
5
6 This prevents to get the syslog flooded with "remaining_time *very*
7 high, returning -1" warning messages on some laptops. With this patch the
8 message get send only the first 10 times and then only 1 message for each 100
9 cases (we can changes this also to a higher number).
10
11 We have this patch already since several months in the SUSE package, maybe
12 it's usefull in general.
13 ---
14 hald/util_pm.c | 22 ++++++++++++++++++++--
15 1 files changed, 20 insertions(+), 2 deletions(-)
16
17 diff --git a/hald/util_pm.c b/hald/util_pm.c
18 index e412ec5..a5a0e12 100644
19 --- a/hald/util_pm.c
20 +++ b/hald/util_pm.c
21 @@ -39,6 +39,7 @@
22 typedef struct {
23 int last_level;
24 int last_chargeRate;
25 + int high_time_warn_count;
26 time_t last_time;
27 } batteryInfo;
28
29 @@ -160,7 +161,8 @@ util_compute_time_remaining (const char *id,
30 battery_info->last_level = chargeLevel;
31 battery_info->last_time = cur_time;
32 battery_info->last_chargeRate = 0;
33 - return -1;
34 + battery_info->high_time_warn_count = 0;
35 + return -1;
36 }
37 }
38
39 @@ -188,7 +190,23 @@ util_compute_time_remaining (const char *id,
40 }
41 /* Battery life cannot be above 60 hours */
42 else if (remaining_time > 60*60*60) {
43 - HAL_WARNING (("remaining_time *very* high, returning -1"));
44 + batteryInfo *battery_info;
45 +
46 + if (!(battery_info = g_hash_table_lookup(saved_battery_info, id))) {
47 + battery_info = g_new0(batteryInfo, 1);
48 + g_hash_table_insert(saved_battery_info, (char*) id, battery_info);
49 + battery_info->last_level = -1;
50 + battery_info->last_time = -1;
51 + battery_info->last_chargeRate = -1;
52 + battery_info->high_time_warn_count = 0;
53 + }
54 +
55 + /* display the warning only 10 times and then ever 100 calls , should avoid to flood syslog */
56 + if (battery_info->high_time_warn_count < 10 || !(battery_info->high_time_warn_count % 100)) {
57 + HAL_WARNING (("remaining_time *very* high, returning -1"));
58 + battery_info->high_time_warn_count += 1;
59 + }
60 +
61 remaining_time = -1;
62 }
63
64 --
65 1.5.3.7
66