summaryrefslogtreecommitdiffstats
path: root/hooks/resume
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-03-11 03:20:01 +0100
committerDave Reisner <dreisner@archlinux.org>2012-03-11 03:38:30 +0100
commit0a972cd469cba75836e8bbea50ed554a2ca184a5 (patch)
treeb05467c3978fecbd0222fab7822ba5dcefbbc725 /hooks/resume
parentd9563ccf4d2fd92e64114844645f90e86d469d50 (diff)
downloadmkinitcpio-0a972cd469cba75836e8bbea50ed554a2ca184a5.tar.gz
mkinitcpio-0a972cd469cba75836e8bbea50ed554a2ca184a5.tar.xz
hooks/resume: refactor
- cleanup syntax, style - use case to detect syntax (avoid problems with vanilla devspecs containing a ':') - support LABEL=/UUID= syntax for vanilla hibernation (FS#28504) - be more verbose about errors Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Diffstat (limited to 'hooks/resume')
-rw-r--r--hooks/resume62
1 files changed, 37 insertions, 25 deletions
diff --git a/hooks/resume b/hooks/resume
index 2079e05..04ca1aa 100644
--- a/hooks/resume
+++ b/hooks/resume
@@ -1,29 +1,41 @@
-# vim:set ft=sh:
-run_hook ()
-{
- if [ -n "${resume}" ]; then
- if [ "${resume}" != "${resume/:}" ]; then
- # Tux-on-ice syntax: swap:/dev/sda2 or file:/dev/sda2:0xdeadbeef
- resumedev=${resume#*:}
- resumedev=${resumedev%%:*}
- else
- # Classical syntax: just a device
- resumedev="${resume}"
- fi
- if poll_device "${resumedev}" ${rootdelay}; then
- if [ "${resume}" != "${resume/:}" ]; then
- # Try resuming with tuxonice
- tuxoniceroot="/sys/power/tuxonice"
- if [ -d "${tuxoniceroot}" ]; then
- echo ${resume} > ${tuxoniceroot}/resume
- echo > ${tuxoniceroot}/do_resume
- fi
+#!/usr/bin/ash
+
+run_hook () {
+ local resumedev
+
+ case $resume in
+ '')
+ err "resume: no device specified for hibernation"
+ return 1;
+ ;;
+ swap:*|file:*)
+ # tux-on-ice syntax: swap:/dev/sda2 or file:/dev/sda2:0xdeadbeef
+ if [ -d /sys/power/tuxonice ]; then
+ echo "$resume" >/sys/power/tuxonice/resume
+ echo >/sys/power/tuxonice/do_resume
+ return 0
else
- # Try resuming with vanilla hibernation
- if [ -e "/sys/power/resume" ]; then
- printf "%d:%d" $(stat -Lc "0x%t 0x%T" ${resume}) > /sys/power/resume
+ err "resume: tux-on-ice syntax detected, but no support found"
+ return 1
+ fi
+ ;;
+
+ *)
+ # standard hibernation
+ if resumedev=$(resolve_device "$resume" "$rootdelay"); then
+ if [ -e /sys/power/resume ]; then
+ printf "%d:%d" $(stat -Lc "0x%t 0x%T" "$resumedev") >/sys/power/resume
+ return 0
+ else
+ err "resume: no hibernation support found"
+ return 1
fi
fi
- fi
- fi
+ ;;
+ esac
+
+ err "resume: hibernation device '$resume' not found"
+ return 1
}
+
+# vim: set ft=sh ts=4 sw=4 et: