Modify the hook-running infrastructure to be generic and to be
POSIX-compliant. Modified pm_main to use the new hook-running
infrastructure.
diff -U 0 -rNX diffignore pm-utils.updates/pm/functions working/pm/functions
--- pm-utils.updates/pm/functions 2008-01-27 12:02:55.000000000 -0600
+++ working/pm/functions 2008-01-27 11:26:51.000000000 -0600
@@ -101,9 +89,14 @@
-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
@@ -114,7 +107,6 @@
-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
@@ -122,15 +114,15 @@
-
- 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; shift
+ 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
@@ -137,0 +130 @@
+ echo "$(date): done running $hooks:$2 backwards"
@@ -139,2 +131,0 @@
-
- echo "$(date): done running $1 hooks."
@@ -185,8 +162,2 @@
- rm -f "$INHIBIT"
-
- run_hooks "$1"
-
- if [ ! -e "$INHIBIT" -a "$(type -t "do_$1")" == "function" ]; then
- sync ; sync ; sync
- "do_$1"
- fi
+ # make sure that our locks are unlocked no matter how the script exits
+ trap remove_suspend_lock 0
@@ -194 +165 @@
- run_hooks "$2" reverse
+ rm -f "$INHIBIT"
@@ -196 +167 @@
- remove_suspend_lock 200
+ run_hooks sleep "$1" reverse "$2"
diff -U 0 -rNX diffignore pm-utils.updates/pm/sleep.d/Makefile.am working/pm/sleep.d/Makefile.am
--- pm-utils.updates/pm/sleep.d/Makefile.am 2008-01-27 11:58:02.000000000 -0600
+++ working/pm/sleep.d/Makefile.am 2008-01-26 13:56:11.000000000 -0600
@@ -17 +17,2 @@
- 99video
+ 99video \
+ zzz
diff -U 0 -rNX diffignore pm-utils.updates/pm/sleep.d/zzz working/pm/sleep.d/zzz
--- pm-utils.updates/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 $?
_______________________________________________
Pm-utils mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/pm-utils