Gentoo Archives: gentoo-commits

From: "Samuli Suominen (ssuominen)" <ssuominen@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in sys-power/acpitool/files: acpitool-0.5.1-kernel3.patch acpitool-0.5.1-wakeup.patch acpitool-0.5.1-battery.patch acpitool-0.5.1-ac_adapter.patch
Date: Mon, 30 Jan 2012 14:46:10
Message-Id: 20120130144558.7C7C72004B@flycatcher.gentoo.org
1 ssuominen 12/01/30 14:45:58
2
3 Added: acpitool-0.5.1-kernel3.patch
4 acpitool-0.5.1-wakeup.patch
5 acpitool-0.5.1-battery.patch
6 acpitool-0.5.1-ac_adapter.patch
7 Log:
8 Fix compability with Linux 3.x wrt #377355 by Damien Thébault. Fix reading of values from ac_adapters and batteries. Rewrite part of the wakeup code. This will also close #337565 (overflow revealed by _FORTIFY_SOURCE) by Diego Elio Pettenò.
9
10 (Portage version: 2.2.0_alpha84/cvs/Linux x86_64)
11
12 Revision Changes Path
13 1.1 sys-power/acpitool/files/acpitool-0.5.1-kernel3.patch
14
15 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-power/acpitool/files/acpitool-0.5.1-kernel3.patch?rev=1.1&view=markup
16 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-power/acpitool/files/acpitool-0.5.1-kernel3.patch?rev=1.1&content-type=text/plain
17
18 Index: acpitool-0.5.1-kernel3.patch
19 ===================================================================
20 http://bugs.gentoo.org/377355
21
22 --- src/acpitool.cpp
23 +++ src/acpitool.cpp
24 @@ -205,8 +205,7 @@
25 Kernel_24 = 1;
26 Kernel_26 = 0;
27 }
28 -
29 - if(strncmp(str,"2.6",3)==0)
30 + else
31 {
32 Kernel_24 = 0;
33 Kernel_26 = 1;
34
35
36
37 1.1 sys-power/acpitool/files/acpitool-0.5.1-wakeup.patch
38
39 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-power/acpitool/files/acpitool-0.5.1-wakeup.patch?rev=1.1&view=markup
40 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-power/acpitool/files/acpitool-0.5.1-wakeup.patch?rev=1.1&content-type=text/plain
41
42 Index: acpitool-0.5.1-wakeup.patch
43 ===================================================================
44 From 3a87a4132667f78fc85c54ad89992bbdd02d1e55 Mon Sep 17 00:00:00 2001
45 From: Carlos Alberto Lopez Perez <clopez@××××××.com>
46 Date: Thu, 6 Oct 2011 03:12:55 +0200
47 Subject: [PATCH] Use dynamic structures instead of predefined ones
48
49 * The file /proc/acpi/wakeup can have much more than 25 entries.
50 In my computer (Dell E6420) I have 27 entries.
51 So instead of using an array of [x] entries better use dynamic
52 vectors and push the new entries when a new line from the file
53 is read.
54
55 * The name of the device is not ever 4 characters. For example I
56 have a device called "LID" which is 3 characters long.
57 Instead of using a fixed size for the device we split the line
58 on the first tab (\t) and use the first part.
59 ---
60 src/acpitool.cpp | 23 +++++++++++------------
61 1 files changed, 11 insertions(+), 12 deletions(-)
62
63 diff --git a/src/acpitool.cpp b/src/acpitool.cpp
64 index 2a610a5..71e01d7 100644
65 --- a/src/acpitool.cpp
66 +++ b/src/acpitool.cpp
67 @@ -460,16 +460,14 @@ int Show_WakeUp_Devices(int verbose)
68
69 int Toggle_WakeUp_Device(const int Device, int verbose)
70 {
71 - ifstream file_in;
72 ofstream file_out;
73 - char *filename, str[50];
74 - int index = 1;
75 - char Name[25][5]; // 25 should be enough I guess, I have only 9 so far //
76 -
77 + char *filename; string str;
78 + int index = 1; int charindex = 0;
79 + std::vector <std::string> Name(index); // Never is enough, use dynamic structures //
80 filename = "/proc/acpi/wakeup";
81
82 - file_in.open(filename);
83 - if (!file_in)
84 + ifstream file_in(filename, ifstream::in);
85 + if (!file_in.good()) // if opening is not successful
86 {
87 if(!verbose)
88 {
89 @@ -484,14 +482,15 @@ int Toggle_WakeUp_Device(const int Device, int verbose)
90 }
91 }
92
93 - file_in.getline(str, 50); // first line are just headers //
94 + getline(file_in, str); // first line are just headers //
95 while(!file_in.eof()) // count all devices and store their names//
96 {
97 - file_in.getline(str, 50);
98 - if(strlen(str)!=0) // avoid empty last line //
99 + getline(file_in, str);
100 + if( str.length() != 0 ) // avoid empty last line //
101 {
102 - memset(Name[index], '\0', 5);
103 - strncpy(Name[index], str, 4);
104 + charindex = 0; // reset to zero
105 + while ( (str[++charindex]!='\t') ); // stop on first tab and get the array index
106 + Name.push_back(str.substr(0,charindex)); // Push the name into the vector
107 index++;
108 }
109 }
110 --
111 1.7.5.4
112
113
114
115
116
117 1.1 sys-power/acpitool/files/acpitool-0.5.1-battery.patch
118
119 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-power/acpitool/files/acpitool-0.5.1-battery.patch?rev=1.1&view=markup
120 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-power/acpitool/files/acpitool-0.5.1-battery.patch?rev=1.1&content-type=text/plain
121
122 Index: acpitool-0.5.1-battery.patch
123 ===================================================================
124 Author: Evgeni Golov <evgeni@××××××.org>, Michael Meskes <meskes@××××××.org>
125 Description: Fix reading of battery information.
126
127 --- src/acpitool.h
128 +++ src/acpitool.h
129 @@ -39,6 +39,9 @@
130 char Serial[13];
131 char Bat_Type[13];
132 char Voltage_Now[13];
133 + char Charge_Now[13];
134 + char Charge_Full[13];
135 + char Charge_Full_Design[13];
136 };
137
138
139 --- src/battery.cpp
140 +++ src/battery.cpp
141 @@ -107,6 +107,9 @@
142 memset(Batt_Info[i]->Serial, '\0', 13);
143 memset(Batt_Info[i]->Bat_Type, '\0', 13);
144 memset(Batt_Info[i]->Voltage_Now, '\0', 13);
145 + memset(Batt_Info[i]->Charge_Now, '\0', 13);
146 + memset(Batt_Info[i]->Charge_Full, '\0', 13);
147 + memset(Batt_Info[i]->Charge_Full_Design, '\0', 13);
148
149 // initialize all struct members to blanks --> avoid rubbish in output //
150
151 @@ -139,7 +142,12 @@
152 case 1 :
153 {
154 Present_Batteries++;
155 - Remaining_Percentage = float(atoi(Batt_Info[i]->Remaining_Cap)) / float(atoi(Batt_Info[i]->LastFull_Cap)) * 100.0;
156 +
157 + if (strcmp(Batt_Info[i]->Charge_Now,"")!=0 &&
158 + strcmp(Batt_Info[i]->Charge_Now,"unknown")!=0)
159 + Remaining_Percentage = float(atoi(Batt_Info[i]->Charge_Now)) / float(atoi(Batt_Info[i]->Charge_Full)) * 100.0;
160 + else
161 + Remaining_Percentage = float(atoi(Batt_Info[i]->Remaining_Cap)) / float(atoi(Batt_Info[i]->LastFull_Cap)) * 100.0;
162
163 /* from Alan Pope : some broken Dell batteries report a remaining capacity bigger
164 than their last full capacity or their design capacity. This led acpitool to report
165 @@ -153,19 +161,24 @@
166 else
167 Precision = 4;
168
169 - if( strncmp(Batt_Info[i]->Charging_State,"char",4)==0 )
170 + if(strncasecmp(Batt_Info[i]->Charging_State,"char",4)==0)
171 {
172 Is_Charging = 1;
173 }
174 else
175 {
176 - if(strncmp(Batt_Info[i]->Charging_State,"disch",5)==0) Is_Discharging = 1;
177 + if(strncasecmp(Batt_Info[i]->Charging_State,"disch",5)==0) Is_Discharging = 1;
178 }
179
180 if(Show_Time) // calculate remaining or charging time only if present battery rate != 0 //
181 {
182 - if(Is_Charging)
183 - Remaining_Time = (float(atoi(Batt_Info[i]->LastFull_Cap)) - float(atoi(Batt_Info[i]->Remaining_Cap))) / float(atoi(Batt_Info[i]->Present_Rate));
184 + if(Is_Charging) {
185 + if (strcmp(Batt_Info[i]->Charge_Now,"")!=0 &&
186 + strcmp(Batt_Info[i]->Charge_Now,"unknown")!=0)
187 + Remaining_Time = (float(atoi(Batt_Info[i]->Charge_Full)) - float(atoi(Batt_Info[i]->Charge_Now))) / float(atoi(Batt_Info[i]->Present_Rate));
188 + else
189 + Remaining_Time = (float(atoi(Batt_Info[i]->LastFull_Cap)) - float(atoi(Batt_Info[i]->Remaining_Cap))) / float(atoi(Batt_Info[i]->Present_Rate));
190 + }
191 else
192 Remaining_Time = float(atoi(Batt_Info[i]->Remaining_Cap)) / float(atoi(Batt_Info[i]->Present_Rate));
193 // this represents hours //
194 @@ -180,9 +193,11 @@
195 Minutes = Time_In_Seconds / 60;
196 Time_In_Seconds = Time_In_Seconds - (Minutes * 60);
197 }
198 -
199 +
200 if(atoi(Batt_Info[i]->Design_Cap) > 0)
201 Battery_Left_Percent = float(atoi(Batt_Info[i]->LastFull_Cap)) / float(atoi(Batt_Info[i]->Design_Cap)) * 100.0;
202 + else if(atoi(Batt_Info[i]->Charge_Full_Design) > 0)
203 + Battery_Left_Percent = float(atoi(Batt_Info[i]->Charge_Full)) / float(atoi(Batt_Info[i]->Charge_Full_Design)) * 100.0;
204 else
205 Battery_Left_Percent = -1.0;
206
207 @@ -207,8 +222,15 @@
208 <<setfill('0')<<setw(2)<<Time_In_Seconds;
209 cout<<endl;
210
211 - cout<<" Design capacity : "<<Batt_Info[i]->Design_Cap<<endl;
212 - cout<<" Last full capacity : "<<Batt_Info[i]->LastFull_Cap;
213 + if(atoi(Batt_Info[i]->Design_Cap) > 0)
214 + cout<<" Design capacity : "<<Batt_Info[i]->Design_Cap<<endl;
215 + else if(atoi(Batt_Info[i]->Charge_Full_Design) > 0)
216 + cout<<" Design capacity : "<<Batt_Info[i]->Charge_Full_Design<<endl;
217 +
218 + if(atoi(Batt_Info[i]->LastFull_Cap) > 0)
219 + cout<<" Last full capacity : "<<Batt_Info[i]->LastFull_Cap;
220 + else if(atoi(Batt_Info[i]->Charge_Full) > 0)
221 + cout<<" Last full capacity : "<<Batt_Info[i]->Charge_Full;
222
223 if(Battery_Left_Percent<100.0)
224 {
225 @@ -327,7 +349,7 @@
226
227
228
229 -int Get_Battery_Info_from_Proc(const int bat_nr, Battery_Info *bat_info, int verbose)
230 +int Get_Battery_Info_from_Proc(const int bat_nr, Battery_Info *batt_info, int verbose)
231 {
232 ifstream file_in;
233 char filename[4][65], str[100], temp[100];
234 @@ -378,7 +400,7 @@
235 {
236 if(!verbose)
237 {
238 - bat_info->Battery_Present = 2; // 2 represents error value //
239 + batt_info->Battery_Present = 2; // 2 represents error value //
240 return 0;
241 }
242 else
243 @@ -422,24 +444,24 @@
244 file_in.getline(str, 100);
245 strncpy(temp, str+25, 4);
246 if(strncmp(temp,"yes",3)==0)
247 - bat_info->Battery_Present = 1; //yes, we have a battery //
248 + batt_info->Battery_Present = 1; //yes, we have a battery //
249 else
250 {
251 - bat_info->Battery_Present = 0;
252 + batt_info->Battery_Present = 0;
253 return 0; //bail out if battery is not present //
254 }
255
256 // then get the design capacity //
257 file_in.getline(str, 100);
258 - strncpy(bat_info->Design_Cap, str+25, 9);
259 + strncpy(batt_info->Design_Cap, str+25, 9);
260
261 // then get the last full capacity //
262 file_in.getline(str, 100);
263 - strncpy(bat_info->LastFull_Cap, str+25, 9);
264 + strncpy(batt_info->LastFull_Cap, str+25, 9);
265
266 - if (strncmp(bat_info->LastFull_Cap,"unknown",7)==0)
267 + if (strncmp(batt_info->LastFull_Cap,"unknown",7)==0)
268 {
269 - bat_info->Battery_Present = 0;
270 + batt_info->Battery_Present = 0;
271 return 0; //bail out if battery is not present //
272 }
273 /* some Dell laptops seem to report a 2nd battery as being present, while it is NOT, but then report the
274 @@ -449,21 +471,21 @@
275
276 // then get the technology //
277 file_in.getline(str, 100);
278 - strncpy(bat_info->Technology, str+25, 12);
279 + strncpy(batt_info->Technology, str+25, 12);
280
281 // then get the model number //
282 for(int t=0; t<5; t++)
283 file_in.getline(str, 100); //skip 5 lines //
284 file_in.getline(str, 100);
285 - strncpy(bat_info->Model, str+25, 12);
286 + strncpy(batt_info->Model, str+25, 12);
287
288 // then get the serial number //
289 file_in.getline(str, 100);
290 - strncpy(bat_info->Serial, str+25, 12);
291 + strncpy(batt_info->Serial, str+25, 12);
292
293 // then get the battery type //
294 file_in.getline(str, 100);
295 - strncpy(bat_info->Bat_Type, str+25, 12);
296 + strncpy(batt_info->Bat_Type, str+25, 12);
297
298 file_in.close();
299
300 @@ -480,17 +502,17 @@
301 // then get the charging state //
302 file_in.getline(str, 100); file_in.getline(str, 100); // skip first 2 lines //
303 file_in.getline(str, 100);
304 - strncpy(bat_info->Charging_State, str+25, 12);
305 - if (strncmp(bat_info->Charging_State,"unknown",7)==0) strncpy(bat_info->Charging_State, "charged",7);
306 + strncpy(batt_info->Charging_State, str+25, 12);
307 + if (strncmp(batt_info->Charging_State,"unknown",7)==0) strncpy(batt_info->Charging_State, "charged",7);
308 /* on older kernels, like 2.4.22, the charging state is reported as "unknown", whereas in recent kernels
309 this was changed to "charged". */
310
311 // then get the charging rate //
312 file_in.getline(str, 100);
313 - strncpy(bat_info->Present_Rate, str+25, 9);
314 - if (strncmp(bat_info->Charging_State,"charged",7)==0)
315 + strncpy(batt_info->Present_Rate, str+25, 9);
316 + if (strncmp(batt_info->Charging_State,"charged",7)==0)
317 {
318 - if (strncmp(bat_info->Present_Rate, "unknown",7)==0) strncpy(bat_info->Present_Rate, "0 ",7);
319 + if (strncmp(batt_info->Present_Rate, "unknown",7)==0) strncpy(batt_info->Present_Rate, "0 ",7);
320 }
321 /* some batteries report the present rate as "unknown", even when they report the battery as being charged.
322 If the battery is charged, the rate should be 0 */
323 @@ -498,12 +520,12 @@
324
325 // then get the remaining capacity //
326 file_in.getline(str, 100);
327 - strncpy(bat_info->Remaining_Cap, str+25, 9);
328 + strncpy(batt_info->Remaining_Cap, str+25, 9);
329
330 file_in.close();
331 }
332 else // battery dir is readable but empty : only . and .. at most //
333 - bat_info->Battery_Present = 3;
334 + batt_info->Battery_Present = 3;
335
336 return 0;
337 }
338 @@ -513,8 +535,8 @@
339 int Get_Battery_Info_from_Sys(const int bat_nr, Battery_Info *batt_info, int verbose)
340 {
341 ifstream file_in;
342 - char filename[6][65], str[100], temp[100];
343 - int bat_count = 0, start = 0, findex = 0;
344 + char filename[6][65], str[100], temp[100], attr[100];
345 + int bat_count = 0, start = 0, findex = 0, value = 0;
346 DIR *battery_dir;
347 char *name, *dirname;
348
349 @@ -613,165 +635,104 @@
350 return -1;
351 }
352
353 - memset(str, '\0', 100);
354 - for(int t=0; t<5; t++)
355 - fgets(str, 100, power_fp); /* skip first 5 lines */
356 -
357 - /* get battery status (full, charging, ...) */
358 - memset(str, '\0', 100);
359 - fgets(str, 100, power_fp);
360 - if (strlen(str)>0)
361 - {
362 - memset(temp, '\0', 100);
363 - sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
364 - strncpy(batt_info->Charging_State, temp, 12);
365 - }
366 -
367 -
368 - /* get battery presence (0 or 1) */
369 - memset(str, '\0', 100);
370 - fgets(str, 100, power_fp);
371 - if (strlen(str)>0)
372 - {
373 - memset(temp, '\0', 100);
374 - strncpy(temp, str+21, 1);
375 - if(strncmp(temp,"1",1)==0)
376 - batt_info->Battery_Present = 1; /* yes, we have a battery */
377 - else
378 - {
379 - batt_info->Battery_Present = 0;
380 - printf(" Battery is not present, bailing out. \n");
381 - return 0; /* bail out if battery is not present */
382 - }
383 - }
384 -
385 -
386 - /* get technology */
387 - memset(str, '\0', 100);
388 - fgets(str, 100, power_fp);
389 - if (strlen(str)>0)
390 - {
391 - memset(temp, '\0', 100);
392 - sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
393 - strncpy(batt_info->Technology, temp, 12);
394 - }
395 - else
396 - strncpy(batt_info->Technology, "unknown", 7);
397 -
398 -
399 -
400 - //printf(" \n bat_info_tech = %s \n\n ", batt_info->Technology);
401 -
402 -
403 -
404 - fgets(str, 100, power_fp); /* skip 1 line */
405 -
406 -
407 - /* get voltage_now */
408 - memset(str, '\0', 100);
409 - fgets(str, 100, power_fp);
410 - if (strlen(str)>0)
411 - {
412 - memset(temp, '\0', 100);
413 - sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
414 - strncpy(batt_info->Voltage_Now, temp, 12);
415 - }
416 - else
417 - strncpy(batt_info->Voltage_Now, "unknown", 7);
418 -
419 -
420 - /* get current_now, which I believe is the charging rate ? */
421 - memset(str, '\0', 100);
422 - fgets(str, 100, power_fp);
423 - if (strlen(str)>0)
424 - {
425 - memset(temp, '\0', 100);
426 - sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
427 - strncpy(batt_info->Present_Rate, temp, 12);
428 - }
429 - else
430 - strncpy(batt_info->Present_Rate, "unknown", 7);
431 -
432 -
433 - /* get charge_full_design */
434 - memset(str, '\0', 100);
435 - fgets(str, 100, power_fp);
436 - if (strlen(str)>0)
437 - {
438 - memset(temp, '\0', 100);
439 - sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
440 - strncpy(batt_info->Design_Cap, temp, 12);
441 - }
442 - else
443 - strncpy(batt_info->Design_Cap, "unknown", 7);
444 -
445 -
446 - //printf(" \n bat_info_design_cap = %s \n ", batt_info->Design_Cap);
447 -
448 -
449 - /* get charge_full, which is the last full capacity I guess ? */
450 - memset(str, '\0', 100);
451 - fgets(str, 100, power_fp);
452 - if (strlen(str)>0)
453 - {
454 - memset(temp, '\0', 100);
455 - sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
456 - strncpy(batt_info->LastFull_Cap, temp, 12);
457 - }
458 - else
459 - strncpy(batt_info->LastFull_Cap, "unknown", 7);
460 -
461 -
462 - //printf(" \n bat_info_lastfull_cap = %s \n\n ", batt_info->LastFull_Cap);
463 -
464 -
465 - /* get charge_now */
466 - memset(str, '\0', 100);
467 - fgets(str, 100, power_fp);
468 - if (strlen(str)>0)
469 - {
470 - memset(temp, '\0', 100);
471 - sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
472 - strncpy(batt_info->Remaining_Cap, temp, 12);
473 - }
474 - else
475 - strncpy(batt_info->Remaining_Cap, "unknown", 7);
476 -
477 - //printf(" \n bat_info_remaining_cap = %s \n\n ", batt_info->Remaining_Cap);
478 -
479 -
480 - /* get model_name */
481 - memset(str, '\0', 100);
482 - fgets(str, 100, power_fp);
483 - if (strlen(str)>0)
484 - {
485 - memset(temp, '\0', 100);
486 - strncpy(temp, str+24, 12); // use strncpy here because sscanf chokes on blanks in this one ? //
487 -
488 - memset(str, '\0', 100);
489 - sscanf(temp, "%[^\n]", str); // strip trailing \n, fucks up output //
490 -
491 - strncpy(batt_info->Model, str, 12);
492 + strncpy(batt_info->Technology, "unknown", 7);
493 + strncpy(batt_info->Voltage_Now, "unknown", 7);
494 + strncpy(batt_info->Charge_Now, "unknown", 7);
495 + strncpy(batt_info->Charge_Full, "unknown", 7);
496 + strncpy(batt_info->Charge_Full_Design, "unknown", 7);
497 + strncpy(batt_info->Present_Rate, "unknown", 7);
498 + strncpy(batt_info->Design_Cap, "unknown", 7);
499 + strncpy(batt_info->LastFull_Cap, "unknown", 7);
500 + strncpy(batt_info->Remaining_Cap, "unknown", 7);
501 + strncpy(batt_info->Model, "unknown", 7);
502 + strncpy(batt_info->Serial, "unknown", 7);
503 +
504 + // see linux-2.6/drivers/power/power_supply_sysfs.c
505 + // there can be different number of lines, so read up to 40 lines
506 + for(int t=0; t<40; t++) {
507 + memset(str, '\0', 100);
508 + memset(attr, '\0', 100);
509 + memset(temp, '\0', 100);
510 + fgets(str, 100, power_fp);
511 + sscanf(str, "%[^=]s %*s %*[^\n]", attr);
512 + sscanf(str, "%*[^=] %*c %s %*[^\n]",temp);
513 + if (strcmp(attr,"POWER_SUPPLY_STATUS")==0) {
514 + strncpy(batt_info->Charging_State, temp, 12);
515 + }
516 + else if (strcmp(attr,"POWER_SUPPLY_TYPE")==0) {
517 + strncpy(batt_info->Bat_Type, temp, 12);
518 + }
519 + else if (strcmp(attr,"POWER_SUPPLY_TECHNOLOGY")==0) {
520 + strncpy(batt_info->Technology, temp, 12);
521 + }
522 + else if (strcmp(attr,"POWER_SUPPLY_VOLTAGE_NOW")==0) {
523 + value = atoi(temp) / 1000;
524 + snprintf(temp, sizeof(temp), "%i mV", value);
525 + strncpy(batt_info->Voltage_Now, temp, 12);
526 + }
527 + else if (strcmp(attr,"POWER_SUPPLY_CURRENT_NOW")==0 ||
528 + strcmp(attr,"POWER_SUPPLY_POWER_NOW")==0) {
529 + value = atoi(temp) / 1000;
530 + snprintf(temp, sizeof(temp), "%i", value);
531 + strncpy(batt_info->Present_Rate, temp, 9);
532 + }
533 + else if (strcmp(attr,"POWER_SUPPLY_CHARGE_NOW")==0) {
534 + value = atoi(temp) / 1000;
535 + snprintf(temp, sizeof(temp), "%i mA", value);
536 + strncpy(batt_info->Charge_Now, temp, 12);
537 + }
538 + else if (strcmp(attr,"POWER_SUPPLY_CHARGE_FULL_DESIGN")==0) {
539 + value = atoi(temp) / 1000;
540 + snprintf(temp, sizeof(temp), "%i mA", value);
541 + strncpy(batt_info->Charge_Full_Design, temp, 12);
542 + }
543 + else if (strcmp(attr,"POWER_SUPPLY_CHARGE_FULL")==0) {
544 + value = atoi(temp) / 1000;
545 + snprintf(temp, sizeof(temp), "%i mA", value);
546 + strncpy(batt_info->Charge_Full, temp, 12);
547 + }
548 + else if (strcmp(attr,"POWER_SUPPLY_ENERGY_FULL_DESIGN")==0) {
549 + value = atoi(temp) / 1000;
550 + snprintf(temp, sizeof(temp), "%i mWh", value);
551 + strncpy(batt_info->Design_Cap, temp, 9);
552 + }
553 + else if (strcmp(attr,"POWER_SUPPLY_ENERGY_FULL")==0) {
554 + value = atoi(temp) / 1000;
555 + snprintf(temp, sizeof(temp), "%i mWh", value);
556 + strncpy(batt_info->LastFull_Cap, temp, 9);
557 + }
558 + else if (strcmp(attr,"POWER_SUPPLY_ENERGY_NOW")==0) {
559 + value = atoi(temp) / 1000;
560 + snprintf(temp, sizeof(temp), "%i mWh", value);
561 + strncpy(batt_info->Remaining_Cap, temp, 9);
562 + }
563 + else if (strcmp(attr,"POWER_SUPPLY_MODEL_NAME")==0) {
564 + strncpy(batt_info->Model, temp, 12);
565 + }
566 + else if (strcmp(attr,"POWER_SUPPLY_SERIAL_NUMBER")==0) {
567 + strncpy(batt_info->Serial, temp, 12);
568 + }
569 + else if (strcmp(attr,"POWER_SUPPLY_PRESENT")==0) {
570 + if(strncmp(temp,"1",1)==0) {
571 + batt_info->Battery_Present = 1;
572 + }
573 + else {
574 + batt_info->Battery_Present = 0;
575 + printf(" Battery is not present, bailing out. \n");
576 + return 0;
577 + }
578 + }
579 }
580 + if (strcmp(batt_info->Charge_Now,"")!=0 &&
581 + strcmp(batt_info->Charge_Now,"unknown")!=0)
582 + snprintf(temp, sizeof(temp), "%s mA", batt_info->Present_Rate);
583 else
584 - strncpy(batt_info->Model, "unknown", 7);
585 + snprintf(temp, sizeof(temp), "%s mW", batt_info->Present_Rate);
586
587 - fgets(str, 100, power_fp);
588 + strncpy(batt_info->Present_Rate, temp, 9);
589
590 - /* get serial */
591 - memset(str, '\0', 100);
592 - fgets(str, 100, power_fp);
593 - if (strlen(str)!=0)
594 - {
595 - memset(temp, '\0', 100);
596 - sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
597 - strncpy(batt_info->Serial, temp, 12);
598 - }
599 - else
600 - strncpy(batt_info->Serial, "unknown", 7);
601 -
602 fclose(power_fp);
603 - }
604 + }
605 else // battery dir is readable but empty : only . and .. at most //
606 batt_info->Battery_Present = 3;
607 return 0;
608
609
610
611 1.1 sys-power/acpitool/files/acpitool-0.5.1-ac_adapter.patch
612
613 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-power/acpitool/files/acpitool-0.5.1-ac_adapter.patch?rev=1.1&view=markup
614 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-power/acpitool/files/acpitool-0.5.1-ac_adapter.patch?rev=1.1&content-type=text/plain
615
616 Index: acpitool-0.5.1-ac_adapter.patch
617 ===================================================================
618 Author: Michael Meskes <meskes@××××××.org>
619 Description: Fix reading of ac_adapter information.
620
621 --- src/ac_adapter.cpp
622 +++ src/ac_adapter.cpp
623 @@ -149,7 +149,7 @@
624 int Do_AC_Info_Sys()
625 {
626 ifstream file_in;
627 - char filename[2][65], str[100], temp[100];
628 + char filename[2][65], str[100], temp[100], attr[100];
629 int ac_count = 0, start = 0, findex = 0;
630 DIR *ac_dir;
631 char *name, *dirname;
632 @@ -206,31 +206,40 @@
633
634 if(ac_count>0)
635 {
636 - for(int i=0; i<ac_count; i++) /* I don't expect to find > 1, but you never know */
637 + for(int i=0, t=0; i<ac_count; i++) /* I don't expect to find > 1, but you never know */
638 {
639 FILE *power_fp = fopen(filename[i], "r");
640 if(power_fp)
641 {
642 - for(int t=0; t<5; t++)
643 - fgets(str, 100, power_fp); /* just skip the first 5 lines */
644 -
645 - memset(str, '\0', 100);
646 - fgets(str, 100, power_fp);
647 + // see linux-2.6/drivers/power/power_supply_sysfs.c
648 + // there can be different number of lines, so read up to 40 lines
649 + for(; t<40; t++)
650 + {
651 + memset(str, '\0', 100);
652 + fgets(str, 100, power_fp);
653
654 - if (strlen(str)!=0)
655 - {
656 - memset(temp, '\0', 100);
657 - sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
658 + if (strlen(str)!=0)
659 + {
660 + memset(temp, '\0', 100);
661 + memset(attr, '\0', 100);
662 + sscanf(str, "%[^=]s %*s %[^\n]", attr);
663 + sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
664
665 - /* keep this for debugging */
666 - /* printf(" from Do_AC_SYS: temp = %s \n", temp);*/
667 -
668 - if(strncmp(temp,"1",1)==0)
669 - printf(" AC adapter : online \n");
670 - else
671 - printf(" AC adapter : off-line \n");
672 + /* keep this for debugging */
673 + /* printf(" from Do_AC_SYS: temp = %s \n", temp);*/
674 +
675 + if (strcmp(attr, "POWER_SUPPLY_ONLINE") == 0)
676 + {
677 + if(strncmp(temp,"1",1)==0)
678 + printf(" AC adapter : online \n");
679 + else
680 + printf(" AC adapter : off-line \n");
681 +
682 + break;
683 + }
684 + }
685 }
686 - else
687 + if (t == 40)
688 printf(" AC adapter : <info not available> \n");
689 }
690 else