[EMAIL PROTECTED] said:
> I'm familiar with hibernate script, but I see a couple of minor issues:

Thanks for looking at it. Here's a version that's less half-assed; the
last one was a quick search-and-replace job.

> suspend may fail, yet you don't propagate the return value. Is this
> correct?

I don't know. The other suspend methods don't propagate a return value,
because both in-kernel swsusp and suspend2 are triggered by
echo > /some/kernel/interface.

This version corrects the comments and error messages, checks for
/dev/snapshot, and gives an error message if s2disk fails.

Jason


# -*- sh -*-
# vim:ft=sh:ts=8:sw=4:noet

AddConfigHandler USuspendConfigEnabler
AddOptionHandler USuspendOptionHandler

AddConfigHelp "UseUSuspend" "Enables the use of the 's2disk' program for 
suspending the machine."

AddShortOption "n"
AddLongOption "no-suspend"
AddOptionHelp "-n, --no-suspend (requires UseUSuspend to be set)" "Disables 
actually suspending the system. This is useful for testing the suspend script 
itself."

SUSPEND_PROG=/usr/local/sbin/s2disk
SUSPEND_STATE_FILE=/sys/power/state
SUSPEND_DEVICE=/dev/snapshot

USuspendConfigEnabler() {
    [ "$1" != "useususpend" ] && return 1
    [ -n "$USING_SUSPEND_STATE" ] && return 0
    UsingSuspendMethod ususpend
    AddSuspendHook 10 EnsureUSuspendCapable
    AddSuspendHook 99 DoUSuspend
    USING_SUSPEND_STATE=$2
    return 0
}

USuspendOptionHandler() {
    [ -z "$USING_SUSPEND_STATE" ] && return 1
    case $1 in
        -n|--no-suspend)
            SUSPEND_STATE_NO_SUSPEND=1
            ;;
        *)
            return 1
    esac
    return 0
}

DoUSuspend() {
    if [ -z "$SUSPEND_STATE_NO_SUSPEND" ] ; then
        vecho 1 "$EXE: Running $SUSPEND_PROG ..."
        $SUSPEND_PROG || vecho 0 "$EXE: $SUSPEND_PROG failed."
    else
        vecho 1 "$EXE: Not actually suspending (--no-suspend given)."
    fi
    return 0
}

EnsureUSuspendCapable() {
    if ! test -x $SUSPEND_PROG ; then
        vecho 0 "$SUSPEND_PROG not installed."
        return 2
    fi
    if ! test -f $SUSPEND_STATE_FILE ; then
        vecho 0 "Your kernel does not have power management built in."
        return 2
    fi
    if ! test -c $SUSPEND_DEVICE ; then
        vecho 0 "$SUSPEND_DEVICE device not found."
        return 2
    fi

    return 0
}



_______________________________________________
Suspend-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/suspend-devel

Reply via email to