Hi,

this is my current implementation of userspace suspend support (with
automatic fallback if it is not available).
There is a second feature in there, around the $INHIBIT variable: it allows
a hook to prevent suspending. Right now i do this if i notice that the
currently running kernel is not available for resume (after a kernel update
but before the reboot, for example). If i know in advance that i will not
be able to resume, it does not make sense trying to suspend :-). Any hook
wanting to prevent suspend just has to "touch $INHIBIT" or "echo 'reason
why we cannot suspend' >> $INHIBIT".

Index: pm/functions
===================================================================
RCS file: /cvs/pm-utils/pm-utils/pm/functions,v
retrieving revision 1.26
diff -u -p -r1.26 functions
--- pm/functions        30 Oct 2006 15:40:42 -0000      1.26
+++ pm/functions        30 Oct 2006 21:20:36 -0000
@@ -4,9 +4,13 @@ export PATH=/sbin:/usr/sbin:/bin:/usr/bi
 
 # default values go here
 HIBERNATE_RESUME_POST_VIDEO=no
+HIBERNATE_METHOD=""
 SUSPEND_MODULES=""
 RESUME_MODULES=""
 PM_LOGFILE=${PM_LOGFILE:=/var/log/pm-suspend.log}
+INHIBIT=/var/run/pm-utils.inhibit
+S2DISK_BIN=/usr/sbin/s2disk
+S2DISK_CONF=/etc/suspend.conf
 
 [ -f /etc/pm/config ] && . /etc/pm/config
 
@@ -18,9 +22,13 @@ add_global() {
 
 # export them all here
 add_global HIBERNATE_RESUME_POST_VIDEO
+add_global HIBERNATE_METHOD
 add_global SUSPEND_MODULES
 add_global RESUME_MODULES
 add_global PM_LOGFILE
+add_global INHIBIT
+add_global S2DISK_BIN
+add_global S2DISK_CONF
 
 source_configs()
 {
@@ -113,6 +121,35 @@ get_power_status()
        return $RETVAL
 }
 
+do_suspend()
+{
+       if [ -x /usr/sbin/s2ram ]; then
+               /usr/sbin/s2ram $S2RAM_OPTS
+       else
+               echo -n "mem" > /sys/power/state
+       fi
+}
+
+do_hibernate()
+{
+       if [ -z "$HIBERNATE_METHOD" ]; then
+               if [ -x $S2DISK_BIN -a -c /dev/snapshot ]; then
+                       HIBERNATE_METHOD="userspace"
+               else
+                       HIBERNATE_METHOD="kernel"
+               fi
+       fi
+       case $HIBERNATE_METHOD in
+               userspace)
+                       $S2DISK_BIN -f $S2DISK_CONF
+                       ;;
+               kernel)
+                       echo -n "platform" > /sys/power/disk
+                       echo -n "disk" > /sys/power/state
+                       ;;
+       esac
+}
+
 pm_main()
 {
        if [ -n "$PM_LOGFILE" ]; then
@@ -120,17 +157,23 @@ pm_main()
                exec > "$PM_LOGFILE" 2>&1
        fi
        take_suspend_lock || exit 1
+
+       rm -f $INHIBIT
+
        run_hooks "$1"
        sync ; sync ; sync
 
        case "$1" in
                suspend)
-                       pm-pmu --suspend || echo -n "mem" > /sys/power/state
+                       if [ ! -e $INHIBIT ]; then
+                               pm-pmu --suspend || do_suspend
+                       fi
                        run_hooks resume reverse
                        ;;
                hibernate)
-                       echo -n "platform" > /sys/power/disk
-                       echo -n "disk" > /sys/power/state
+                       if [ ! -e $INHIBIT ]; then
+                               do_hibernate
+                       fi
                        run_hooks thaw reverse
                        ;;
        esac
-- 
Stefan Seyfried
QA / R&D Team Mobile Devices        |              "Any ideas, John?"
SUSE LINUX Products GmbH, Nürnberg  | "Well, surrounding them's out." 
_______________________________________________
Pm-utils mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/pm-utils

Reply via email to