summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Lowther <victor.lowther@gmail.com>2008-05-18 10:25:01 -0500
committerVictor Lowther <victor.lowther@gmail.com>2008-05-18 10:25:01 -0500
commitcc55fcd04883f1462144eb3efdbb1c09fe7d6089 (patch)
tree6835e83dfc1ee3673e59f6bee71ce40159a59810
parenta95fac932e9f9a921690860bd01f4e5b88b619c2 (diff)
Split the NTP handling code in 90clock into its own code.
While I was at it, reorganized the hooks to conform to the new ordering convention.
-rwxr-xr-xpm/sleep.d/45battery20
-rwxr-xr-xpm/sleep.d/50NetworkManager40
-rwxr-xr-xpm/sleep.d/50ntpd25
-rwxr-xr-xpm/sleep.d/75modules29
-rwxr-xr-xpm/sleep.d/90chvt20
-rwxr-xr-xpm/sleep.d/90clock27
-rwxr-xr-xpm/sleep.d/95led13
7 files changed, 145 insertions, 29 deletions
diff --git a/pm/sleep.d/45battery b/pm/sleep.d/45battery
new file mode 100755
index 0000000..1944e98
--- /dev/null
+++ b/pm/sleep.d/45battery
@@ -0,0 +1,20 @@
+#!/bin/sh
+# Have HAL rescan batteries on resume.
+# TODO: Merge this code back into HAL, it should not be in pm-utils.
+
+. "${PM_FUNCTIONS}"
+
+resume_batteries()
+{
+ for x in $(hal-find-by-capability --capability battery 2>/dev/null); do
+ dbus-send --system --reply-timeout=2000 \
+ --dest=org.freedesktop.Hal "$x" \
+ org.freedesktop.Hal.Device.Rescan "string:$x"
+ done
+}
+
+case "$1" in
+ resume|thaw)
+ resume_batteries
+ ;;
+esac
diff --git a/pm/sleep.d/50NetworkManager b/pm/sleep.d/50NetworkManager
new file mode 100755
index 0000000..244e2c7
--- /dev/null
+++ b/pm/sleep.d/50NetworkManager
@@ -0,0 +1,40 @@
+#!/bin/sh
+# If we are running NetworkManager, tell it we are going to sleep.
+# TODO: Make NetworkManager smarter about how to handle sleep/resume
+# If we are asleep for less time than it takes for TCP to reset a
+# connection, and we are assigned the same IP on resume, we should
+# not break established connections. Apple can do this, and it is
+# rather nifty.
+
+. "${PM_FUNCTIONS}"
+
+command_exists dbus-send || exit $NA
+
+suspend_nm()
+{
+ # Tell NetworkManager to shut down networking
+ dbus-send --system \
+ --dest=org.freedesktop.NetworkManager \
+ /org/freedesktop/NetworkManager \
+ org.freedesktop.NetworkManager.sleep
+}
+
+resume_nm()
+{
+ # Wake up NetworkManager and make it do a new connection
+ dbus-send --system \
+ --dest=org.freedesktop.NetworkManager \
+ /org/freedesktop/NetworkManager \
+ org.freedesktop.NetworkManager.wake
+}
+
+case "$1" in
+ hibernate|suspend)
+ suspend_nm
+ ;;
+ thaw|resume)
+ resume_nm
+ ;;
+ *) exit $NA
+ ;;
+esac
diff --git a/pm/sleep.d/50ntpd b/pm/sleep.d/50ntpd
new file mode 100755
index 0000000..4b59abf
--- /dev/null
+++ b/pm/sleep.d/50ntpd
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+NTPD_LOCK="pm-ntpd.lock"
+
+stop_ntp()
+{
+ if try_lock "${NTPD_LOCK}"; then
+ trap 'release_lock "${NTPD_LOCK}"' 0
+ stopservice ntpd
+ fi
+
+start_ntp()
+{
+ # 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) stop_ntp ;;
+ thaw|resume) start_ntp ;;
+ *) exit $NA ;;
+esac
diff --git a/pm/sleep.d/75modules b/pm/sleep.d/75modules
new file mode 100755
index 0000000..3f292e4
--- /dev/null
+++ b/pm/sleep.d/75modules
@@ -0,0 +1,29 @@
+#!/bin/sh
+# Unload requested modules.
+
+. "${PM_FUNCTIONS}"
+
+suspend_modules()
+{
+ [ -z "$SUSPEND_MODULES" ] && return $NA
+ for x in $SUSPEND_MODULES ; do
+ modunload $x
+ done
+ return 0
+}
+
+resume_modules()
+{
+ modreload
+}
+
+case "$1" in
+ hibernate|suspend)
+ suspend_modules
+ ;;
+ thaw|resume)
+ resume_modules
+ ;;
+ *) exit $NA
+ ;;
+esac
diff --git a/pm/sleep.d/90chvt b/pm/sleep.d/90chvt
new file mode 100755
index 0000000..47a2c85
--- /dev/null
+++ b/pm/sleep.d/90chvt
@@ -0,0 +1,20 @@
+#!/bin/sh
+# Ensure we eare in text mode by switching to an unused vt.
+# Also avoids lots of ghastly suspend/resume errors due to trying
+# to suspend/resume while running in X.
+
+. "${PM_FUNCTIONS}"
+
+case "$1" in
+ hibernate|suspend)
+ fgconsole |savestate console
+ chvt 63
+ ;;
+ thaw|resume)
+ state_exists console || exit 1
+ chvt $(restorestate console)
+ deallocvt 63
+ ;;
+ *)
+ ;;
+esac
diff --git a/pm/sleep.d/90clock b/pm/sleep.d/90clock
index 985b266..d824778 100755
--- a/pm/sleep.d/90clock
+++ b/pm/sleep.d/90clock
@@ -1,41 +1,22 @@
#!/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
+# TODO: 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
- ;;
+ hibernate|suspend) suspend_clock ;;
+ thaw|resume) resume_clock ;;
+ *) exit $NA ;;
esac
diff --git a/pm/sleep.d/95led b/pm/sleep.d/95led
index 253f0b6..b4bb970 100755
--- a/pm/sleep.d/95led
+++ b/pm/sleep.d/95led
@@ -1,15 +1,16 @@
#!/bin/sh
-# IBM specific hook to handle the suspend LED.
-# TODO: Merge with 05led.
+# On an IBM system. make the suspend LED blink.
+# TODO: Merge with 95led? Should be trivial.
[ -f /proc/acpi/ibm/led ] || exit $NA
case "$1" in
- thaw|resume)
+ hibernate|suspend)
echo "7 blink" >/proc/acpi/ibm/led
;;
- *)
+ thaw|resume)
+ echo "7 off" >/proc/acpi/ibm/led
+ ;;
+ *) exit $NA
;;
esac
-
-exit $NA