Subject: pkg/23432: xbattbar doesn't use acpiacad driver
To: None <gnats-bugs@gnats.netbsd.org>
From: None <mrg@eterna.com.au>
List: netbsd-bugs
Date: 11/14/2003 19:13:46
>Number:         23432
>Category:       pkg
>Synopsis:       xbattbar doesn't use acpiacad driver
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Nov 14 08:14:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     matthew green
>Release:        NetBSD 1.6ZE
>Organization:
people's front against (bozotic) www (softwar foundation)
>Environment:
	
	
System: NetBSD phat-bass.eterna.com.au 1.6ZE NetBSD 1.6ZE (_phat_) #40: Wed Nov  5 16:37:54 EST 2003  mrg@phat-bass.eterna.com.au:/var/sys/_phat_ i386
Architecture: i386
Machine: i386
>Description:

	xbattbar should use the acpiacad (AC-adapter) driver if present,
	and fall back to checking battery's for 'discharging' only if there
	is no acpiacad status returned.  there exist systems for whom
	acpiacad does not work - until those systems are fixed, and to
	support older systems, rather than limiting systems with working
	acpiacad drivers, these systems should not include acpiacad driver.

	the patch below allows xbattbar to fall back to the current method
	of using acpibat's "discharging" indicator only if there are no
	"acpiacad" entries found in.

>How-To-Repeat:

	notice that occasionlly xbattbar shows "disconnected" when you are
	connected, because the battery was discharging.  it takes a lot longer
	than necessary to notice changes.

>Fix:

	this change to patches/patch-ab changes xbattbar as described aboved.
	ie, if acpiacad info is found, it will be used.  if it is not found,
	the info current returned via acpibat will be returned.  this will
	affect people with acpi enable systems that include the acpiacad
	driver but that it does not work.  if this patch is applied those
	people will need to rebuild their kernel without acpiacad support.

	(one could add a switch, but as this patch didn't already touch
	options i didn't want to go there.  you could also force it via an
	env var if you were really sick.)

	(i don't consider this fix important enough for pkgsrc freeze, which
	is why i am logging this change here for later.)


Index: distinfo
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/xbattbar/distinfo,v
retrieving revision 1.9
diff -p -r1.9 distinfo
*** distinfo	10 Nov 2003 23:53:32 -0000	1.9
--- distinfo	14 Nov 2003 08:02:28 -0000
*************** $NetBSD: distinfo,v 1.9 2003/11/10 23:53
*** 3,6 ****
  SHA1 (xbattbar_1.4.2.tar.gz) = 14e9aafd62919e4a625d3f84df3b074b9eef8279
  Size (xbattbar_1.4.2.tar.gz) = 14079 bytes
  SHA1 (patch-aa) = 3bd4b688ccaeebe766335245c1a8c5dde52768c2
! SHA1 (patch-ab) = dfaf520dcc10228da4ab4c222210f0ecb4914f4f
--- 3,6 ----
  SHA1 (xbattbar_1.4.2.tar.gz) = 14e9aafd62919e4a625d3f84df3b074b9eef8279
  Size (xbattbar_1.4.2.tar.gz) = 14079 bytes
  SHA1 (patch-aa) = 3bd4b688ccaeebe766335245c1a8c5dde52768c2
! SHA1 (patch-ab) = bf57c90400ecc7c1ea0ca2cf57ddc753e560b96a
Index: patches/patch-ab
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/xbattbar/patches/patch-ab,v
retrieving revision 1.6
diff -p -r1.6 patch-ab
*** patches/patch-ab	10 Nov 2003 23:53:32 -0000	1.6
--- patches/patch-ab	14 Nov 2003 08:02:28 -0000
***************
*** 1,7 ****
  $NetBSD: patch-ab,v 1.6 2003/11/10 23:53:32 mrg Exp $
  
  --- xbattbar.c.orig	2001-02-02 16:25:29.000000000 +1100
! +++ xbattbar.c	2003-11-10 17:50:08.000000000 +1100
  @@ -27,6 +27,14 @@
   
   #include <sys/types.h>
--- 1,7 ----
  $NetBSD: patch-ab,v 1.6 2003/11/10 23:53:32 mrg Exp $
  
  --- xbattbar.c.orig	2001-02-02 16:25:29.000000000 +1100
! +++ xbattbar.c	2003-11-14 18:59:45.000000000 +1100
  @@ -27,6 +27,14 @@
   
   #include <sys/types.h>
*************** $NetBSD: patch-ab,v 1.6 2003/11/10 23:53
*** 17,23 ****
   #include <signal.h>
   #include <stdio.h>
   #include <unistd.h>
! @@ -583,39 +591,174 @@
   #define _PATH_APM_CTLDEV       "/dev/apmctl"
   #define _PATH_APM_NORMAL       "/dev/apm"
   
--- 17,23 ----
   #include <signal.h>
   #include <stdio.h>
   #include <unistd.h>
! @@ -583,39 +591,179 @@
   #define _PATH_APM_CTLDEV       "/dev/apmctl"
   #define _PATH_APM_NORMAL       "/dev/apm"
   
*************** $NetBSD: patch-ab,v 1.6 2003/11/10 23:53
*** 161,167 ****
  +       if (acpi) {
  +#ifdef HAVE_NETBSD_ACPI
  +		int32_t rtot = 0, maxtot = 0;
! +		p = APM_AC_ON;
  +		for (i = 0 ; i < ns ; i++) {
  +			if ((etds[i].validflags & ENVSYS_FCURVALID) == 0)
  +				continue;
--- 161,168 ----
  +       if (acpi) {
  +#ifdef HAVE_NETBSD_ACPI
  +		int32_t rtot = 0, maxtot = 0;
! +		int found_acpiacad = 0, discharge_p = APM_AC_ON;
! +		p = APM_AC_OFF;
  +		for (i = 0 ; i < ns ; i++) {
  +			if ((etds[i].validflags & ENVSYS_FCURVALID) == 0)
  +				continue;
*************** $NetBSD: patch-ab,v 1.6 2003/11/10 23:53
*** 172,194 ****
  +				rtot += etds[i].cur.data_s;
  +				maxtot += etds[i].max.data_s;
  +			}
! +			/*
! +			 * XXX: We should use acpiacad driver and look for
! +			 * " connected", but that's broken on some machines
! +			 * and we want this to work everywhere.  With this
! +			 * we will occasionally catch a machine conditioning
! +			 * a battery while connected, while other machines take
! +			 * 10-15 seconds to switch from "charging" to
! +			 * "discharging" and vice versa, but this is the best
! +			 * compromise.
! +			 */
  +			if (ebis[i].units == ENVSYS_INDICATOR &&
  +			    etds[i].cur.data_s &&
  +			    strncmp(ebis[i].desc, "acpibat", 7) == 0 &&
  +			    strcmp(&ebis[i].desc[cc - 11], "discharging") == 0) {
! +				p = APM_AC_OFF;
  +			}
  +		}
  +		r = (rtot * 100.0) / maxtot;
  +#endif
          } else {
--- 173,199 ----
  +				rtot += etds[i].cur.data_s;
  +				maxtot += etds[i].max.data_s;
  +			}
! +			if (ebis[i].units == ENVSYS_INDICATOR &&
! +			    etds[i].cur.data_s &&
! +			    strncmp(ebis[i].desc, "acpiacad", 8) == 0) {
! +				found_acpiacad = 1;
! +				if (strcmp(&ebis[i].desc[cc - 10],
! +				    " connected") == 0)
! +					p = APM_AC_ON;
! +			}
  +			if (ebis[i].units == ENVSYS_INDICATOR &&
  +			    etds[i].cur.data_s &&
  +			    strncmp(ebis[i].desc, "acpibat", 7) == 0 &&
  +			    strcmp(&ebis[i].desc[cc - 11], "discharging") == 0) {
! +				discharge_p = APM_AC_OFF;
  +			}
  +		}
+ +		/*
+ +		 * Some acpiacad drivers don't work properly; if not, take he
+ +		 * acpiacad driver out of your kernel.
+ +		 */
+ +		if (found_acpiacad == 0)
+ +			p = discharge_p;
  +		r = (rtot * 100.0) / maxtot;
  +#endif
          } else {
>Release-Note:
>Audit-Trail:
>Unformatted: