diff options
author | Victor Lowther <victor.lowther@gmail.com> | 2008-09-17 21:41:26 -0500 |
---|---|---|
committer | Victor Lowther <victor.lowther@gmail.com> | 2008-09-17 21:41:26 -0500 |
commit | 04d25924f782d96ef55f164aea55e3d227a8a3ec (patch) | |
tree | 9c7c88d4e8a74c75ce50119979ed925ab9ba55e5 | |
parent | 38a9d169b831aa1528a47060612cba3dd5ff3514 (diff) |
Move the check_ functions to pm-functions.
Also conditionalize the do_ functions in the sleep modules. Now, we only
declare the actual do_ functions if the system can in fact sleep using
the requested method.
-rwxr-xr-x | pm/module.d/kernel | 54 | ||||
-rwxr-xr-x | pm/module.d/tuxonice | 57 | ||||
-rwxr-xr-x | pm/module.d/uswsusp | 82 | ||||
-rw-r--r-- | pm/pm-functions.in | 7 |
4 files changed, 90 insertions, 110 deletions
diff --git a/pm/module.d/kernel b/pm/module.d/kernel index 88a9e5d..ee71278 100755 --- a/pm/module.d/kernel +++ b/pm/module.d/kernel @@ -1,38 +1,24 @@ #!/bin/sh -check_suspend() -{ - [ -c /dev/pmu ] || grep -q mem /sys/power/state -} - -do_suspend() -{ - if [ -c /dev/pmu ]; then - pm-pmu --suspend - else - echo -n "mem" > /sys/power/state +if [ -z "$SUSPEND_MODULE" ]; then + if grep -q mem /sys/power/state; then + SUSPEND_MODULE="kernel" + do_suspend() { echo -n "mem" >/sys/power/state; } + elif [ -c /dev/pmu ] && pm-pmu --check; then + SUSPEND_MODULE="kernel" + do_suspend() { pm-pmu --suspend; } fi -} - -check_hibernate() -{ - [ -f /sys/power/disk ] && grep -q disk /sys/power/state -} - -do_hibernate() -{ - [ -n "${HIBERNATE_MODE}" ] && \ - grep -qw "${HIBERNATE_MODE}" /sys/power/disk && \ - echo -n "${HIBERNATE_MODE}" > /sys/power/disk - echo -n "disk" > /sys/power/state -} - -check_suspend_hybrid() -{ - return 1 -} +fi -do_suspend_hybrid() -{ - return 1 -} +if [ -z "$HIBERNATE_MODULE" ] && \ + [ -f /sys/power/disk ] && \ + grep -q disk /sys/power/state; then + HIBERNATE_MODULE="kernel" + do_hibernate() + { + [ -n "${HIBERNATE_MODE}" ] && \ + grep -qw "${HIBERNATE_MODE}" /sys/power/disk && \ + echo -n "${HIBERNATE_MODE}" > /sys/power/disk + echo -n "disk" > /sys/power/state + } +fi diff --git a/pm/module.d/tuxonice b/pm/module.d/tuxonice index 57b7bb8..f4e3de9 100755 --- a/pm/module.d/tuxonice +++ b/pm/module.d/tuxonice @@ -11,41 +11,26 @@ for loc in "/sys/power/tuxonice" "/sys/power/suspend2"; do [ -d "${loc}" ] && { TUXONICE_LOC="${loc}"; break; } done -check_suspend() -{ - [ -c /dev/pmu ] || grep -q mem /sys/power/state -} +if [ -z "$HIBERNATE_MODULE" -a -n "$TUXONICE_LOC" ] && \ + [ -f "${TUXONICE_LOC}/do_hibernate" ]; then + HIBERNATE_METHOD="tuxonice" + do_hibernate() + { + echo 5 > "${TUXONICE_LOC}/powerdown_method" + echo anything > "${TUXONICE_LOC}/do_hibernate" + } +fi -do_suspend() -{ - if [ -c /dev/pmu ]; then - pm-pmu --suspend - else - echo -n "mem" > /sys/power/state - fi -} - -check_hibernate() -{ - [ -f "${TUXONICE_LOC}/do_hibernate" ] -} - -do_hibernate() -{ - echo 5 > "${TUXONICE_LOC}/powerdown_method" - echo anything > "${TUXONICE_LOC}/do_hibernate" -} - -check_suspend_hybrid() -{ +if [ -z "$SUSPEND_HYBRID_MODULE" -a -n "$TUXONICE_LOC" ] && \ grep -q mem /sys/power/state && \ - [ -f "${TUXONICE_LOC}/do_hibernate" ] -} -do_suspend_hybrid() -{ - echo 3 >"${TUXONICE_LOC}/powerdown_method" - echo anything >"${TUXONICE_LOC}/do_hibernate" - [ -f /sys/power/tuxonice/did_suspend_to_both ] && \ - [ "$(cat /sys/power/tuxonice/did_suspend_to_both)" != "1" ] && \ - REVERSE="thaw" -} + [ -f "${TUXONICE_LOC}/do_hibernate" ]; then + SUSPEND_HYBRID_METHOD="tuxonice" + do_suspend_hybrid() + { + echo 3 >"${TUXONICE_LOC}/powerdown_method" + echo anything >"${TUXONICE_LOC}/do_hibernate" + [ -f /sys/power/tuxonice/did_suspend_to_both ] && \ + [ "$(cat /sys/power/tuxonice/did_suspend_to_both)" != "1" ] && \ + REVERSE="thaw" + } +fi diff --git a/pm/module.d/uswsusp b/pm/module.d/uswsusp index 615da3a..1bb1e68 100755 --- a/pm/module.d/uswsusp +++ b/pm/module.d/uswsusp @@ -33,44 +33,6 @@ uswsusp_get_quirks() [ "$QUIRK_NONE" = "true" ] && OPTS="" } -check_suspend() -{ - command_exists s2ram || return 1 - [ -c /dev/pmu ] || grep -q mem /sys/power/state -} - -do_suspend() -{ - uswsusp_get_quirks - s2ram --force $OPTS -} - -check_hibernate() -{ - [ -f /sys/power/disk ] && \ - grep -q disk /sys/power/state && \ - [ -c /dev/snapshot ] && - command_exists s2disk -} - -do_hibernate() -{ - s2disk -} - -check_suspend_hybrid() -{ - grep -q mem /sys/power/state && \ - command_exists s2both && \ - check_hibernate -} - -do_suspend_hybrid() -{ - uswsusp_get_quirks - s2both --force $OPTS -} - uswsusp_help() { echo # first echo makes it look nicer. @@ -90,5 +52,45 @@ uswsusp_help() echo " --quirk-none" } -add_module_help uswsusp_help -add_before_hooks uswsusp_hooks +if [ -z "$SUSPEND_METHOD" ] && command_exists s2ram && \ + ( grep -q mem /sys/power/state || \ + ( [ -c /dev/pmu ] && pm-pmu --check; ); ); then + SUSPEND_METHOD="uswsusp" + do_suspend() + { + uswsusp_get_quirks + s2ram --force $OPTS + } + if [ "$METHOD" = "suspend" ]; then + add_before_hooks uswsusp_hooks + add_module_help uswsusp_help + fi +fi + +if [ -z "$HIBERNATE_METHOD" ] && \ + [ -f /sys/power/disk ] && \ + grep -q disk /sys/power/state && \ + [ -c /dev/snapshot ] && + command_exists s2disk; then + HIBERNATE_METHOD="uswsusp" + do_hibernate() + { + s2disk + } +fi + +if [ -z "$SUSPEND_HYBRID_METHOD" ] && + grep -q mem /sys/power/state && \ + command_exists s2both && \ + check_hibernate; then + SUSPEND_HYBRID_METHOD="uswsusp" + do_suspend_hybrid() + { + uswsusp_get_quirks + s2both --force $OPTS + } + if [ "$METHOD" = "suspend_hybrid" ]; then + add_before_hooks uswsusp_hooks + add_module_help uswsusp_help + fi +fi diff --git a/pm/pm-functions.in b/pm/pm-functions.in index a9c8912..54c5fca 100644 --- a/pm/pm-functions.in +++ b/pm/pm-functions.in @@ -46,6 +46,9 @@ INHIBIT="${STORAGEDIR}/inhibit" PM_CMDLINE="$*" BEFORE_HOOKS="" MODULE_HELP="" +SUSPEND_MODULE="" +HIBERNATE_MODULE="" +SUSPEND_HYBRID_MODULE="" # when loading configuration files, allow stash-specific ones # to override the pm-utils global ones. @@ -233,6 +236,10 @@ init_logfile() exec > "$1" 2>&1 } +check_suspend() { [ -n "$SUSPEND_MODULE" ]; } +check_hibernate() { [ -n "$HIBERNATE_MODULE" ]; } +check_suspend_hybrid() { [ -n "$SUSPEND_HYBRID_MODULE" ]; } + SLEEP_FUNCTIONS="${PM_UTILS_LIBDIR}/module.d/${SLEEP_MODULE}" [ -f "${SLEEP_FUNCTIONS}" ] || { echo "Requested sleep module $SLEEP_MODULE not available." |