summaryrefslogtreecommitdiff
path: root/pm/functions.in
diff options
context:
space:
mode:
Diffstat (limited to 'pm/functions.in')
-rw-r--r--pm/functions.in125
1 files changed, 2 insertions, 123 deletions
diff --git a/pm/functions.in b/pm/functions.in
index bfa9a55..a7905ce 100644
--- a/pm/functions.in
+++ b/pm/functions.in
@@ -1,131 +1,10 @@
#!/bin/sh
# vim:noexpandtab
+# Common functionality for the hooks.
-# Default values go here. It is important to _not_ initialize some
-# variables here. They are:
-#
-# PM_CMDLINE
-# RESUME_MODULES
-#
# for great debugging!
-[ "${PM_DEBUG}" = "true" ] && {
- export PM_DEBUG
- set -x
-}
-set -a
-PM_UTILS_LIBDIR="@PM-UTILS-LIBDIR@"
-PM_UTILS_ETCDIR="@PM-UTILS-SYSCONFDIR@"
-PM_UTILS_RUNDIR="/var/run/pm-utils"
-
-PATH=/sbin:/usr/sbin:/bin:/usr/bin:"${PM_UTILS_LIBDIR}"/bin
-HIBERNATE_MODE="platform"
-HIBERNATE_RESUME_POST_VIDEO=no
-INHIBIT="${PM_UTILS_RUNDIR}/inhibit"
-PM_LOGFILE="${PM_LOGFILE:=/var/log/pm-suspend.log}"
-SUSPEND_MODULES=""
-TEMPORARY_CPUFREQ_GOVERNOR="performance"
-LOCKDIR="${PM_UTILS_RUNDIR}/locks"
-STORAGEDIR="${PM_UTILS_RUNDIR}/storage"
-SLEEP_MODULE="kernel"
-NA=254
-
-# Use c sort order
-export LC_COLLATE=C
-
-[ -f "${PM_UTILS_LIBDIR}"/defaults ] && . "${PM_UTILS_LIBDIR}"/defaults
-
-set +a
-
-for cfg in "${PM_UTILS_ETCDIR}"/config.d/*[!~] ; do
- [ -f "$cfg" ] || continue
- set -a
- . "${cfg}"
- set +a
-done
-
-take_suspend_lock()
-{
- VT=$(fgconsole)
- chvt 63
- try_lock "pm-utils.lock" || return 1
- mkdir -p "${STORAGEDIR}"
- return 0
-}
-
-remove_suspend_lock()
-{
- rm -rf "${STORAGEDIR}"
- chvt 1
- chvt $VT
- release_lock "pm-utils.lock"
-}
-
-hook_exit_status(){
- case $1 in
- 0) echo "success." ;;
- $NA) echo "not applicable." ;;
- *) echo "Returned exit code $1." ;;
- esac
-}
-
-run_hooks() {
- # $1 = type of hook to find.
- # $2 = paramaters to pass to hooks.
- # $3 = if present and equal to "reverse", run hooks backwards.
- # Currently only power and sleep are meaningful.
- local syshooks="${PM_UTILS_ETCDIR}/$1.d"
- local phooks="${PM_UTILS_LIBDIR}/$1.d"
- local sort="sort"
- local base
- local hook
- local oifs="${IFS}"
- # the next two lines are not a typo or a formatting error!
- local nifs="
-"
- IFS="${nifs}" # tolerate spaces in filenames.
- [ "$3" = "reverse" ] && sort="sort -r"
- for base in $(IFS="${oifs}"; for f in "$syshooks/"*[!~] "$phooks/"*[!~];
- do [ -O "$f" ] && echo ${f##*/} ; done | $sort | uniq) ;
- do
- if [ -f "$syshooks/$base" ]; then
- hook="$syshooks/$base"
- elif [ -f "$phooks/$base" ]; then
- hook="$phooks/$base"
- fi
- [ -x "${hook}" ] && (
- IFS="${oifs}"
- echo "$(date): running ${hook} $2"
- "${hook}" $2
- hook_exit_status $?
- )
- done
- IFS="${oifs}"
-}
-
-init_logfile()
-{
- if [ -h "$1" ]; then
- echo "$1 is a symbolic link, refusing to overwrite."
- return 1
- elif [ ! -O "$1" ]; then
- echo "We do not own $1, refusing to overwrite."
- return 1
- elif [ -z "$1" ]; then
- echo "Please pass a filename to init_logfile."
- return 1
- fi
- exec > "$1" 2>&1
-}
-
-
-SLEEP_FUNCTIONS="${PM_UTILS_LIBDIR}/module.d/${SLEEP_MODULE}"
-[ -f "${SLEEP_FUNCTIONS}" ] || {
- echo "Requested sleep module $SLEEP_MODULE not available."
- exit 1
-}
-
-. "${SLEEP_FUNCTIONS}"
+[ "${PM_DEBUG}" = "true" ] && set -x
# try to take the lock. Fail if we cannot get it.