[Pm-utils] [PATCH 3/6] Split out hooks that should be aux hooks.
Victor Lowther
victor.lowther at gmail.com
Sun May 11 18:43:54 PDT 2008
This includes bluetooth handling, the ntpd part of clock handling,
and network-manager handling. More to come later.
Also updates the documentation.
---
pm/HOWTO.hooks | 21 +++++++--
pm/sleep.d/90clock | 54 +++++----------------
pm/sleep.d/{49bluetooth => bluetooth} | 0
pm/sleep.d/{10NetworkManager => network-manager} | 0
pm/sleep.d/ntpd | 31 ++++++++++++
5 files changed, 61 insertions(+), 45 deletions(-)
diff --git a/pm/HOWTO.hooks b/pm/HOWTO.hooks
index 7beb1f2..ddf4044 100644
--- a/pm/HOWTO.hooks
+++ b/pm/HOWTO.hooks
@@ -28,13 +28,26 @@ false -- The hook MUST perform whatever action is appropriate when the system
NAMING SCHEME
-All hooks are run in lexical sort order according to the C locale.
+Hooks are always run in one of two phases, either the core phase or
+the aux phase. The pm-utils infrastructure classifies hooks into
+these two phases based on how the hooks are named.
+
+A hook will be classified as a core hook if the first two characters
+of its base filename are any of the digits 0 through 9. Any other
+hook will be classified as an aux hook.
+
+When running hooks forwards, all aux hooks will run first in no
+specified order, and when they are all finished the core hooks will
+run in C locale lexical sort order.
+
+When running hooks backwards, all core hooks are run in reverse C
+lexical sort order, then all aux hooks will run in no specified order.
SLEEP.D SPECIFIC NOTES
-For any given sleep/wakeup cycle, the hooks in sleep.d are run twice:
-* Once in C lexical sort order before the system goes to sleep, and
-* Once in reverse C lexical sort order when the system wakes up.
+For any given sleep/wakeup cycle, the hooks in sleep.d are run in
+normal order before the system goes to sleep, and once in reverse
+order when the system wakes up.
CONVENIENCE FUNCTIONS
diff --git a/pm/sleep.d/90clock b/pm/sleep.d/90clock
dissimilarity index 80%
index 985b266..e3115bd 100755
--- a/pm/sleep.d/90clock
+++ b/pm/sleep.d/90clock
@@ -1,41 +1,13 @@
-#!/bin/sh
-# Synchronize system time with hardware time.
-# TODO: Split NTP handling to its own hook. Having it here is ugly and silly.
-# Do modern kernels handle this correctly? If so, we should detect that
-# and skip this hook.
-
-. "${PM_FUNCTIONS}"
-
-NTPD_LOCK="pm-ntpd.lock"
-
-suspend_clock()
-{
- if try_lock "${NTPD_LOCK}"; then
- trap 'release_lock "${NTPD_LOCK}"' 0
- stopservice ntpd
- fi
- /sbin/hwclock --systohc >/dev/null 2>&1 0<&1
-}
-
-resume_clock()
-{
- /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_lock "${NTPD_LOCK}"' 0
- sleep 20;
- restartservice ntpd; ) &
- return $rc
-}
-
-case "$1" in
- hibernate|suspend)
- suspend_clock
- ;;
- thaw|resume)
- resume_clock
- ;;
- *) exit $NA
- ;;
-esac
+#!/bin/sh
+# Synchronize system time with hardware time.
+# TODO: Do modern kernels handle this correctly? If so, we should detect that
+# and skip this hook.
+
+. "${PM_FUNCTIONS}"
+
+case "$1" in
+ hibernate|suspend) /sbin/hwclock --systohc >/dev/null 2>&1 0<&1 ;;
+ thaw|resume) /sbin/hwclock --hctosys >/dev/null 2>&1 0<&1 ;;
+ *) exit $NA
+ ;;
+esac
diff --git a/pm/sleep.d/49bluetooth b/pm/sleep.d/bluetooth
similarity index 100%
rename from pm/sleep.d/49bluetooth
rename to pm/sleep.d/bluetooth
diff --git a/pm/sleep.d/10NetworkManager b/pm/sleep.d/network-manager
similarity index 100%
rename from pm/sleep.d/10NetworkManager
rename to pm/sleep.d/network-manager
diff --git a/pm/sleep.d/ntpd b/pm/sleep.d/ntpd
new file mode 100644
index 0000000..05464e2
--- /dev/null
+++ b/pm/sleep.d/ntpd
@@ -0,0 +1,31 @@
+#!/bin/sh
+. "${PM_FUNCTIONS}"
+NTPD_LOCK="pm-ntpd.lock"
+suspend_clock()
+{
+ if try_lock "${NTPD_LOCK}"; then
+ trap 'release_lock "${NTPD_LOCK}"' 0
+ stopservice ntpd
+ fi
+}
+
+resume_clock()
+{
+ rc=$?
+ # Bring back ntpd _after_ NetworkManager and such come back...
+ spin_lock "${NTPD_LOCK}";
+ trap 'release_lock "${NTPD_LOCK}"' 0
+ sleep 20;
+ restartservice ntpd;
+}
+
+case "$1" in
+ hibernate|suspend)
+ suspend_clock
+ ;;
+ thaw|resume)
+ resume_clock
+ ;;
+ *) exit $NA
+ ;;
+esac
--
1.5.4.3
More information about the Pm-utils
mailing list