Attached patch against mainline GIT to posixify pm-utils.
Changes made:
* Overall:
Rewrote scripts to make them POSIX compliant.
* pm/functions:
Changed locking to use directories as locking primitives, because
atomicity of directory creation is enforced by the kernel and mkdir
will fail if a directory already exists. I investigated using
noclobber, but POSIX says to die on redirection failure instead of
returning an error.
Changed location of the main lock to reside in /tmp, so that it will
be automatically cleaned on boot if suspend/resume fails.
Genericised the hook-running infrastructure, modified pm-powersave
to use it instead of implementing its own.
Changed run_hooks to handle going forwards and backwards in one call
When running hooks backwards, run_hooks automatically skips ones that
failed running forwards. This allows hooks to signal that they do
not need to run on resume by returning a non-zero exit status.
Modified module load/unload, service stop/start, and save/restore
state functions to avoid environment variable hackery and (more
important) use of eval where not required.
Simplified get_power_status -- on_ac_power never returns 255, so do
not bother testing for it.
In pm_main, moved unlocking into a trap 0 function so that it will be
called no matter how the script exits. Also modified pm_main to use
the new auto-reversing run_hooks infrastructure.
In modunload, got rid of gratuitous use of seq as well as numerous
bashisms.
Added LC_COLLATE=c so that our sort order will always be stable.
* src/pm-action:
Moved LC_COLLATE=c to pm/functions
Replaced calls to basename with parameter expansion.
* src/pm-powersave:
Got rid of duplicate hook-running infrastructure
* pm/sleep.d/zzz:
New file that actually does the suspend/hibernate.
* pm/sleep.d/49bluetooth:
Don't save any state if we are not in a system where this applies.
* pm/sleep.d/50modules:
Don't use nonexistent RESUME_MODULES environment variable, just call
the modreload function.
* pm/sleep.d/90clock:
Use new locking infrastructure.
* pm/sleep.d/94cpufreq:
Replace parsing of output of ls with globbing.
Change fallback governor from "userspace" to "performance"
* pm/sleep.d/99video:
Get rid of redundant tests
diff -urNX diffignore pm-utils/AUTHORS working/AUTHORS
--- pm-utils/AUTHORS 2008-01-26 13:53:23.000000000 -0600
+++ working/AUTHORS 2008-01-12 18:41:49.000000000 -0600
@@ -2,3 +2,4 @@
Peter Jones <[EMAIL PROTECTED]>
David Zeuthen <[EMAIL PROTECTED]>
Richard Hughes <[EMAIL PROTECTED]>
+Victor Lowther <[EMAIL PROTECTED]>
diff -urNX diffignore pm-utils/ChangeLog working/ChangeLog
--- pm-utils/ChangeLog 2008-01-26 13:53:23.000000000 -0600
+++ working/ChangeLog 2008-01-26 14:42:39.000000000 -0600
@@ -1,3 +1,69 @@
+2008-01-14 Victor Lowther <[EMAIL PROTECTED]>
+
+ * Overall:
+ Rewrote scripts to make them POSIX compliant.
+
+ * pm/functions:
+ Changed locking to use directories as locking primitives, because
+ atomicity of directory creation is enforced by the kernel and mkdir
+ will fail if a directory already exists. I investigated using
+ noclobber, but POSIX says to die on redirection failure instead of
+ returning an error.
+
+ Changed location of the main lock to reside in /tmp, so that it will
+ be automatically cleaned on boot if suspend/resume fails.
+
+ Genericised the hook-running infrastructure, modified pm-powersave
+ to use it instead of implementing its own.
+
+ Changed run_hooks to handle going forwards and backwards in one call
+ When running hooks backwards, run_hooks automatically skips ones that
+ failed running forwards. This allows hooks to signal that they do
+ not need to run on resume by returning a non-zero exit status.
+
+ Modified module load/unload, service stop/start, and save/restore
+ state functions to avoid environment variable hackery and (more
+ important) use of eval where not required.
+
+ Simplified get_power_status -- on_ac_power never returns 255, so do
+ not bother testing for it.
+
+ In pm_main, moved unlocking into a trap 0 function so that it will be
+ called no matter how the script exits. Also modified pm_main to use
+ the new auto-reversing run_hooks infrastructure.
+
+ In modunload, got rid of gratuitous use of seq as well as numerous
+ bashisms.
+
+ Added LC_COLLATE=c so that our sort order will always be stable.
+
+ * src/pm-action:
+ Moved LC_COLLATE=c to pm/functions
+ Replaced calls to basename with parameter expansion.
+
+ * src/pm-powersave:
+ Got rid of duplicate hook-running infrastructure
+
+ * pm/sleep.d/zzz:
+ New file that actually does the suspend/hibernate.
+
+ * pm/sleep.d/49bluetooth:
+ Don't save any state if we are not in a system where this applies.
+
+ * pm/sleep.d/50modules:
+ Don't use nonexistent RESUME_MODULES environment variable, just call
+ the modreload function.
+
+ * pm/sleep.d/90clock:
+ Use new locking infrastructure.
+
+ * pm/sleep.d/94cpufreq:
+ Replace parsing of output of ls with globbing.
+ Change fallback governor from "userspace" to "performance"
+
+ * pm/sleep.d/99video:
+ Get rid of redundant tests
+
2007-12-29 Richard Hughes <[EMAIL PROTECTED]>
* pm/functions:
diff -urNX diffignore pm-utils/pm/functions working/pm/functions
--- pm-utils/pm/functions 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/functions 2008-01-14 16:44:38.000000000 -0600
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
# vim:noexpandtab
export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/lib/pm-utils/bin
@@ -15,110 +15,121 @@
PM_LOGFILE=${PM_LOGFILE:=/var/log/pm-suspend.log}
SUSPEND_MODULES=""
TEMPORARY_CPUFREQ_GOVERNOR="userspace"
+LOCKDIR="/tmp/.suspended"
+
+# make sure we have a stable sort order!
+export LC_COLLATE=C
[ -f /usr/lib/pm-utils/defaults ] && . /usr/lib/pm-utils/defaults
set +a
-# set nullglob to make glob results empty in case the pattern does not
-# match any files
-shopt -s nullglob
-
-source_configs()
-{
- cfgs="/etc/pm/config.d/*[^~]"
- for cfg in $cfgs ; do
- [ -f $cfg ] || continue
- set -a
- . $cfg
- set +a
+# first, source our config files
+for cfg in /etc/pm/config.d/*[!~] ; do
+ [ -f "$cfg" ] || continue
+ set -a
+ . "${cfg}"
+ set +a
+done
+
+# try to take the lock. Fail if we cannot get it.
+try_lock()
+{
+ # $1 = directory to use as lock directory
+ # we use directory creation because the kernel enforces atomicity,
+ # and mkdir will fail if the directory already exists.
+ mkdir "$1" >/dev/null 2>&1 || return 1
+ return 0
+}
+
+# spin waiting for the lock with optional timeout.
+# return once we have it, or the timeout has expired
+spin_lock()
+{
+ # $1 = directory to use as the lock directory
+ # $2 = optional timeout
+ local elapsed=0
+ while ! try_lock $1; do
+ sleep 1;
+ [ "x$2" != "x" ] && [ $(( $elapsed == $2 )) -ne 0 ] && return 1
done
}
-source_configs
+# release the lock
+release_lock()
+{
+ # $1 = directory used as the lock directory
+ # make sure it is ours first.
+ rm -rf "$1"
+ return $?
+}
+
take_suspend_lock()
{
+ try_lock "$LOCKDIR" || return 1
VT=$(fgconsole)
chvt 63
- if [ -f /.suspended ]; then
- read pid < /.suspended
- if [ -d /proc/$pid ]; then
- return 1
- fi
- fi
- echo "$$" > /.suspended
- rm -f /var/run/pm-suspend
- touch /var/run/pm-suspend
+ [ -d /var/run/pm-suspend ] && rm -rf /var/run/pm-suspend
+ mkdir /var/run/pm-suspend
return 0
}
remove_suspend_lock()
{
- rm -f /var/run/pm-suspend
+ rm -rf /var/run/pm-suspend
chvt 1
chvt $VT
- openvt -- sh -c "usleep $1 ; rm -f /.suspended >/dev/null 2>&1 0<&1" >/dev/null 2>&1 0<&1 &
+ release_lock "${LOCKDIR}"
}
-find_sleepd_files()
-{
- flist="/etc/pm/sleep.d/*[^~] /usr/lib/pm-utils/sleep.d/*[^~]"
- bases=$(for file in $flist ; do echo $(basename $file) ; done | sort -n | uniq)
- for base in $bases ; do
- if [ -x "/etc/pm/sleep.d/$base" ]; then
- echo /etc/pm/sleep.d/$base
- elif [ -x "/usr/lib/pm-utils/sleep.d/$base" ]; then
- echo /usr/lib/pm-utils/sleep.d/$base
+find_hooks() {
+ # $1 = type of hook to find.
+ # Currently only power and sleep are meaningful.
+ local syshooks="/etc/pm/$1.d"
+ local phooks="/usr/lib/pm-utils/$1.d"
+ local base
+
+ for base in $(for f in $syshooks/*[!~] $phooks/*[!~];
+ do [ -f "$f" ] && echo ${f##*/} ; done | sort | uniq) ;
+ do
+ if [ -x "$syshooks/$base" ]; then
+ echo $syshooks/$base
+ elif [ -x "$phooks/$base" ]; then
+ echo $phooks/$base
fi
done
}
-run_hooks()
-{
- [ -z "$1" ] && return 0
-
- [ -f /var/run/pm-suspend ] && . /var/run/pm-suspend
- rm -f /var/run/pm-suspend
-
+run_hooks() {
+ # $1 = hooks to run
+ # $2 = parameters to pass to hooks
+ # $3 = if $3 = "reverse", then also run the hooks that ran sucessfully
+ # backwards with parameters in $4
+ # $4 = parameters to pass to scripts when running backwards
echo "$(date): running $1 hooks."
-
- files=$(find_sleepd_files)
- if [ "$2" = "reverse" ]; then
- filea=($files)
- filen=${#filea[*]}
- while [ "$filen" -gt 0 ]; do
- let filen--
- file="${filea[$filen]}"
- echo "===== $(date): running hook: $file ====="
- $file $1
- done
- else
- for file in $files ; do
- echo "===== $(date): running hook: $file ====="
- $file $1
+ local hooks="$1"
+ local params="$2"
+ shift 2
+ local revhooks
+ local file
+ for file in $(find_hooks "${hooks}"); do
+ echo "===== $(date): running hook: $file $params ====="
+ "$file" $params && revhooks="${file}${revhooks:+" ${revhooks}"}"
+ done
+ echo "$(date): done running $hooks:$params hooks."
+ if [ "x$1" = "xreverse" ]; then
+ echo "$(date): running $hooks hooks backwards."
+ for file in $revhooks; do
+ echo "===== $(date): running hook :$file $2 ====="
+ "${file}" $2
done
+ echo "$(date): done running $hooks:$2 backwards"
fi
-
- echo "$(date): done running $1 hooks."
}
get_power_status()
{
- RETVAL=0
- on_ac_power
- case "$?" in
- "0")
- echo "ac"
- ;;
- "1")
- echo "battery"
- ;;
- "255")
- echo "error"
- RETVAL=1
- ;;
- esac
- return $RETVAL
+ on_ac_power && echo "ac" || echo "battery"
}
do_suspend()
@@ -139,31 +150,24 @@
pm_main()
{
- if [ -n "$PM_LOGFILE" ]; then
+ if [ "$PM_LOGFILE" ]; then
exec > "$PM_LOGFILE" 2>&1
fi
take_suspend_lock || exit 1
- rm -f "$INHIBIT"
-
- run_hooks "$1"
+ # make sure that our locks are unlocked no matter how the script exits
+ trap remove_suspend_lock 0
- if [ ! -e "$INHIBIT" -a "$(type -t "do_$1")" == "function" ]; then
- sync ; sync ; sync
- "do_$1"
- fi
-
- run_hooks "$2" reverse
+ rm -f "$INHIBIT"
- remove_suspend_lock 200
+ run_hooks sleep "$1" reverse "$2"
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"
@@ -176,26 +180,23 @@
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!
@@ -209,15 +210,15 @@
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
}
-_service=$(type -p service)
-if [ -z "$_service" ]; then
+if type service |grep -q "not found"; then
service() {
if [ -x "/etc/init.d/$1" ]; then
"/etc/init.d/$@"
@@ -227,32 +228,26 @@
fi
}
fi
-unset _service
stopservice()
{
- service "$1" status 2>/dev/null | grep -c -q running
- if [ "$?" == "0" ]; then
- N=${1//[-.]/_}
- echo "export ${N}_SERVICE_ACTIVATE=yes" >> /var/run/pm-suspend
+ if service "$1" status 2>/dev/null | grep -c -q running; then
+ touch "/var/run/pm-suspend/service:$1"
service "$1" stop
fi
}
restartservice()
{
- N=${1//[-.]/_}
- if [ "x$(eval echo \$${N}_SERVICE_ACTIVATE)" == "xyes" ]; then
- service "$1" start
- fi
+ [ -f "/var/run/pm-suspend/service:$1" ] && service "$1" start
}
savestate()
{
- echo "export ${1}_STATE=$2" >> /var/run/pm-suspend
+ echo "$2" > "/var/run/pm-suspend/state:$1"
}
restorestate()
{
- eval echo \$${1}_STATE
+ cat "/var/run/pm-suspend/state:${1}"
}
diff -urNX diffignore pm-utils/pm/Makefile.am working/pm/Makefile.am
--- pm-utils/pm/Makefile.am 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/Makefile.am 2008-01-26 14:01:04.000000000 -0600
@@ -4,7 +4,7 @@
extra_SCRIPTS = \
functions \
- defaults
+ defaults
EXTRA_DIST = \
$(extra_SCRIPTS)
diff -urNX diffignore pm-utils/pm/power.d/sched-powersave working/pm/power.d/sched-powersave
--- pm-utils/pm/power.d/sched-powersave 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/power.d/sched-powersave 2008-01-13 01:12:35.000000000 -0600
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
path_mc="/sys/devices/system/cpu/sched_mc_power_savings"
path_smp="/sys/devices/system/cpu/sched_smp_power_savings"
diff -urNX diffignore pm-utils/pm/sleep.d/00clear working/pm/sleep.d/00clear
--- pm-utils/pm/sleep.d/00clear 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/sleep.d/00clear 2008-01-26 13:56:11.000000000 -0600
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
. /usr/lib/pm-utils/functions
diff -urNX diffignore pm-utils/pm/sleep.d/00logging working/pm/sleep.d/00logging
--- pm-utils/pm/sleep.d/00logging 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/sleep.d/00logging 2008-01-26 13:56:11.000000000 -0600
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
. /usr/lib/pm-utils/functions
diff -urNX diffignore pm-utils/pm/sleep.d/01grub working/pm/sleep.d/01grub
--- pm-utils/pm/sleep.d/01grub 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/sleep.d/01grub 2008-01-26 13:56:11.000000000 -0600
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
default_resume_kernel()
{
@@ -10,7 +10,7 @@
esac
[ -x /sbin/grubby -a -x /sbin/grub ] || return 1
- [ -e /boot/vmlinuz-$(uname -r) ] || return 1
+ [ -e "/boot/vmlinuz-$(uname -r)" ] || return 1
out=$(/sbin/grubby --info /boot/vmlinuz-$(uname -r) |grep index)
[ -n "${out}" ] || return 1
diff -urNX diffignore pm-utils/pm/sleep.d/05led working/pm/sleep.d/05led
--- pm-utils/pm/sleep.d/05led 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/sleep.d/05led 2008-01-26 13:56:11.000000000 -0600
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
[ -f /proc/acpi/ibm/led ] || exit 0
diff -urNX diffignore pm-utils/pm/sleep.d/10NetworkManager working/pm/sleep.d/10NetworkManager
--- pm-utils/pm/sleep.d/10NetworkManager 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/sleep.d/10NetworkManager 2008-01-26 13:56:11.000000000 -0600
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
. /usr/lib/pm-utils/functions
diff -urNX diffignore pm-utils/pm/sleep.d/20video working/pm/sleep.d/20video
--- pm-utils/pm/sleep.d/20video 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/sleep.d/20video 2008-01-26 13:56:11.000000000 -0600
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# Copyright 2006-2007 Richard Hughes <[EMAIL PROTECTED]>
# Copyright 2007 Peter Jones <[EMAIL PROTECTED]>
@@ -9,7 +9,7 @@
. /usr/lib/pm-utils/functions
-vbetool=$(type -p vbetool)
+vbetool="$(type -p vbetool)"
vbe() {
if [ -z "$vbetool" ]; then
echo "vbetool not found" 1>&2
@@ -18,7 +18,7 @@
$vbetool "$@"
}
-radeontool=$(type -p radeontool)
+radeontool="$(type -p radeontool)"
radeon() {
if [ -z "$radeontool" ]; then
echo "radeontool not found" 1>&2
@@ -30,32 +30,32 @@
suspend_video()
{
# 0=nothing, 1=s3_bios, 2=s3_mode, 3=both
- if [ "${DISPLAY_QUIRK_S3_BIOS}" == "true" -a \
- "${DISPLAY_QUIRK_S3_MODE}" == "true" ]; then
+ if [ "x${DISPLAY_QUIRK_S3_BIOS}" = "xtrue" -a \
+ "x${DISPLAY_QUIRK_S3_MODE}" = "xtrue" ]; then
sysctl -w kernel.acpi_video_flags=3
- elif [ "${DISPLAY_QUIRK_S3_BIOS}" == "true" ]; then
+ elif [ "x${DISPLAY_QUIRK_S3_BIOS}" = "xtrue" ]; then
sysctl -w kernel.acpi_video_flags=1
- elif [ "${DISPLAY_QUIRK_S3_MODE}" == "true" ]; then
+ elif [ "x${DISPLAY_QUIRK_S3_MODE}" = "xtrue" ]; then
sysctl -w kernel.acpi_video_flags=2
else
sysctl -w kernel.acpi_video_flags=0
fi
# We might need to do one or many of these quirks
- if [ "${DISPLAY_QUIRK_RADEON_OFF}" == "true" ]; then
+ if [ "x${DISPLAY_QUIRK_RADEON_OFF}" = "xtrue" ]; then
radeon dac off
radeon light off
fi
- if [ "${DISPLAY_QUIRK_VBESTATE_RESTORE}" == "true" ]; then
+ if [ "x${DISPLAY_QUIRK_VBESTATE_RESTORE}" = "xtrue" ]; then
vbe vbestate save > /var/run/vbestate
fi
- if [ "${DISPLAY_QUIRK_VBEMODE_RESTORE}" == "true" ]; then
+ if [ "x${DISPLAY_QUIRK_VBEMODE_RESTORE}" = "xtrue" ]; then
vbe vbemode get > /var/run/vbemode
fi
- if [ "${DISPLAY_QUIRK_VGA_MODE_3}" == "true" ]; then
+ if [ "x${DISPLAY_QUIRK_VGA_MODE_3}" = "xtrue" ]; then
vbe vbemode set 3
fi
- if [ "${DISPLAY_QUIRK_DPMS_SUSPEND}" == "true" ]; then
+ if [ "x${DISPLAY_QUIRK_DPMS_SUSPEND}" = "xtrue" ]; then
vbe dpms suspend
fi
}
@@ -66,7 +66,7 @@
suspend_video
;;
hibernate)
- if [ "x$HIBERNATE_RESUME_POST_VIDEO" == "xyes" ]; then
+ if [ "x$HIBERNATE_RESUME_POST_VIDEO" = "xyes" ]; then
suspend_video
fi
;;
diff -urNX diffignore pm-utils/pm/sleep.d/49bluetooth working/pm/sleep.d/49bluetooth
--- pm-utils/pm/sleep.d/49bluetooth 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/sleep.d/49bluetooth 2008-01-26 13:56:11.000000000 -0600
@@ -1,15 +1,12 @@
-#!/bin/bash
+#!/bin/sh
. /usr/lib/pm-utils/functions
suspend_bluetooth()
{
- if [ -f /proc/acpi/ibm/bluetooth ]; then
- savestate ibm_bluetooth $(awk '{ print $2 ; exit; }' /proc/acpi/ibm/bluetooth)
- echo disable > /proc/acpi/ibm/bluetooth
- else
- savestate ibm_bluetooth missing
- fi
+ [ -f /proc/acpi/ibm/bluetooth ] || return 1
+ savestate ibm_bluetooth "$(awk '{ print $2 ; exit; }' /proc/acpi/ibm/bluetooth)"
+ echo disable > /proc/acpi/ibm/bluetooth
}
resume_bluetooth()
diff -urNX diffignore pm-utils/pm/sleep.d/50modules working/pm/sleep.d/50modules
--- pm-utils/pm/sleep.d/50modules 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/sleep.d/50modules 2008-01-26 13:56:11.000000000 -0600
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
. /usr/lib/pm-utils/functions
@@ -13,10 +13,7 @@
resume_modules()
{
- [ -z "$RESUME_MODULES" ] && return 0
- for x in $RESUME_MODULES ; do
- modprobe $x
- done
+ modreload
}
case "$1" in
diff -urNX diffignore pm-utils/pm/sleep.d/55battery working/pm/sleep.d/55battery
--- pm-utils/pm/sleep.d/55battery 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/sleep.d/55battery 2008-01-26 13:56:11.000000000 -0600
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
. /usr/lib/pm-utils/functions
diff -urNX diffignore pm-utils/pm/sleep.d/60sysfont working/pm/sleep.d/60sysfont
--- pm-utils/pm/sleep.d/60sysfont 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/sleep.d/60sysfont 2008-01-26 13:56:11.000000000 -0600
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
. /usr/lib/pm-utils/functions
diff -urNX diffignore pm-utils/pm/sleep.d/65alsa working/pm/sleep.d/65alsa
--- pm-utils/pm/sleep.d/65alsa 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/sleep.d/65alsa 2008-01-26 13:56:11.000000000 -0600
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
. /usr/lib/pm-utils/functions
diff -urNX diffignore pm-utils/pm/sleep.d/90clock working/pm/sleep.d/90clock
--- pm-utils/pm/sleep.d/90clock 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/sleep.d/90clock 2008-01-26 13:56:11.000000000 -0600
@@ -1,28 +1,28 @@
-#!/bin/bash
-
+#!/bin/sh
. /usr/lib/pm-utils/functions
+NTPD_LOCK=/tmp/.pm-ntpd.lock
+release_ntpd_lock() {
+ rmdir "${NTPD_LOCK}"
+}
suspend_clock() {
- if [ ! -f /var/run/pm-ntpd.lock ]; then
- touch /var/run/pm-ntpd.lock
- stopservice ntpd
- fi
-
- /sbin/hwclock --systohc >/dev/null 2>&1 0<&1
- return $?
+ if try_lock "${NTPD_LOCK}"; then
+ trap release_ntpd_lock 0
+ stopservice ntpd
+ fi
+ /sbin/hwclock --systohc >/dev/null 2>&1 0<&1
+ return $?
}
resume_clock() {
- /sbin/hwclock --hctosys >/dev/null 2>&1 0<&1
- rc=$?
-
- # Bring back ntpd _after_ NetworkManager and such come back...
- ( touch /var/run/pm-ntpd.lock ;
- sleep 20 ;
- restartservice ntpd ;
- rm -f /var/run/pm-ntpd.lock
- ) &
- return $rc
+ /sbin/hwclock --hctosys >/dev/null 2>&1 0<&1
+ rc=$?
+ # Bring back ntpd _after_ NetworkManager and such come back...
+ ( spin_lock "${NTPD_LOCK}";
+ trap release_ntpd_lock 0
+ sleep 20;
+ restartservice ntpd; ) &
+ return $rc
}
case "$1" in
diff -urNX diffignore pm-utils/pm/sleep.d/94cpufreq working/pm/sleep.d/94cpufreq
--- pm-utils/pm/sleep.d/94cpufreq 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/sleep.d/94cpufreq 2008-01-26 13:56:11.000000000 -0600
@@ -1,41 +1,29 @@
-#!/bin/bash
+#!/bin/sh
. /usr/lib/pm-utils/functions
hibernate_cpufreq()
{
- [ -d /sys/devices/system/cpu/ ] || return 0
- pushd /sys/devices/system/cpu/ >/dev/null 2>&1
- for x in $(ls -1) ; do
- [ -d $x/cpufreq ] || continue
- [ -f $x/cpufreq/scaling_governor ] || continue
-
- savestate ${x}_governor $(cat $x/cpufreq/scaling_governor)
- done
- for x in $(ls -1) ; do
- [ -d $x/cpufreq ] || continue
- [ -f $x/cpufreq/scaling_governor ] || continue
-
- gov="$TEMPORARY_CPUFREQ_GOVERNOR"
- grep -q "$GOVERNOR" $x/cpufreq/scaling_available_governors \
- || gov="userspace"
- sh -c "echo \"$gov\" > $x/cpufreq/scaling_governor"
- done
- popd >/dev/null 2>&1
+ [ -d /sys/devices/system/cpu/ ] || return 1
+ ( cd /sys/devices/system/cpu/
+ for x in cpu[0-9]* ; do
+ [ -f "$x/cpufreq/scaling_governor" ] || continue
+ savestate "${x}_governor" $(cat "$x/cpufreq/scaling_governor")
+ local gov="$TEMPORARY_CPUFREQ_GOVERNOR"
+ grep -q "$GOVERNOR" "$x/cpufreq/scaling_available_governors" \
+ || gov="performance"
+ echo "$gov" > "$x/cpufreq/scaling_governor"
+ done )
}
thaw_cpufreq()
{
- x=0
- while :; do
- gov=$(restorestate $(echo cpu${x}_governor))
+ ( cd /sys/devices/system/cpu/
+ for x in cpu[0-9]* ; do
+ local gov=$(restorestate "${x}_governor")
[ -z "$gov" ] && break
-
- sh -c "echo \"$gov\" > /sys/devices/system/cpu/cpu$x/cpufreq/scaling_governor"
- unset gov
- x=$(($x + 1))
- done
- unset x
+ echo "$gov" > "$x/cpufreq/scaling_governor"
+ done )
}
case "$1" in
diff -urNX diffignore pm-utils/pm/sleep.d/95led working/pm/sleep.d/95led
--- pm-utils/pm/sleep.d/95led 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/sleep.d/95led 2008-01-26 13:56:11.000000000 -0600
@@ -1,6 +1,6 @@
-#!/bin/bash
+#!/bin/sh
-[ -f /proc/acpi/ibm/led ] || exit 0
+[ -f /proc/acpi/ibm/led ] || exit 1
case "$1" in
thaw|resume)
diff -urNX diffignore pm-utils/pm/sleep.d/99video working/pm/sleep.d/99video
--- pm-utils/pm/sleep.d/99video 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/sleep.d/99video 2008-01-26 13:56:11.000000000 -0600
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# Copyright 2006-2007 Richard Hughes <[EMAIL PROTECTED]>
# Copyright 2007 Peter Jones <[EMAIL PROTECTED]>
@@ -12,7 +12,6 @@
reset_brightness() {
for bl in /sys/class/backlight/* ; do
- [ -d $bl ] || continue
[ -f $bl/brightness ] || continue
BR=$(cat $bl/brightness)
echo 0 > $bl/brightness
@@ -40,25 +39,25 @@
resume_video()
{
- if [ "${DISPLAY_QUIRK_RADEON_OFF}" == "true" ]; then
+ if [ "x${DISPLAY_QUIRK_RADEON_OFF}" = "xtrue" ]; then
radeon dac on
radeon light on
fi
# We might need to do one or many of these quirks
- if [ "${DISPLAY_QUIRK_VBE_POST}" == "true" ]; then
+ if [ "x${DISPLAY_QUIRK_VBE_POST}" = "xtrue" ]; then
vbe post
usleep 100000
fi
- if [ "${DISPLAY_QUIRK_VBESTATE_RESTORE}" == "true" ]; then
+ if [ "x${DISPLAY_QUIRK_VBESTATE_RESTORE}" = "xtrue" ]; then
vbe vbestate restore < /var/run/vbestate
fi
- if [ "${DISPLAY_QUIRK_VBEMODE_RESTORE}" == "true" ]; then
- vbe vbemode set `cat /var/run/vbemode`
+ if [ "x${DISPLAY_QUIRK_VBEMODE_RESTORE}" = "xtrue" ]; then
+ vbe vbemode set $(cat /var/run/vbemode)
fi
- if [ "${DISPLAY_QUIRK_DPMS_ON}" == "true" ]; then
+ if [ "x${DISPLAY_QUIRK_DPMS_ON}" = "xtrue" ]; then
vbe dpms on
fi
- if [ "${DISPLAY_QUIRK_RESET_BRIGHTNESS}" == "true" ]; then
+ if [ "x${DISPLAY_QUIRK_RESET_BRIGHTNESS}" = "xtrue" ]; then
reset_brightness
fi
}
@@ -69,7 +68,7 @@
resume_video
;;
thaw)
- if [ "x$HIBERNATE_RESUME_POST_VIDEO" == "xyes" ]; then
+ if [ "x$HIBERNATE_RESUME_POST_VIDEO" = "xyes" ]; then
resume_video
fi
;;
diff -urNX diffignore pm-utils/pm/sleep.d/Makefile.am working/pm/sleep.d/Makefile.am
--- pm-utils/pm/sleep.d/Makefile.am 2008-01-26 13:53:23.000000000 -0600
+++ working/pm/sleep.d/Makefile.am 2008-01-26 13:56:11.000000000 -0600
@@ -14,7 +14,8 @@
90clock \
94cpufreq \
95led \
- 99video
+ 99video \
+ zzz
EXTRA_DIST=$(sleep_SCRIPTS)
diff -urNX diffignore pm-utils/pm/sleep.d/zzz working/pm/sleep.d/zzz
--- pm-utils/pm/sleep.d/zzz 1969-12-31 18:00:00.000000000 -0600
+++ working/pm/sleep.d/zzz 2008-01-26 13:56:11.000000000 -0600
@@ -0,0 +1,10 @@
+#!/bin/sh
+. /usr/lib/pm-utils/functions
+[ -e "$INHIBIT" ] && return 1
+sync;sync;sync;
+case $1 in
+ suspend|hibernate|suspend_hybrid) do_$1 ;;
+ resume|thaw) exit 0 ;;
+ *) exit 1 ;;
+esac
+exit $?
Binary files pm-utils/pm/.swp and working/pm/.swp differ
diff -urNX diffignore pm-utils/README working/README
--- pm-utils/README 2008-01-26 13:53:23.000000000 -0600
+++ working/README 2008-01-12 18:43:53.000000000 -0600
@@ -26,7 +26,7 @@
How do "hooks" work?
-* You put a file in /etc/pm/hooks, which is executable. When suspend or
+* You put an executable file in /etc/pm/sleep.d. When suspend or
hibernate is called, several things happen:
1) a new virtual terminal is alloced and switched to
@@ -34,9 +34,9 @@
modified by end-users.
3) /etc/pm/config.d/* are evaluated in C sort order. These files can be
provided by individual packages outside of pm-utils. If a global config
- variable is set, the value set to will be appended to the previous value.
+ variable is set, the value set to will overwrite the previous value.
If any other variable is set, it will be ignored.
- 4) each of /etc/pm/hooks/* are executed in C sort order. The first command
+ 4) each of /etc/pm/sleep.d/* are executed in C sort order. The first command
line argument is "suspend" or "hibernate". These files may source
configuration files from /etc/pm/config.d/ on their own in order to pick
up variables set there that aren't part of the global list. Note that
@@ -45,7 +45,7 @@
will clobber any such variables.
5) the system suspends or hibernates.
6) some event happens to wake the machine up
- 7) each of /etc/pm/hooks/* are executed in reverse C sort order. The first
+ 7) each of /etc/pm/sleep.d/* are executed in reverse C sort order. The first
command line argument is "resume" or "thaw".
8) the system switches back to the original virtual terminal from step 1.
diff -urNX diffignore pm-utils/src/on_ac_power working/src/on_ac_power
--- pm-utils/src/on_ac_power 2008-01-26 13:53:23.000000000 -0600
+++ working/src/on_ac_power 2008-01-17 20:56:18.000000000 -0600
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# Test if the computer is running on line power
# Exit status:
@@ -39,8 +39,8 @@
# 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.
diff -urNX diffignore pm-utils/src/pm-action working/src/pm-action
--- pm-utils/src/pm-action 2008-01-26 13:53:23.000000000 -0600
+++ working/src/pm-action 2008-01-17 20:56:28.000000000 -0600
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# Simple suspend script
#
@@ -27,7 +27,7 @@
# The rule here? Simplicity.
help_options() {
- echo "$(basename "$0") [options]"
+ echo "${0##*/} [options]"
echo
echo "Options can change how the supend or hibernate is done."
echo
@@ -51,8 +51,6 @@
exit 1
fi
-export LC_COLLATE=C
-
# Get the command line options
while [ $# -gt 0 ]
do
@@ -91,9 +89,7 @@
[ -f /sys/power/state ] || exit 1
-ACTION=$(basename "$0")
-ACTION=${ACTION#pm-}
-ACTION=${ACTION/-/_}
+ACTION=${0##*pm-}
case "$ACTION" in
suspend)
diff -urNX diffignore pm-utils/src/pm-is-supported working/src/pm-is-supported
--- pm-utils/src/pm-is-supported 2008-01-26 13:53:23.000000000 -0600
+++ working/src/pm-is-supported 2008-01-17 20:56:57.000000000 -0600
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# Copyright 2007 Red Hat, Inc.
#
@@ -23,7 +23,7 @@
export LC_COLLATE=C
-ARG=${1#--}
+ARG="${1#--}"
[ -f /sys/power/state ] || exit 1
diff -urNX diffignore pm-utils/src/pm-powersave working/src/pm-powersave
--- pm-utils/src/pm-powersave 2008-01-26 13:53:23.000000000 -0600
+++ working/src/pm-powersave 2008-01-17 20:56:41.000000000 -0600
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
# vim:noexpandtab
# Simple powersave script
#
@@ -24,35 +24,11 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-# set nullglob to make glob results empty in case the pattern does not
-# match any files
-shopt -s nullglob
+[ -f /usr/lib/pm-utils/functions ] || return 1
+. /usr/lib/pm-utils/functions
-find_powerd_files()
-{
- flist="/etc/pm/power.d/*[^~] /usr/lib/pm-utils/power.d/*[^~]"
- bases=$(for file in $flist ; do echo $(basename $file) ; done | sort -n | uniq)
- for base in $bases ; do
- if [ -x "/etc/pm/power.d/$base" ]; then
- echo /etc/pm/power.d/$base
- elif [ -x "/usr/lib/pm-utils/power.d/$base" ]; then
- echo /usr/lib/pm-utils/power.d/$base
- fi
- done
-}
-
-runpowerhooks()
-{
- files=$(find_powerd_files)
- for file in $files ; do
- $file $1
- done
-}
-
-if [ "$1" == "true" ] ; then
- runpowerhooks true
-elif [ "$1" == "false" ] ; then
- runpowerhooks false
+if [ "x$1" = "xtrue" -o "x$1" = "xfalse" ] ; then
+ run_hooks power "$1"
else
echo "Argument needs to be true or false" >&2
exit 1
_______________________________________________
Pm-utils mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/pm-utils