diff options
-rw-r--r-- | pm/functions.in | 17 | ||||
-rwxr-xr-x | pm/sleep.d/99video | 71 | ||||
-rw-r--r-- | src/pm-action.in | 44 |
3 files changed, 70 insertions, 62 deletions
diff --git a/pm/functions.in b/pm/functions.in index cc737c9..dbce365 100644 --- a/pm/functions.in +++ b/pm/functions.in @@ -34,6 +34,8 @@ export LC_COLLATE=C set +a +log() { [ $LOGGING ] && echo $*; } + source_configs() { for cfg in "${PM_UTILS_ETCDIR}"/config.d/*[!~] ; do @@ -48,7 +50,7 @@ source_configs SLEEP_FUNCTIONS="${PM_UTILS_LIBDIR}/module.d/${SLEEP_MODULE}" [ -f "${SLEEP_FUNCTIONS}" ] || { - echo "Requested sleep module $SLEEP_MODULE not available." + log "Requested sleep module $SLEEP_MODULE not available." exit 1 } @@ -121,9 +123,9 @@ command_exists() hook_exit_status(){ case $1 in - 0) echo "success." ;; - $NA) echo "not applicable." ;; - *) echo "Returned exit code $1." ;; + 0) log "success." ;; + $NA) log "not applicable." ;; + *) log "Returned exit code $1." ;; esac } @@ -153,7 +155,7 @@ run_hooks() { fi [ -x "${hook}" ] && ( IFS="${oifs}" - echo "$(date): running ${hook} $2" + log "$(date): running ${hook} $2" "${hook}" $2 hook_exit_status $? ) @@ -192,6 +194,7 @@ init_logfile() echo "Please pass a filename to init_logfile." return 1 fi + export LOGGING="true" exec > "$1" 2>&1 } @@ -201,7 +204,7 @@ _rmmod() touch "${STORAGEDIR}/module:$1" return 0 else - echo "# could not unload '$1', usage count was $2" + log "# could not unload '$1', usage count was $2" return 1 fi } @@ -257,7 +260,7 @@ if ! command_exists service; then shift "/etc/init.d/$svc" "$@" else - echo "$1" $": unrecognized service" 1>&2 + log "$1" $": unrecognized service" 1>&2 return 1 fi } diff --git a/pm/sleep.d/99video b/pm/sleep.d/99video index a0dc13d..de3d989 100755 --- a/pm/sleep.d/99video +++ b/pm/sleep.d/99video @@ -9,6 +9,26 @@ . "${PM_FUNCTIONS}" +for opt in $PM_CMDLINE; do + [ "${opt#--quirk-}" = "$opt" ] && continue # not one we care about. + case "${1##--quirk-}" in # just quirks, please + dpms-on) DPMS_ON="true" ;; + dpms-suspend) DPMS_SUSPEND="true" ;; + radeon-off) RADEON_OFF="true" ;; + reset-brightness) RESET_BRIGHTNESS="true" ;; + s3-bios) S3_BIOS="true" ;; + s3-mode) S3_MODE="true" ;; + vbe-post) VBE_POST="true" ;; + vbemode-restore) VBEMODE_RESTORE="true" ;; + vbestate-restore) VBESTATE_RESTORE="true" ;; + vga-mode3) VGA_MODE_3="true" ;; + none) QUIRK_NONE="true" ;; + *) continue ;; + esac + shift +done + + reset_brightness() { for bl in /sys/class/backlight/* ; do @@ -71,45 +91,58 @@ suspend_video() { # 0=nothing, 1=s3_bios, 2=s3_mode, 3=both local acpi_flag=0 - [ "${QUIRK_S3_BIOS}" = "true" ] && acpi_flag=$(($acpi_flag + 1)) - [ "${QUIRK_S3_MODE}" = "true" ] && acpi_flag=$(($acpi_flag + 2)) + [ "${S3_BIOS}" = "true" ] && acpi_flag=$(($acpi_flag + 1)) + [ "${S3_MODE}" = "true" ] && acpi_flag=$(($acpi_flag + 2)) sysctl -w kernel.acpi_video_flags=$acpi_flag - quirk "${QUIRK_VBESTATE_RESTORE}" && vbe_savestate - quirk "${QUIRK_VBEMODE_RESTORE}" && vbe_savemode - quirk "${QUIRK_RADEON_OFF}" && radeon_off - quirk "${QUIRK_VGA_MODE_3}" && vbe vbemode set 3 - quirk "${QUIRK_DPMS_SUSPEND}" && vbe dpms suspend + quirk "${VBESTATE_RESTORE}" && vbe_savestate + quirk "${VBEMODE_RESTORE}" && vbe_savemode + quirk "${RADEON_OFF}" && radeon_off + quirk "${VGA_MODE_3}" && vbe vbemode set 3 + quirk "${DPMS_SUSPEND}" && vbe dpms suspend save_fbcon # there should be a quirk, but HAL does not pass it. } resume_video() { # We might need to do one or many of these quirks - quirk "${QUIRK_VBE_POST}" && vbe_post - quirk "${QUIRK_VBESTATE_RESTORE}" && vbe_restorestate - quirk "${QUIRK_VBEMODE_RESTORE}" && vbe_restoremode + quirk "${VBE_POST}" && vbe_post + quirk "${VBESTATE_RESTORE}" && vbe_restorestate + quirk "${VBEMODE_RESTORE}" && vbe_restoremode resume_fbcon # also should be handled by a quirk. - quirk "${QUIRK_RADEON_OFF}" && radeon_on - quirk "${QUIRK_DPMS_ON}" && vbe dpms on - quirk "${QUIRK_RESET_BRIGHTNESS}" && reset_brightness + quirk "${RADEON_OFF}" && radeon_on + quirk "${DPMS_ON}" && vbe dpms on + quirk "${RESET_BRIGHTNESS}" && reset_brightness } +help() { + echo # first echo makes it look nicer. + echo "Video quirk handler options:" + echo + echo " --quirk-dpms-on" + echo " --quirk-dpms-suspend" + echo " --quirk-radeon-off" + echo " --quirk-reset-brightness" + echo " --quirk-s3-bios" + echo " --quirk-s3-mode" + echo " --quirk-vbe-post" + echo " --quirk-vbemode-restore" + echo " --quirk-vbestate-restore" + echo " --quirk-vga-mode3" + echo " --quirk-none" +} case "$1" in - suspend*) - suspend_video - ;; + suspend*) suspend_video ;; hibernate) if [ "$HIBERNATE_RESUME_POST_VIDEO" = "yes" ]; then suspend_video fi ;; - resume) - resume_video - ;; + resume) resume_video ;; thaw) if [ "${HIBERNATE_RESUME_POST_VIDEO}" = "yes" ]; then resume_video fi ;; + help) help ;; esac diff --git a/src/pm-action.in b/src/pm-action.in index f76f9ae..82aa295 100644 --- a/src/pm-action.in +++ b/src/pm-action.in @@ -26,25 +26,17 @@ # The rule here? Simplicity. +export PM_FUNCTIONS="@PM-UTILS-LIBDIR@/functions" +. "${PM_FUNCTIONS}" + +# save the command line parameters for the hooks. +export PM_CMDLINE="$*" help() { echo "${0##*/} [options]" echo - echo "Options can change how the supend or hibernate is done." - echo - echo "Possible actions are:" - echo - echo " --quirk-dpms-on" - echo " --quirk-dpms-suspend" - echo " --quirk-radeon-off" - echo " --quirk-reset-brightness" - echo " --quirk-s3-bios" - echo " --quirk-s3-mode" - echo " --quirk-vbe-post" - echo " --quirk-vbemode-restore" - echo " --quirk-vbestate-restore" - echo " --quirk-vga-mode3" - echo " --quirk-none" + echo "Options can change how suspend or hibernate is done." + run_hooks sleep help exit 0 } @@ -53,31 +45,13 @@ if [ -n "$EUID" -a "$EUID" != "0" ]; then exit 1 fi -# Get the command line options +# Save the command line options for the hooks while [ $# -gt 0 ] do - [ "${1##--}" = "$1" ] && break #if this matches, it is not an option! [ "$1" = "--help" ] && help - case "${1##--quirk-}" in # just quirks, please - dpms-on) export QUIRK_DPMS_ON="true" ;; - dpms-suspend) export QUIRK_DPMS_SUSPEND="true" ;; - radeon-off) export QUIRK_RADEON_OFF="true" ;; - reset-brightness) export QUIRK_RESET_BRIGHTNESS="true" ;; - s3-bios) export QUIRK_S3_BIOS="true" ;; - s3-mode) export QUIRK_S3_MODE="true" ;; - vbe-post) export QUIRK_VBE_POST="true" ;; - vbemode-restore) export QUIRK_VBEMODE_RESTORE="true" ;; - vbestate-restore) export QUIRK_VBESTATE_RESTORE="true" ;; - vga-mode3) export QUIRK_VGA_MODE_3="true" ;; - none) export QUIRK_NONE="true" ;; - *) continue ;; - esac shift done -export PM_FUNCTIONS="@PM-UTILS-LIBDIR@/functions" -. "${PM_FUNCTIONS}" - ACTION="$(echo ${0##*pm-} |tr - _)" case "$ACTION" in @@ -88,8 +62,6 @@ case "$ACTION" in exit 1 ;; esac -export PM_CMDLINE="$@" - "check_$ACTION" || { echo "System does not support $ACTION sleep."; exit 1; } take_suspend_lock || exit 1 |