summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuli Suominen <ssuominen@gentoo.org>2012-01-30 14:45:58 +0000
committerSamuli Suominen <ssuominen@gentoo.org>2012-01-30 14:45:58 +0000
commit4a973721e8dc30593cdd08446a377ca641be7bd4 (patch)
tree8502e20dd9d149fac88376c5239dfc934f51a144 /sys-power
parentVersion bump, bug #393055. (diff)
downloadhistorical-4a973721e8dc30593cdd08446a377ca641be7bd4.tar.gz
historical-4a973721e8dc30593cdd08446a377ca641be7bd4.tar.bz2
historical-4a973721e8dc30593cdd08446a377ca641be7bd4.zip
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ò.
Package-Manager: portage-2.2.0_alpha84/cvs/Linux x86_64
Diffstat (limited to 'sys-power')
-rw-r--r--sys-power/acpitool/ChangeLog15
-rw-r--r--sys-power/acpitool/Manifest21
-rw-r--r--sys-power/acpitool/acpitool-0.5.1-r1.ebuild25
-rw-r--r--sys-power/acpitool/files/acpitool-0.5.1-ac_adapter.patch73
-rw-r--r--sys-power/acpitool/files/acpitool-0.5.1-battery.patch484
-rw-r--r--sys-power/acpitool/files/acpitool-0.5.1-kernel3.patch14
-rw-r--r--sys-power/acpitool/files/acpitool-0.5.1-wakeup.patch70
7 files changed, 699 insertions, 3 deletions
diff --git a/sys-power/acpitool/ChangeLog b/sys-power/acpitool/ChangeLog
index 5f365aa56607..322bf3eca478 100644
--- a/sys-power/acpitool/ChangeLog
+++ b/sys-power/acpitool/ChangeLog
@@ -1,6 +1,17 @@
# ChangeLog for sys-power/acpitool
-# Copyright 1999-2010 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/sys-power/acpitool/ChangeLog,v 1.15 2010/05/24 18:50:26 pacho Exp $
+# Copyright 1999-2012 Gentoo Foundation; Distributed under the GPL v2
+# $Header: /var/cvsroot/gentoo-x86/sys-power/acpitool/ChangeLog,v 1.16 2012/01/30 14:45:58 ssuominen Exp $
+
+*acpitool-0.5.1-r1 (30 Jan 2012)
+
+ 30 Jan 2012; Samuli Suominen <ssuominen@gentoo.org>
+ +acpitool-0.5.1-r1.ebuild, +files/acpitool-0.5.1-ac_adapter.patch,
+ +files/acpitool-0.5.1-battery.patch, +files/acpitool-0.5.1-kernel3.patch,
+ +files/acpitool-0.5.1-wakeup.patch:
+ 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ò.
24 May 2010; Pacho Ramos <pacho@gentoo.org> acpitool-0.5.1.ebuild:
stable amd64, bug 317629
diff --git a/sys-power/acpitool/Manifest b/sys-power/acpitool/Manifest
index 8d7a8c2ba0cb..f193ad4f20fe 100644
--- a/sys-power/acpitool/Manifest
+++ b/sys-power/acpitool/Manifest
@@ -1,4 +1,23 @@
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA1
+
+AUX acpitool-0.5.1-ac_adapter.patch 2259 RMD160 85dea3bbc2968e41adf7fcff418dd7b44268cb6c SHA1 a1b2ba5b4507b40fc50da3ecc112cf99f4fcca42 SHA256 8761325c90dd4d10faeefd662f419ad5c4bc85aefc408506800596b49abef680
+AUX acpitool-0.5.1-battery.patch 17336 RMD160 03d1b02d9c0ce57232f816793ad941ec9fb67289 SHA1 8565ba9a70a450b213d45f51a040cbb94ac26018 SHA256 37190bbc61732809aea917c4568311b681b03808a7340da35df20690d1bbc5cb
+AUX acpitool-0.5.1-kernel3.patch 250 RMD160 b8a9f3f3725f366eb5c8564541865cea488d1b6f SHA1 bc978eb84fc8e1705a7215d2d6d87deb88361cad SHA256 fd9e112dfdf9ea4390d6da6df841542b98434a3d681f4efe5092d33a97826037
+AUX acpitool-0.5.1-wakeup.patch 2570 RMD160 9c12842b5b0fada21e460fed19ba5a2ea811043a SHA1 67a8b58a89e70e531918a35ba91ba992b5f3ca0f SHA256 e9d30451fe203c0392a8e4efac349aed83cff8f5cfc373fe5aaf68355b9f3c48
DIST acpitool-0.5.1.tar.bz2 109584 RMD160 6909c8d05badfb72a9e1212af238bc0c41b9e4c3 SHA1 7c4cdffd09b4c68971cf2e3edd95693cf6b3b740 SHA256 004fb6cd43102918b6302cf537a2db7ceadda04aef2e0906ddf230f820dad34f
+EBUILD acpitool-0.5.1-r1.ebuild 708 RMD160 cacc1faf86f925e356d1141c62ac8f0ab15c62bf SHA1 74bf6f268d0f61047d7bfd803e2d527df1a396f1 SHA256 2fb1e3cda5ca595f4ea41e3475e8b90d6dfe08a379402c96562e6a14ff2d94d7
EBUILD acpitool-0.5.1.ebuild 658 RMD160 609298b4025ed88782802e1601ba48088a5560f7 SHA1 0d641831de240fbe79f91f18a284d964a6d66d7e SHA256 0fef21cb13c1d9deafc5270e74b6ce7f777b9ef6b980dd852a43a5d00013aec4
-MISC ChangeLog 4168 RMD160 5af195d12fbd5598478e1f59532b4bdbbed4a690 SHA1 d958a95d5d33f93a53a2aea70105201896139082 SHA256 0bcfc02dc3f31b9875844f490ad308276ba51dd32d0a5aff1378e38c40e5f7fc
+MISC ChangeLog 4695 RMD160 62f77dc6a0261de905a79a6827804dba41db43e1 SHA1 56b1ae3bc3b3a69665b735dfbc5b31cb56447f86 SHA256 5ac87806a343cf1897e1a47272b439342a10badc1c7833c639f91c022788eee6
MISC metadata.xml 160 RMD160 8521c3bd3ae0fb2bfddce5edb33fd31e223747e1 SHA1 194b7194f38673fe427e5893a42cd4c1506ce846 SHA256 b13062a43e40469b137e1206494a44b45755ea69511b64e5373cb1ce30bbb160
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v2.0.18 (GNU/Linux)
+
+iQEcBAEBAgAGBQJPJqyUAAoJEEdUh39IaPFNPR8H+wSWwTITxT8Jj+6a4BtcAepO
+g9GQbOAo3NhHy9t+faSPgE3HvKVe2IqSyLEG2xeoyxLApPWGEgZExrA+325FIvTr
+hQUIs6I1T7QkqCAHSeeYqW2urDJsa35wqg6joEAxyIYgAaGE6+lgSujM+AA/EbOb
+KLPhIbI/0QPwVaaYwXnspJNIfDlw1CXCZhJk9K5Cnd0Qb7qWxvkhonLrjOca9hSu
+or90+/FcO9bDCHfnqBFk7LQdt1RQGxw911pZ/fwpIySlOTrmKpga+pRygxYbRVn1
+w9LADNTPMtiAs0eTIlg5VmyGBBULKkU3ngEsfRAvi35AfNePfvdElFYf8HZVxzY=
+=dMty
+-----END PGP SIGNATURE-----
diff --git a/sys-power/acpitool/acpitool-0.5.1-r1.ebuild b/sys-power/acpitool/acpitool-0.5.1-r1.ebuild
new file mode 100644
index 000000000000..55b739ae37ab
--- /dev/null
+++ b/sys-power/acpitool/acpitool-0.5.1-r1.ebuild
@@ -0,0 +1,25 @@
+# Copyright 1999-2012 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/sys-power/acpitool/acpitool-0.5.1-r1.ebuild,v 1.1 2012/01/30 14:45:58 ssuominen Exp $
+
+EAPI=4
+inherit eutils
+
+DESCRIPTION="A small command line application, intended to be a replacement for the apm tool"
+HOMEPAGE="http://packages.debian.org/sid/acpitool"
+SRC_URI="mirror://gentoo/${P}.tar.bz2"
+
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="~amd64 ~x86"
+IUSE=""
+
+DOCS="AUTHORS ChangeLog README TODO"
+
+src_prepare() {
+ epatch \
+ "${FILESDIR}"/${P}-ac_adapter.patch \
+ "${FILESDIR}"/${P}-battery.patch \
+ "${FILESDIR}"/${P}-kernel3.patch \
+ "${FILESDIR}"/${P}-wakeup.patch
+}
diff --git a/sys-power/acpitool/files/acpitool-0.5.1-ac_adapter.patch b/sys-power/acpitool/files/acpitool-0.5.1-ac_adapter.patch
new file mode 100644
index 000000000000..070fdf9de1b7
--- /dev/null
+++ b/sys-power/acpitool/files/acpitool-0.5.1-ac_adapter.patch
@@ -0,0 +1,73 @@
+Author: Michael Meskes <meskes@debian.org>
+Description: Fix reading of ac_adapter information.
+
+--- src/ac_adapter.cpp
++++ src/ac_adapter.cpp
+@@ -149,7 +149,7 @@
+ int Do_AC_Info_Sys()
+ {
+ ifstream file_in;
+- char filename[2][65], str[100], temp[100];
++ char filename[2][65], str[100], temp[100], attr[100];
+ int ac_count = 0, start = 0, findex = 0;
+ DIR *ac_dir;
+ char *name, *dirname;
+@@ -206,31 +206,40 @@
+
+ if(ac_count>0)
+ {
+- for(int i=0; i<ac_count; i++) /* I don't expect to find > 1, but you never know */
++ for(int i=0, t=0; i<ac_count; i++) /* I don't expect to find > 1, but you never know */
+ {
+ FILE *power_fp = fopen(filename[i], "r");
+ if(power_fp)
+ {
+- for(int t=0; t<5; t++)
+- fgets(str, 100, power_fp); /* just skip the first 5 lines */
+-
+- memset(str, '\0', 100);
+- fgets(str, 100, power_fp);
++ // see linux-2.6/drivers/power/power_supply_sysfs.c
++ // there can be different number of lines, so read up to 40 lines
++ for(; t<40; t++)
++ {
++ memset(str, '\0', 100);
++ fgets(str, 100, power_fp);
+
+- if (strlen(str)!=0)
+- {
+- memset(temp, '\0', 100);
+- sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
++ if (strlen(str)!=0)
++ {
++ memset(temp, '\0', 100);
++ memset(attr, '\0', 100);
++ sscanf(str, "%[^=]s %*s %[^\n]", attr);
++ sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
+
+- /* keep this for debugging */
+- /* printf(" from Do_AC_SYS: temp = %s \n", temp);*/
+-
+- if(strncmp(temp,"1",1)==0)
+- printf(" AC adapter : online \n");
+- else
+- printf(" AC adapter : off-line \n");
++ /* keep this for debugging */
++ /* printf(" from Do_AC_SYS: temp = %s \n", temp);*/
++
++ if (strcmp(attr, "POWER_SUPPLY_ONLINE") == 0)
++ {
++ if(strncmp(temp,"1",1)==0)
++ printf(" AC adapter : online \n");
++ else
++ printf(" AC adapter : off-line \n");
++
++ break;
++ }
++ }
+ }
+- else
++ if (t == 40)
+ printf(" AC adapter : <info not available> \n");
+ }
+ else
diff --git a/sys-power/acpitool/files/acpitool-0.5.1-battery.patch b/sys-power/acpitool/files/acpitool-0.5.1-battery.patch
new file mode 100644
index 000000000000..76428ca7d970
--- /dev/null
+++ b/sys-power/acpitool/files/acpitool-0.5.1-battery.patch
@@ -0,0 +1,484 @@
+Author: Evgeni Golov <evgeni@debian.org>, Michael Meskes <meskes@debian.org>
+Description: Fix reading of battery information.
+
+--- src/acpitool.h
++++ src/acpitool.h
+@@ -39,6 +39,9 @@
+ char Serial[13];
+ char Bat_Type[13];
+ char Voltage_Now[13];
++ char Charge_Now[13];
++ char Charge_Full[13];
++ char Charge_Full_Design[13];
+ };
+
+
+--- src/battery.cpp
++++ src/battery.cpp
+@@ -107,6 +107,9 @@
+ memset(Batt_Info[i]->Serial, '\0', 13);
+ memset(Batt_Info[i]->Bat_Type, '\0', 13);
+ memset(Batt_Info[i]->Voltage_Now, '\0', 13);
++ memset(Batt_Info[i]->Charge_Now, '\0', 13);
++ memset(Batt_Info[i]->Charge_Full, '\0', 13);
++ memset(Batt_Info[i]->Charge_Full_Design, '\0', 13);
+
+ // initialize all struct members to blanks --> avoid rubbish in output //
+
+@@ -139,7 +142,12 @@
+ case 1 :
+ {
+ Present_Batteries++;
+- Remaining_Percentage = float(atoi(Batt_Info[i]->Remaining_Cap)) / float(atoi(Batt_Info[i]->LastFull_Cap)) * 100.0;
++
++ if (strcmp(Batt_Info[i]->Charge_Now,"")!=0 &&
++ strcmp(Batt_Info[i]->Charge_Now,"unknown")!=0)
++ Remaining_Percentage = float(atoi(Batt_Info[i]->Charge_Now)) / float(atoi(Batt_Info[i]->Charge_Full)) * 100.0;
++ else
++ Remaining_Percentage = float(atoi(Batt_Info[i]->Remaining_Cap)) / float(atoi(Batt_Info[i]->LastFull_Cap)) * 100.0;
+
+ /* from Alan Pope : some broken Dell batteries report a remaining capacity bigger
+ than their last full capacity or their design capacity. This led acpitool to report
+@@ -153,19 +161,24 @@
+ else
+ Precision = 4;
+
+- if( strncmp(Batt_Info[i]->Charging_State,"char",4)==0 )
++ if(strncasecmp(Batt_Info[i]->Charging_State,"char",4)==0)
+ {
+ Is_Charging = 1;
+ }
+ else
+ {
+- if(strncmp(Batt_Info[i]->Charging_State,"disch",5)==0) Is_Discharging = 1;
++ if(strncasecmp(Batt_Info[i]->Charging_State,"disch",5)==0) Is_Discharging = 1;
+ }
+
+ if(Show_Time) // calculate remaining or charging time only if present battery rate != 0 //
+ {
+- if(Is_Charging)
+- Remaining_Time = (float(atoi(Batt_Info[i]->LastFull_Cap)) - float(atoi(Batt_Info[i]->Remaining_Cap))) / float(atoi(Batt_Info[i]->Present_Rate));
++ if(Is_Charging) {
++ if (strcmp(Batt_Info[i]->Charge_Now,"")!=0 &&
++ strcmp(Batt_Info[i]->Charge_Now,"unknown")!=0)
++ Remaining_Time = (float(atoi(Batt_Info[i]->Charge_Full)) - float(atoi(Batt_Info[i]->Charge_Now))) / float(atoi(Batt_Info[i]->Present_Rate));
++ else
++ Remaining_Time = (float(atoi(Batt_Info[i]->LastFull_Cap)) - float(atoi(Batt_Info[i]->Remaining_Cap))) / float(atoi(Batt_Info[i]->Present_Rate));
++ }
+ else
+ Remaining_Time = float(atoi(Batt_Info[i]->Remaining_Cap)) / float(atoi(Batt_Info[i]->Present_Rate));
+ // this represents hours //
+@@ -180,9 +193,11 @@
+ Minutes = Time_In_Seconds / 60;
+ Time_In_Seconds = Time_In_Seconds - (Minutes * 60);
+ }
+-
++
+ if(atoi(Batt_Info[i]->Design_Cap) > 0)
+ Battery_Left_Percent = float(atoi(Batt_Info[i]->LastFull_Cap)) / float(atoi(Batt_Info[i]->Design_Cap)) * 100.0;
++ else if(atoi(Batt_Info[i]->Charge_Full_Design) > 0)
++ Battery_Left_Percent = float(atoi(Batt_Info[i]->Charge_Full)) / float(atoi(Batt_Info[i]->Charge_Full_Design)) * 100.0;
+ else
+ Battery_Left_Percent = -1.0;
+
+@@ -207,8 +222,15 @@
+ <<setfill('0')<<setw(2)<<Time_In_Seconds;
+ cout<<endl;
+
+- cout<<" Design capacity : "<<Batt_Info[i]->Design_Cap<<endl;
+- cout<<" Last full capacity : "<<Batt_Info[i]->LastFull_Cap;
++ if(atoi(Batt_Info[i]->Design_Cap) > 0)
++ cout<<" Design capacity : "<<Batt_Info[i]->Design_Cap<<endl;
++ else if(atoi(Batt_Info[i]->Charge_Full_Design) > 0)
++ cout<<" Design capacity : "<<Batt_Info[i]->Charge_Full_Design<<endl;
++
++ if(atoi(Batt_Info[i]->LastFull_Cap) > 0)
++ cout<<" Last full capacity : "<<Batt_Info[i]->LastFull_Cap;
++ else if(atoi(Batt_Info[i]->Charge_Full) > 0)
++ cout<<" Last full capacity : "<<Batt_Info[i]->Charge_Full;
+
+ if(Battery_Left_Percent<100.0)
+ {
+@@ -327,7 +349,7 @@
+
+
+
+-int Get_Battery_Info_from_Proc(const int bat_nr, Battery_Info *bat_info, int verbose)
++int Get_Battery_Info_from_Proc(const int bat_nr, Battery_Info *batt_info, int verbose)
+ {
+ ifstream file_in;
+ char filename[4][65], str[100], temp[100];
+@@ -378,7 +400,7 @@
+ {
+ if(!verbose)
+ {
+- bat_info->Battery_Present = 2; // 2 represents error value //
++ batt_info->Battery_Present = 2; // 2 represents error value //
+ return 0;
+ }
+ else
+@@ -422,24 +444,24 @@
+ file_in.getline(str, 100);
+ strncpy(temp, str+25, 4);
+ if(strncmp(temp,"yes",3)==0)
+- bat_info->Battery_Present = 1; //yes, we have a battery //
++ batt_info->Battery_Present = 1; //yes, we have a battery //
+ else
+ {
+- bat_info->Battery_Present = 0;
++ batt_info->Battery_Present = 0;
+ return 0; //bail out if battery is not present //
+ }
+
+ // then get the design capacity //
+ file_in.getline(str, 100);
+- strncpy(bat_info->Design_Cap, str+25, 9);
++ strncpy(batt_info->Design_Cap, str+25, 9);
+
+ // then get the last full capacity //
+ file_in.getline(str, 100);
+- strncpy(bat_info->LastFull_Cap, str+25, 9);
++ strncpy(batt_info->LastFull_Cap, str+25, 9);
+
+- if (strncmp(bat_info->LastFull_Cap,"unknown",7)==0)
++ if (strncmp(batt_info->LastFull_Cap,"unknown",7)==0)
+ {
+- bat_info->Battery_Present = 0;
++ batt_info->Battery_Present = 0;
+ return 0; //bail out if battery is not present //
+ }
+ /* some Dell laptops seem to report a 2nd battery as being present, while it is NOT, but then report the
+@@ -449,21 +471,21 @@
+
+ // then get the technology //
+ file_in.getline(str, 100);
+- strncpy(bat_info->Technology, str+25, 12);
++ strncpy(batt_info->Technology, str+25, 12);
+
+ // then get the model number //
+ for(int t=0; t<5; t++)
+ file_in.getline(str, 100); //skip 5 lines //
+ file_in.getline(str, 100);
+- strncpy(bat_info->Model, str+25, 12);
++ strncpy(batt_info->Model, str+25, 12);
+
+ // then get the serial number //
+ file_in.getline(str, 100);
+- strncpy(bat_info->Serial, str+25, 12);
++ strncpy(batt_info->Serial, str+25, 12);
+
+ // then get the battery type //
+ file_in.getline(str, 100);
+- strncpy(bat_info->Bat_Type, str+25, 12);
++ strncpy(batt_info->Bat_Type, str+25, 12);
+
+ file_in.close();
+
+@@ -480,17 +502,17 @@
+ // then get the charging state //
+ file_in.getline(str, 100); file_in.getline(str, 100); // skip first 2 lines //
+ file_in.getline(str, 100);
+- strncpy(bat_info->Charging_State, str+25, 12);
+- if (strncmp(bat_info->Charging_State,"unknown",7)==0) strncpy(bat_info->Charging_State, "charged",7);
++ strncpy(batt_info->Charging_State, str+25, 12);
++ if (strncmp(batt_info->Charging_State,"unknown",7)==0) strncpy(batt_info->Charging_State, "charged",7);
+ /* on older kernels, like 2.4.22, the charging state is reported as "unknown", whereas in recent kernels
+ this was changed to "charged". */
+
+ // then get the charging rate //
+ file_in.getline(str, 100);
+- strncpy(bat_info->Present_Rate, str+25, 9);
+- if (strncmp(bat_info->Charging_State,"charged",7)==0)
++ strncpy(batt_info->Present_Rate, str+25, 9);
++ if (strncmp(batt_info->Charging_State,"charged",7)==0)
+ {
+- if (strncmp(bat_info->Present_Rate, "unknown",7)==0) strncpy(bat_info->Present_Rate, "0 ",7);
++ if (strncmp(batt_info->Present_Rate, "unknown",7)==0) strncpy(batt_info->Present_Rate, "0 ",7);
+ }
+ /* some batteries report the present rate as "unknown", even when they report the battery as being charged.
+ If the battery is charged, the rate should be 0 */
+@@ -498,12 +520,12 @@
+
+ // then get the remaining capacity //
+ file_in.getline(str, 100);
+- strncpy(bat_info->Remaining_Cap, str+25, 9);
++ strncpy(batt_info->Remaining_Cap, str+25, 9);
+
+ file_in.close();
+ }
+ else // battery dir is readable but empty : only . and .. at most //
+- bat_info->Battery_Present = 3;
++ batt_info->Battery_Present = 3;
+
+ return 0;
+ }
+@@ -513,8 +535,8 @@
+ int Get_Battery_Info_from_Sys(const int bat_nr, Battery_Info *batt_info, int verbose)
+ {
+ ifstream file_in;
+- char filename[6][65], str[100], temp[100];
+- int bat_count = 0, start = 0, findex = 0;
++ char filename[6][65], str[100], temp[100], attr[100];
++ int bat_count = 0, start = 0, findex = 0, value = 0;
+ DIR *battery_dir;
+ char *name, *dirname;
+
+@@ -613,165 +635,104 @@
+ return -1;
+ }
+
+- memset(str, '\0', 100);
+- for(int t=0; t<5; t++)
+- fgets(str, 100, power_fp); /* skip first 5 lines */
+-
+- /* get battery status (full, charging, ...) */
+- memset(str, '\0', 100);
+- fgets(str, 100, power_fp);
+- if (strlen(str)>0)
+- {
+- memset(temp, '\0', 100);
+- sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
+- strncpy(batt_info->Charging_State, temp, 12);
+- }
+-
+-
+- /* get battery presence (0 or 1) */
+- memset(str, '\0', 100);
+- fgets(str, 100, power_fp);
+- if (strlen(str)>0)
+- {
+- memset(temp, '\0', 100);
+- strncpy(temp, str+21, 1);
+- if(strncmp(temp,"1",1)==0)
+- batt_info->Battery_Present = 1; /* yes, we have a battery */
+- else
+- {
+- batt_info->Battery_Present = 0;
+- printf(" Battery is not present, bailing out. \n");
+- return 0; /* bail out if battery is not present */
+- }
+- }
+-
+-
+- /* get technology */
+- memset(str, '\0', 100);
+- fgets(str, 100, power_fp);
+- if (strlen(str)>0)
+- {
+- memset(temp, '\0', 100);
+- sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
+- strncpy(batt_info->Technology, temp, 12);
+- }
+- else
+- strncpy(batt_info->Technology, "unknown", 7);
+-
+-
+-
+- //printf(" \n bat_info_tech = %s \n\n ", batt_info->Technology);
+-
+-
+-
+- fgets(str, 100, power_fp); /* skip 1 line */
+-
+-
+- /* get voltage_now */
+- memset(str, '\0', 100);
+- fgets(str, 100, power_fp);
+- if (strlen(str)>0)
+- {
+- memset(temp, '\0', 100);
+- sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
+- strncpy(batt_info->Voltage_Now, temp, 12);
+- }
+- else
+- strncpy(batt_info->Voltage_Now, "unknown", 7);
+-
+-
+- /* get current_now, which I believe is the charging rate ? */
+- memset(str, '\0', 100);
+- fgets(str, 100, power_fp);
+- if (strlen(str)>0)
+- {
+- memset(temp, '\0', 100);
+- sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
+- strncpy(batt_info->Present_Rate, temp, 12);
+- }
+- else
+- strncpy(batt_info->Present_Rate, "unknown", 7);
+-
+-
+- /* get charge_full_design */
+- memset(str, '\0', 100);
+- fgets(str, 100, power_fp);
+- if (strlen(str)>0)
+- {
+- memset(temp, '\0', 100);
+- sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
+- strncpy(batt_info->Design_Cap, temp, 12);
+- }
+- else
+- strncpy(batt_info->Design_Cap, "unknown", 7);
+-
+-
+- //printf(" \n bat_info_design_cap = %s \n ", batt_info->Design_Cap);
+-
+-
+- /* get charge_full, which is the last full capacity I guess ? */
+- memset(str, '\0', 100);
+- fgets(str, 100, power_fp);
+- if (strlen(str)>0)
+- {
+- memset(temp, '\0', 100);
+- sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
+- strncpy(batt_info->LastFull_Cap, temp, 12);
+- }
+- else
+- strncpy(batt_info->LastFull_Cap, "unknown", 7);
+-
+-
+- //printf(" \n bat_info_lastfull_cap = %s \n\n ", batt_info->LastFull_Cap);
+-
+-
+- /* get charge_now */
+- memset(str, '\0', 100);
+- fgets(str, 100, power_fp);
+- if (strlen(str)>0)
+- {
+- memset(temp, '\0', 100);
+- sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
+- strncpy(batt_info->Remaining_Cap, temp, 12);
+- }
+- else
+- strncpy(batt_info->Remaining_Cap, "unknown", 7);
+-
+- //printf(" \n bat_info_remaining_cap = %s \n\n ", batt_info->Remaining_Cap);
+-
+-
+- /* get model_name */
+- memset(str, '\0', 100);
+- fgets(str, 100, power_fp);
+- if (strlen(str)>0)
+- {
+- memset(temp, '\0', 100);
+- strncpy(temp, str+24, 12); // use strncpy here because sscanf chokes on blanks in this one ? //
+-
+- memset(str, '\0', 100);
+- sscanf(temp, "%[^\n]", str); // strip trailing \n, fucks up output //
+-
+- strncpy(batt_info->Model, str, 12);
++ strncpy(batt_info->Technology, "unknown", 7);
++ strncpy(batt_info->Voltage_Now, "unknown", 7);
++ strncpy(batt_info->Charge_Now, "unknown", 7);
++ strncpy(batt_info->Charge_Full, "unknown", 7);
++ strncpy(batt_info->Charge_Full_Design, "unknown", 7);
++ strncpy(batt_info->Present_Rate, "unknown", 7);
++ strncpy(batt_info->Design_Cap, "unknown", 7);
++ strncpy(batt_info->LastFull_Cap, "unknown", 7);
++ strncpy(batt_info->Remaining_Cap, "unknown", 7);
++ strncpy(batt_info->Model, "unknown", 7);
++ strncpy(batt_info->Serial, "unknown", 7);
++
++ // see linux-2.6/drivers/power/power_supply_sysfs.c
++ // there can be different number of lines, so read up to 40 lines
++ for(int t=0; t<40; t++) {
++ memset(str, '\0', 100);
++ memset(attr, '\0', 100);
++ memset(temp, '\0', 100);
++ fgets(str, 100, power_fp);
++ sscanf(str, "%[^=]s %*s %*[^\n]", attr);
++ sscanf(str, "%*[^=] %*c %s %*[^\n]",temp);
++ if (strcmp(attr,"POWER_SUPPLY_STATUS")==0) {
++ strncpy(batt_info->Charging_State, temp, 12);
++ }
++ else if (strcmp(attr,"POWER_SUPPLY_TYPE")==0) {
++ strncpy(batt_info->Bat_Type, temp, 12);
++ }
++ else if (strcmp(attr,"POWER_SUPPLY_TECHNOLOGY")==0) {
++ strncpy(batt_info->Technology, temp, 12);
++ }
++ else if (strcmp(attr,"POWER_SUPPLY_VOLTAGE_NOW")==0) {
++ value = atoi(temp) / 1000;
++ snprintf(temp, sizeof(temp), "%i mV", value);
++ strncpy(batt_info->Voltage_Now, temp, 12);
++ }
++ else if (strcmp(attr,"POWER_SUPPLY_CURRENT_NOW")==0 ||
++ strcmp(attr,"POWER_SUPPLY_POWER_NOW")==0) {
++ value = atoi(temp) / 1000;
++ snprintf(temp, sizeof(temp), "%i", value);
++ strncpy(batt_info->Present_Rate, temp, 9);
++ }
++ else if (strcmp(attr,"POWER_SUPPLY_CHARGE_NOW")==0) {
++ value = atoi(temp) / 1000;
++ snprintf(temp, sizeof(temp), "%i mA", value);
++ strncpy(batt_info->Charge_Now, temp, 12);
++ }
++ else if (strcmp(attr,"POWER_SUPPLY_CHARGE_FULL_DESIGN")==0) {
++ value = atoi(temp) / 1000;
++ snprintf(temp, sizeof(temp), "%i mA", value);
++ strncpy(batt_info->Charge_Full_Design, temp, 12);
++ }
++ else if (strcmp(attr,"POWER_SUPPLY_CHARGE_FULL")==0) {
++ value = atoi(temp) / 1000;
++ snprintf(temp, sizeof(temp), "%i mA", value);
++ strncpy(batt_info->Charge_Full, temp, 12);
++ }
++ else if (strcmp(attr,"POWER_SUPPLY_ENERGY_FULL_DESIGN")==0) {
++ value = atoi(temp) / 1000;
++ snprintf(temp, sizeof(temp), "%i mWh", value);
++ strncpy(batt_info->Design_Cap, temp, 9);
++ }
++ else if (strcmp(attr,"POWER_SUPPLY_ENERGY_FULL")==0) {
++ value = atoi(temp) / 1000;
++ snprintf(temp, sizeof(temp), "%i mWh", value);
++ strncpy(batt_info->LastFull_Cap, temp, 9);
++ }
++ else if (strcmp(attr,"POWER_SUPPLY_ENERGY_NOW")==0) {
++ value = atoi(temp) / 1000;
++ snprintf(temp, sizeof(temp), "%i mWh", value);
++ strncpy(batt_info->Remaining_Cap, temp, 9);
++ }
++ else if (strcmp(attr,"POWER_SUPPLY_MODEL_NAME")==0) {
++ strncpy(batt_info->Model, temp, 12);
++ }
++ else if (strcmp(attr,"POWER_SUPPLY_SERIAL_NUMBER")==0) {
++ strncpy(batt_info->Serial, temp, 12);
++ }
++ else if (strcmp(attr,"POWER_SUPPLY_PRESENT")==0) {
++ if(strncmp(temp,"1",1)==0) {
++ batt_info->Battery_Present = 1;
++ }
++ else {
++ batt_info->Battery_Present = 0;
++ printf(" Battery is not present, bailing out. \n");
++ return 0;
++ }
++ }
+ }
++ if (strcmp(batt_info->Charge_Now,"")!=0 &&
++ strcmp(batt_info->Charge_Now,"unknown")!=0)
++ snprintf(temp, sizeof(temp), "%s mA", batt_info->Present_Rate);
+ else
+- strncpy(batt_info->Model, "unknown", 7);
++ snprintf(temp, sizeof(temp), "%s mW", batt_info->Present_Rate);
+
+- fgets(str, 100, power_fp);
++ strncpy(batt_info->Present_Rate, temp, 9);
+
+- /* get serial */
+- memset(str, '\0', 100);
+- fgets(str, 100, power_fp);
+- if (strlen(str)!=0)
+- {
+- memset(temp, '\0', 100);
+- sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
+- strncpy(batt_info->Serial, temp, 12);
+- }
+- else
+- strncpy(batt_info->Serial, "unknown", 7);
+-
+ fclose(power_fp);
+- }
++ }
+ else // battery dir is readable but empty : only . and .. at most //
+ batt_info->Battery_Present = 3;
+ return 0;
diff --git a/sys-power/acpitool/files/acpitool-0.5.1-kernel3.patch b/sys-power/acpitool/files/acpitool-0.5.1-kernel3.patch
new file mode 100644
index 000000000000..cd793d2e1e67
--- /dev/null
+++ b/sys-power/acpitool/files/acpitool-0.5.1-kernel3.patch
@@ -0,0 +1,14 @@
+http://bugs.gentoo.org/377355
+
+--- src/acpitool.cpp
++++ src/acpitool.cpp
+@@ -205,8 +205,7 @@
+ Kernel_24 = 1;
+ Kernel_26 = 0;
+ }
+-
+- if(strncmp(str,"2.6",3)==0)
++ else
+ {
+ Kernel_24 = 0;
+ Kernel_26 = 1;
diff --git a/sys-power/acpitool/files/acpitool-0.5.1-wakeup.patch b/sys-power/acpitool/files/acpitool-0.5.1-wakeup.patch
new file mode 100644
index 000000000000..b36d7306bddf
--- /dev/null
+++ b/sys-power/acpitool/files/acpitool-0.5.1-wakeup.patch
@@ -0,0 +1,70 @@
+From 3a87a4132667f78fc85c54ad89992bbdd02d1e55 Mon Sep 17 00:00:00 2001
+From: Carlos Alberto Lopez Perez <clopez@igalia.com>
+Date: Thu, 6 Oct 2011 03:12:55 +0200
+Subject: [PATCH] Use dynamic structures instead of predefined ones
+
+ * The file /proc/acpi/wakeup can have much more than 25 entries.
+ In my computer (Dell E6420) I have 27 entries.
+ So instead of using an array of [x] entries better use dynamic
+ vectors and push the new entries when a new line from the file
+ is read.
+
+ * The name of the device is not ever 4 characters. For example I
+ have a device called "LID" which is 3 characters long.
+ Instead of using a fixed size for the device we split the line
+ on the first tab (\t) and use the first part.
+---
+ src/acpitool.cpp | 23 +++++++++++------------
+ 1 files changed, 11 insertions(+), 12 deletions(-)
+
+diff --git a/src/acpitool.cpp b/src/acpitool.cpp
+index 2a610a5..71e01d7 100644
+--- a/src/acpitool.cpp
++++ b/src/acpitool.cpp
+@@ -460,16 +460,14 @@ int Show_WakeUp_Devices(int verbose)
+
+ int Toggle_WakeUp_Device(const int Device, int verbose)
+ {
+- ifstream file_in;
+ ofstream file_out;
+- char *filename, str[50];
+- int index = 1;
+- char Name[25][5]; // 25 should be enough I guess, I have only 9 so far //
+-
++ char *filename; string str;
++ int index = 1; int charindex = 0;
++ std::vector <std::string> Name(index); // Never is enough, use dynamic structures //
+ filename = "/proc/acpi/wakeup";
+
+- file_in.open(filename);
+- if (!file_in)
++ ifstream file_in(filename, ifstream::in);
++ if (!file_in.good()) // if opening is not successful
+ {
+ if(!verbose)
+ {
+@@ -484,14 +482,15 @@ int Toggle_WakeUp_Device(const int Device, int verbose)
+ }
+ }
+
+- file_in.getline(str, 50); // first line are just headers //
++ getline(file_in, str); // first line are just headers //
+ while(!file_in.eof()) // count all devices and store their names//
+ {
+- file_in.getline(str, 50);
+- if(strlen(str)!=0) // avoid empty last line //
++ getline(file_in, str);
++ if( str.length() != 0 ) // avoid empty last line //
+ {
+- memset(Name[index], '\0', 5);
+- strncpy(Name[index], str, 4);
++ charindex = 0; // reset to zero
++ while ( (str[++charindex]!='\t') ); // stop on first tab and get the array index
++ Name.push_back(str.substr(0,charindex)); // Push the name into the vector
+ index++;
+ }
+ }
+--
+1.7.5.4
+
+