Subject: regression in acpi_apm
To: None <current-users@netbsd.org>
From: Iain Hibbert <plunky@rya-online.net>
List: current-users
Date: 10/27/2007 12:32:28
Hi,
   With "apm* at acpi?" I see a regression involving the battery minutes
left value. apm(4) says:

	minutes_left is an estimated remaining lifetime (or 0 if the BIOS
	cannot provide an estimate).

but acpi_apm.c fills it in with a bogus value of 0xffff. A change was made
to apm(8) to handle this behaviour, but it doesn't help third party
software (eg icewm)

  The patch below fixes this regression, and also makes apm(8) behave
a bit better wrt user specified options

  Ok to commit?

iain

--- /usr/src/sys/dev/acpi/acpi_apm.c	2007-07-20 22:20:53.000000000 +0100
+++ sys/dev/acpi/acpi_apm.c	2007-10-27 11:44:17.000000000 +0100
@@ -289,7 +289,7 @@
 	(void)memset(pinfo, 0, sizeof(*pinfo));
 	pinfo->ac_state = APM_AC_UNKNOWN;
 	pinfo->minutes_valid = 0;
-	pinfo->minutes_left = 0xffff; /* unknown */
+	pinfo->minutes_left = 0;
 	pinfo->batteryid = 0;
 	pinfo->nbattery = 0;	/* to be incremented as batteries are found */
 	pinfo->battery_flags = 0;
--- /usr/src/usr.sbin/apm/apm.c	2006-09-24 16:57:45.000000000 +0100
+++ usr.sbin/apm/apm.c	2007-10-27 11:59:04.000000000 +0100
@@ -279,17 +279,14 @@
 		switch (action) {
 		case GETSTATUS:
 printval:
-			/*
-			 * default unknown value for minutes_left, from
-			 * sys/dev/acpi/acpi_apm.c
-			 */
-			if (api->minutes_left == 0xffff)
-				domin = FALSE;
-
 			if (verbose) {
 				if (dobstate)
 					printf("Battery charge state: %s\n",
 					    battstate(api->battery_state));
+
+				if (dopct && domin && api->minutes_left == 0)
+					domin = FALSE;
+
 				if (dopct || domin) {
 					printf("Battery remaining: ");
 					if (dopct)