[Patches] Script bugs and hibernate on pmu
Sjoerd Simons
sjoerd at luon.net
Sun Feb 19 15:55:26 PST 2006
Hi,
Two patches this time:
The first (05_pmu_nohibernate.patch) is a little bit of a hack. When deciding
if a system can suspend/hibernate it overrides the info it got from
/sys/power/state if on an pmu system. On my powerbook using /sys/power/* only
result in crashes.
The second fixes various things in various hal scripts. I've only fixed
hal-system-lcd-* and hal-system-power-*, because i actually use those and
could test them. Anyway summary of the changes:
* When checking for an empty string use [ -z "$x" ] instead of
[ "$x" == "" ]
* The string compare operate is = not ==, while this works with bash it
doesn't on other shells (notably dash)
* Fix missing quoting in some places
* hal-system-lcd-set-brightness
+ Check if the level value is allowed before doing the pmu brightness
action.
* hal-system-power-hibernate
+ Disable the usage of /sys/power/state on pmu systems
* hal-system-power-suspend
+ Use $HAL_PROP_POWER_MANAGEMENT_TYPE instead of
$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD to check if it's run on a pmu
system
+ Call hal-system-power-pmu only as fallback if there are no other
scripts that can do suspend are installed
+ Sent org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported if
any of the suspend scripts/methods failed, not just for the pmu
The good news is that gnome-power-manager is now working nicely on my
powerbook. So a hal and gnome-power-manager that work nicely together should
be in debian experiment RSN.
Sjoerd
--
A failure will not appear until a unit has passed final inspection.
-------------- next part --------------
Index: hald/linux2/osspec.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/osspec.c,v
retrieving revision 1.45
diff -u -r1.45 osspec.c
--- hald/linux2/osspec.c 13 Feb 2006 16:42:32 -0000 1.45
+++ hald/linux2/osspec.c 19 Feb 2006 23:19:47 -0000
@@ -471,6 +471,15 @@
can_hibernate = TRUE;
free (poweroptions);
+ if (!strcmp(hal_device_property_get_string(d,"power_management.type"), "pmu")) {
+ /* Although /sys/power/state exists on pmu based machines, using it just
+ * crashes mine. Suspending works via the pmu though. So overriding what we
+ * just saw...
+ * Should be removed as soon as /sys/power works on PMU */
+ can_hibernate = FALSE;
+ can_suspend = TRUE;
+ }
+
/* check for the presence of suspend2 */
if (access ("/proc/software_suspend", F_OK) == 0)
can_hibernate = TRUE;
-------------- next part --------------
Index: tools/hal-system-lcd-get-brightness
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-lcd-get-brightness,v
retrieving revision 1.7
diff -u -r1.7 hal-system-lcd-get-brightness
--- tools/hal-system-lcd-get-brightness 18 Feb 2006 23:11:23 -0000 1.7
+++ tools/hal-system-lcd-get-brightness 19 Feb 2006 22:44:22 -0000
@@ -8,13 +8,13 @@
# (at your option) any later version.
# Check for environment variables
-if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "" ]; then
+if [ -z "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" ]; then
echo "Missing or empty environment variable(s)." >&2
echo "This script should be started by hald." >&2
exit 1
fi
-if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "pmu" ]; then
+if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "pmu" ]; then
value="`hal-system-power-pmu getlcd`"
if [ $? -ne 0 ]; then
echo "org.freedesktop.Hal.Device.LaptopPanel.NotSupported" >&2
@@ -24,37 +24,37 @@
fi
# Check for file existance and that it's readable
-if [ ! -r $HAL_PROP_LINUX_ACPI_PATH ]; then
+if [ ! -r "$HAL_PROP_LINUX_ACPI_PATH" ]; then
echo "org.freedesktop.Hal.Device.LaptopPanel.NotSupported" >&2
echo "$1 not readable!" >&2
exit 1
fi
-if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "toshiba" ]; then
+if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "toshiba" ]; then
# cat /proc/acpi/toshiba/lcd
# brightness: 5
# brightness_levels: 8
value="`cat $HAL_PROP_LINUX_ACPI_PATH | grep brightness: | awk '{print $2;}'`"
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "asus" ]; then
+elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "asus" ]; then
# cat /proc/acpi/asus/brn
# 5
value="`cat $HAL_PROP_LINUX_ACPI_PATH`"
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "panasonic" ]; then
+elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "panasonic" ]; then
# cat /proc/acpi/pcc/brightness
# 5
value="`cat $HAL_PROP_LINUX_ACPI_PATH`"
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "ibm" ]; then
+elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "ibm" ]; then
# cat /proc/acpi/ibm/brightness
# level: 5
# commands: up, down
# commands: level <level> (<level> is 0-7)
value="`cat $HAL_PROP_LINUX_ACPI_PATH | grep level: | awk '{print $2;}'`"
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "sony" ]; then
+elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "sony" ]; then
# cat /proc/acpi/sony/brightness
# 5
value="`cat $HAL_PROP_LINUX_ACPI_PATH`"
let "value = ${value} - 1"
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "omnibook" ]; then
+elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "omnibook" ]; then
# cat /proc/omnibook/lcd
# LCD brightness: 7
value="`cat $HAL_PROP_LINUX_ACPI_PATH | awk '{print $3;}'`"
Index: tools/hal-system-lcd-set-brightness
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-lcd-set-brightness,v
retrieving revision 1.7
diff -u -r1.7 hal-system-lcd-set-brightness
--- tools/hal-system-lcd-set-brightness 18 Feb 2006 23:11:23 -0000 1.7
+++ tools/hal-system-lcd-set-brightness 19 Feb 2006 22:44:23 -0000
@@ -8,8 +8,8 @@
# (at your option) any later version.
# Check for environment variables
-if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "" ] ||
- [ "$HAL_PROP_LAPTOP_PANEL_NUM_LEVELS" == "" ] ; then
+if [ -z "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" ] ||
+ [ -z "$HAL_PROP_LAPTOP_PANEL_NUM_LEVELS" ] ; then
echo "Missing or empty environment variable(s)." >&2
echo "This script should be started by hald." >&2
exit 1
@@ -18,7 +18,14 @@
# read value for set brightness
read value
-if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "pmu" ]; then
+# Check for values outside range
+if [ ${value} -lt 0 ] || [ ${value} -gt $HAL_PROP_LAPTOP_PANEL_NUM_LEVELS ]; then
+ echo "org.freedesktop.Hal.Device.LaptopPanel.Invalid" >&2
+ echo "Brightness has to be between 0 and $HAL_PROP_LAPTOP_PANEL_NUM_LEVELS!" >&2
+ exit 1
+fi
+
+if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "pmu" ]; then
hal-system-power-pmu setlcd $value
if [ $? -ne 0 ]; then
echo "org.freedesktop.Hal.Device.LaptopPanel.NotSupported" >&2
@@ -28,39 +35,33 @@
fi
# Check for file existance and that it's writable
-if [ ! -w $HAL_PROP_LINUX_ACPI_PATH ]; then
+if [ ! -w "$HAL_PROP_LINUX_ACPI_PATH" ]; then
echo "org.freedesktop.Hal.Device.LaptopPanel.NotSupported" >&2
echo "$1 not writable!" >&2
exit 1
fi
-# Check for values outside range
-if [ ${value} -lt 0 ] || [ ${value} -gt $HAL_PROP_LAPTOP_PANEL_NUM_LEVELS ]; then
- echo "org.freedesktop.Hal.Device.LaptopPanel.Invalid" >&2
- echo "Brightness has to be between 0 and $HAL_PROP_LAPTOP_PANEL_NUM_LEVELS!" >&2
- exit 1
-fi
-if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "toshiba" ]; then
+if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "toshiba" ]; then
# echo "brightness: {0..x}" >/proc/acpi/toshiba/lcd
echo "brightness: $value" > $HAL_PROP_LINUX_ACPI_PATH
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "asus" ]; then
+elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "asus" ]; then
# echo {0..15} > /proc/acpi/asus/brn
# http://www.taupro.com/wiki/ChemBook/LCDdisplayPowerConfiguration
echo "$value" > $HAL_PROP_LINUX_ACPI_PATH
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "panasonic" ]; then
+elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "panasonic" ]; then
# echo {0..15} > /proc/acpi/pcc/brightness
# http://readlist.com/lists/vger.kernel.org/linux-kernel/7/36405.html
echo "$value" > $HAL_PROP_LINUX_ACPI_PATH
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "ibm" ]; then
+elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "ibm" ]; then
# echo "level {0..7}" > /proc/acpi/ibm/brightness
# http://ibm-acpi.sourceforge.net/README
echo "level $value" > $HAL_PROP_LINUX_ACPI_PATH
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "sony" ]; then
+elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "sony" ]; then
# echo "{1..8}" > /proc/acpi/sony/brightness
# http://popies.net/sonypi/2.6-sony_acpi4.patch
echo "$value" > $HAL_PROP_LINUX_ACPI_PATH
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "omnibook" ]; then
+elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "omnibook" ]; then
# echo "{0..7}" > /proc/omnibook/lcd
# http://bugzilla.gnome.org/show_bug.cgi?id=331458
echo "$value" > $HAL_PROP_LINUX_ACPI_PATH
Index: tools/hal-system-power-hibernate
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-power-hibernate,v
retrieving revision 1.6
diff -u -r1.6 hal-system-power-hibernate
--- tools/hal-system-power-hibernate 16 Jan 2006 12:47:40 -0000 1.6
+++ tools/hal-system-power-hibernate 19 Feb 2006 22:44:23 -0000
@@ -43,8 +43,9 @@
# Suspend2 tools installed
/usr/sbin/hibernate --force
RET=$?
- elif [ -w "/sys/power/state" ] ; then
- # Use the raw kernel sysfs interface
+ elif [ -w "/sys/power/state" ] &&
+ [ "$HAL_PROP_POWER_MANAGEMENT_TYPE" != pmu ] ; then
+ # Use the raw kernel sysfs interface if possible (not on pmu yet)
echo "disk" > /sys/power/state
RET=$?
else
Index: tools/hal-system-power-suspend
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-power-suspend,v
retrieving revision 1.6
diff -u -r1.6 hal-system-power-suspend
--- tools/hal-system-power-suspend 18 Feb 2006 23:00:55 -0000 1.6
+++ tools/hal-system-power-suspend 19 Feb 2006 22:44:23 -0000
@@ -18,15 +18,6 @@
read seconds_to_sleep
-#PMU systems cannot use /sys/power/state yet, so use a helper to issue an ioctl
-if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "pmu" ]; then
- hal-system-power-pmu sleep
- if [ $? -ne 0 ]; then
- echo "org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported" >&2
- exit 1
- fi
- exit 0
-fi
#SuSE and ALTLinux only support powersave
if [ -f "/etc/altlinux-release" ] || [ -f "/etc/SuSE-release" ] ; then
@@ -62,6 +53,10 @@
elif [ -x "/usr/sbin/pmi" ] ; then
/usr/sbin/pmi action suspend force
RET=$?
+ elif [ "$HAL_PROP_POWER_MANAGEMENT_TYPE" = "pmu" ]; then
+ #PMU systems cannot use /sys/power/state yet, so use a helper to issue an ioctl
+ hal-system-power-pmu sleep
+ RET=$?
elif [ -w "/sys/power/state" ] ; then
# Use the raw kernel sysfs interface
echo "mem" > /sys/power/state
@@ -72,4 +67,8 @@
fi
fi
+if [ $RET -ne 0 ]; then
+ echo "org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported" >&2
+ exit 1
+fi
exit $RET
More information about the hal
mailing list