On Jan 28, 2008 3:02 PM, Richard Hughes <[EMAIL PROTECTED]> wrote:
> On Sat, 2008-01-26 at 14:47 -0600, Victor Lowther wrote:
> > Attached patch against mainline GIT to posixify pm-utils.
>
> Right, I've applied all the ones I can - I know we've patched things in
> parallel a bit here, and hence a couple of the patches now won't apply.
> Victor, could you please pull current master and then resync the other
> two please. Thanks dude.
Attached as a single patch. This patch modifies the module
unload/reload code to be POSIX compliant, and includes a minor
quotation fix in on_ac_power.
It omits the get_power_status changes included in the original patch
series, because there is some debate on the mailing list as to whether
those changes are valid, there is no in-tree use of get_power_status,
and the original code is POSIX compliant without any modification (my
changes were purely simplification fixes based on the in-tree version
on on_ac_power).
> Richard.
>
>
>
diff -U 5 -rNX /home/victor/pm-utils/trunk/diffignore pm-utils/pm/functions pm-utils.updates/pm/functions
--- pm-utils/pm/functions 2008-01-28 16:19:18.000000000 -0600
+++ pm-utils.updates/pm/functions 2008-01-28 13:56:13.000000000 -0600
@@ -186,12 +179,11 @@
return 0
}
_rmmod() {
if modprobe -r $1; then
- echo "export RESUME_MODULES=\"$1 \$RESUME_MODULES\"" \
- >> /var/run/pm-suspend
+ touch "/var/run/pm-suspend/module:$1"
return 0
else
echo "# could not unload '$1', usage count was $2"
return 1
fi
@@ -200,30 +192,27 @@
# this recursively unloads the given modules and all that depend on it
# first parameter is the module to be unloaded
modunload()
{
local MOD D C USED MODS I
- local UNL=$1 RET=1
- # the kernel only knows underscores in module names, no dashes
- UNL=${UNL//-/_}
- # RET is the return code.
- # If at least one module was unloaded, return 0.
- # if the module was not loaded, also return 0 since this is no error.
- # if no module was unloaded successfully, return 1
+ local UNL="$(echo $1 |tr -- - _)" RET=1
+
while read MOD D C USED D; do
[ "$MOD" = "$UNL" ] || continue
- if [ "$USED" == "-" ]; then
- _rmmod $MOD $C
+ if [ "$USED" = "-" ]; then
+ # no dependent modules, just try to remove this one.
+ _rmmod "$MOD" $C
RET=$?
else
- USED=${USED//,/ }
- MODS=($USED)
- # it seems slightly more likely to rmmod in one pass,
- # if we try backwards.
- for I in `seq [EMAIL PROTECTED] -1 0`; do
- MOD=${MODS[$I]}
+ # modules depend on this one. try to remove them first.
+ MODS="${USED%%*,}"
+ while [ "${MODS}" ]; do
+ # try to unload the last one first
+ MOD="${MODS##*,}"
modunload $MOD && RET=0
+ # prune the last one from the list
+ MODS="${MODS%,*}"
done
# if we unloaded at least one module, then let's
# try again!
[ $RET -eq 0 ] && modunload $MOD
RET=$?
@@ -233,15 +222,16 @@
# if we came this far, there was nothing to do,
# the module is no longer loaded.
return 0
}
+# reload all the modules in no particular order.
modreload()
{
- if [ "$(eval echo \$${1}_MODULE_LOAD)" == "yes" ]; then
- modprobe "$1" >/dev/null 2>&1
- fi
+ for x in /var/run/pm-suspend/module:* ; do
+ [ -f "${x}" ] && modprobe "${x##*:}" >/dev/null 2>&1
+ done
}
if type service |grep -q "not found"; then
service() {
if [ -x "/etc/init.d/$1" ]; then
diff -U 5 -rNX /home/victor/pm-utils/trunk/diffignore pm-utils/pm/sleep.d/50modules pm-utils.updates/pm/sleep.d/50modules
--- pm-utils/pm/sleep.d/50modules 2008-01-28 14:05:21.000000000 -0600
+++ pm-utils.updates/pm/sleep.d/50modules 2008-01-27 22:19:55.000000000 -0600
@@ -11,14 +11,11 @@
return 0
}
resume_modules()
{
- [ -z "$RESUME_MODULES" ] && return 0
- for x in $RESUME_MODULES ; do
- modprobe $x
- done
+ modreload
}
case "$1" in
hibernate|suspend)
suspend_modules
diff -U 5 -rNX /home/victor/pm-utils/trunk/diffignore pm-utils/src/on_ac_power pm-utils.updates/src/on_ac_power
--- pm-utils/src/on_ac_power 2008-01-28 14:05:21.000000000 -0600
+++ pm-utils.updates/src/on_ac_power 2008-01-27 22:19:55.000000000 -0600
@@ -37,11 +37,11 @@
# Assume online, since we have no data.
[ -z "$ac_adapters" ] && exit 0
# If any of them are online, then we're done.
for device in $ac_adapters ; do
- present=$(hal-get-property --udi $device --key ac_adapter.present)
- [ "$present" == "true" ] && exit 0
+ present=$(hal-get-property --udi "$device" --key ac_adapter.present)
+ [ "x$present" = "xtrue" ] && exit 0
done
# If there are adapters, but none are online, we're not on AC.
exit 1
_______________________________________________
Pm-utils mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/pm-utils