Package: powermgmt-base
Version: 1.30+nmu1
Severity: minor
Tags: patch
User: [email protected]
Usertags: origin-ubuntu karmic ubuntu-patch

Hi Chris,

In Ubuntu, we've applied the attached patch which does the following:

  * on_ac_power: use /sys/class/power_supply if present on *all* systems,
    not just acpi systems, as this should be the preferred abstraction on
    all platforms.  LP: #321219.

This follows up on Joey Hess's last NMU to close bug #473629.
/sys/class/power_supply is not specific to ACPI, so we should check it
regardless of whether ACPI support is detected - if the PMU and APM /proc
interfaces aren't already obsolete too, I guess they will be at some point
down the line, and the "acpi_available" check itself depends on the legacy
/proc/acpi being present.

It's possible that this change will fix bug #514889, but I haven't proven
this to be the case.

Cheers,
-- 
Steve Langasek                   Give me a lever long enough and a Free OS
Debian Developer                   to set it on, and I can move the world.
Ubuntu Developer                                    http://www.debian.org/
[email protected]                                     [email protected]
diff -Nru powermgmt-base-1.30+nmu1/src/on_ac_power powermgmt-base-1.30+nmu1ubuntu1/src/on_ac_power
--- powermgmt-base-1.30+nmu1/src/on_ac_power	2008-09-01 10:42:08.000000000 -0700
+++ powermgmt-base-1.30+nmu1ubuntu1/src/on_ac_power	2009-11-12 06:10:13.000000000 -0800
@@ -13,41 +13,46 @@
 
 set -e
 
-# ACPI
+# sysfs
 #
 # This algorithm is complicated by the possibility of multiple AC
 # adapters.  We scan the ac_adapter/power_supply directory looking for adapters
 # that have known states.  If any adapter is on-line, we return 0.  If
 # no adapters are on-line but one or more are off-line, we return 1.
 #
-if /sbin/acpi_available; then
-    OFF_LINE_P=no
-    if [ -d /sys/class/power_supply/ ]; then
-        for FN in /sys/class/power_supply/*; do
-	    if test -d "${FN}" && test -r "${FN}/type"; then
-	        type="$(cat ${FN}/type)"
-	        if test "x${type}" = "xMains"; then
-	            if [ -r "${FN}/online" ]; then
-		        online="$(cat ${FN}/online)"
-		        [ "$online" = 1 ] && exit 0
-		        [ "$online" = 0 ] && OFF_LINE_P=yes
-		    fi
+OFF_LINE_P=no
+
+if [ -d /sys/class/power_supply/ ]; then
+    for FN in /sys/class/power_supply/*; do
+	if test -d "${FN}" && test -r "${FN}/type"; then
+	    type="$(cat ${FN}/type)"
+	    if test "x${type}" = "xMains"; then
+		if [ -r "${FN}/online" ]; then
+		    online="$(cat ${FN}/online)"
+		    [ "$online" = 1 ] && exit 0
+		    [ "$online" = 0 ] && OFF_LINE_P=yes
 		fi
 	    fi
-	done
-    elif [ -d /proc/acpi/ac_adapter ]; then
-	for FN in /proc/acpi/ac_adapter/*; do
-	    if [ -d "${FN}" ]; then
-		if [ -r "${FN}/state" ]; then
-		    grep --quiet on-line "${FN}/state" && exit 0
-		    grep --quiet off-line "${FN}/state" && OFF_LINE_P=yes
-		elif [ -r "${FN}/status" ]; then
-		    grep --quiet on-line "${FN}/status" && exit 0
-		    grep --quiet off-line "${FN}/status" && OFF_LINE_P=yes
-		fi
+	fi
+    done
+    [ "${OFF_LINE_P}" = "yes" ] && exit 1
+fi
+
+# ACPI
+# same algorithm as above, a fallback only when the generic sysfs interface
+# is not available (old kernels only)
+if /sbin/acpi_available && [ -d /proc/acpi/ac_adapter ]; then
+    for FN in /proc/acpi/ac_adapter/*; do
+	if [ -d "${FN}" ]; then
+	    if [ -r "${FN}/state" ]; then
+		grep --quiet on-line "${FN}/state" && exit 0
+		grep --quiet off-line "${FN}/state" && OFF_LINE_P=yes
+	    elif [ -r "${FN}/status" ]; then
+		grep --quiet on-line "${FN}/status" && exit 0
+		grep --quiet off-line "${FN}/status" && OFF_LINE_P=yes
 	    fi
-	done
-    fi
+	fi
+    done
     [ "${OFF_LINE_P}" = "yes" ] && exit 1
 fi
 

Reply via email to