add powermanagement and disk utils

This commit is contained in:
Ertuğrul Erata
2015-07-31 10:59:10 +03:00
parent ada4e1ce08
commit 5ddcdd77d9
70 changed files with 3472 additions and 61 deletions
@@ -0,0 +1,43 @@
From 640b53438c20818b3e344343b58b1f1765606a85 Mon Sep 17 00:00:00 2001
From: Martin Pitt <martin.pitt@ubuntu.com>
Date: Mon, 31 Jan 2011 15:30:01 +0100
Subject: [PATCH] 49bluetooth: Wait for btusb module to get unused
The 49bluetooth hook disables /proc/acpi/ibm/bluetooth but this isn't
synchronous, i. e. it doesn't wait until the module usage count actually drops
to 0. Due to that, it's impossible to add btusb to SUSPEND_MODULES (on some
models/older kernels you need to do that to fix suspend problems), as at that
point the module is still in use.
On my system (ThinkPad X201) the module takes between 0.3 and 0.5 seconds to
unload, so use 100 ms wait steps with a timeout of 2 seconds.
Bug: https://bugs.freedesktop.org//show_bug.cgi?id=33759
Bug-Ubuntu: https://launchpad.net/bugs/698331
---
pm/sleep.d/49bluetooth | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/pm/sleep.d/49bluetooth b/pm/sleep.d/49bluetooth
index d46ba49..0dc1909 100755
--- a/pm/sleep.d/49bluetooth
+++ b/pm/sleep.d/49bluetooth
@@ -12,6 +12,15 @@ suspend_bluetooth()
if grep -q enabled /proc/acpi/ibm/bluetooth; then
savestate ibm_bluetooth enable
echo disable > /proc/acpi/ibm/bluetooth
+
+ # wait for up to 2 seconds for the module to actually get
+ # unused
+ TIMEOUT=20
+ while [ $TIMEOUT -ge 0 ]; do
+ [ `cat /sys/module/btusb/refcnt` = 0 ] && break
+ TIMEOUT=$((TIMEOUT-1))
+ sleep 0.1
+ done
else
savestate ibm_bluetooth disable
fi
--
1.7.2.3
@@ -0,0 +1,26 @@
Description: Disable SATA link power management by default, as it still causes disk errors and corruptions on many hardware.
Author: Martin Pitt <martin.pitt@ubuntu.com>
Bug-Ubuntu: https://launchpad.net/bugs/539467
Index: pm-utils/pm/power.d/sata_alpm
===================================================================
--- pm-utils.orig/pm/power.d/sata_alpm 2011-02-01 15:53:09.164867778 +0100
+++ pm-utils/pm/power.d/sata_alpm 2011-02-01 15:53:28.954867786 +0100
@@ -2,7 +2,7 @@
. "${PM_FUNCTIONS}"
-SATA_ALPM_ENABLE=${SATA_ALPM_ENABLE:-true}
+SATA_ALPM_ENABLE=${SATA_ALPM_ENABLE:-false}
help() {
cat <<EOF
@@ -16,7 +16,7 @@
This hook has 1 parameter:
SATA_ALPM_ENABLE = whether to use SATA ALPM on battery.
-Defaults to "true".
+Defaults to "false".
EOF
}
@@ -0,0 +1,40 @@
From: Florian Kriener <florian@kriener.org>
To: submit@bugs.debian.org
Subject: [pm-utils] wrong path in intel-audio-powersave (and a small bug)
Date: Sat, 25 Sep 2010 11:27:30 +0200
In the script intel-audio-powersave is this loop
for dev in /sys/module/snd_*/parameters/power_save; do
[ -w "$dev/parameters/power_save" ] || continue
printf "Setting power savings for $s to %d..." "$dev##*/" "$1"
echo $1 > "$dev/parameters/power_save" && echo Done. || echo Failed.
done
I think it should be
for dev in /sys/module/snd_*; do
[ -w "$dev/parameters/power_save" ] || continue
printf "Setting power savings for %s to %d..." "${dev##*/}" "$1"
echo $1 > "$dev/parameters/power_save" && echo Done. || echo Failed.
done
This fixes the two bugs.
diff --git a/pm/power.d/intel-audio-powersave b/pm/power.d/intel-audio-powersave
index 36675a8..da63e40 100644
--- a/pm/power.d/intel-audio-powersave
+++ b/pm/power.d/intel-audio-powersave
@@ -20,9 +20,9 @@ EOF
audio_powersave() {
[ "$INTEL_AUDIO_POWERSAVE" = "true" ] || exit $NA
- for dev in /sys/module/snd_*/parameters/power_save; do
+ for dev in /sys/module/snd_*; do
[ -w "$dev/parameters/power_save" ] || continue
- printf "Setting power savings for $s to %d..." "$dev##*/" "$1"
+ printf "Setting power savings for %s to %d..." "${dev##*/}" "$1"
echo $1 > "$dev/parameters/power_save" && echo Done. || echo Failed.
done
}
@@ -0,0 +1,19 @@
Author: James Westby <james.westby@ubuntu.com>
Description: Do not clear the log file on each operation, but instead append to it.
This makes debugging of several suspends much easier.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=25255
Bug-Ubuntu: https://launchpad.net/bugs/410352
Index: pm-utils/pm/pm-functions.in
===================================================================
--- pm-utils.orig/pm/pm-functions.in 2010-07-05 18:41:21.118322244 +0200
+++ pm-utils/pm/pm-functions.in 2010-07-05 18:41:24.126325221 +0200
@@ -271,7 +271,7 @@
return 1
fi
export LOGGING=true
- exec > "$1" 2>&1
+ exec >> "$1" 2>&1
}
check_suspend() { [ -n "$SUSPEND_MODULE" ]; }
@@ -0,0 +1,8 @@
#!/bin/sh
# Check for and abort a hibernate if the kernel indicates it has been
# updated, as we will be completly unable to resume.
if [ "$1" = "hibernate" ] && [ -f "/run/do-not-hibernate" ]; then
echo "kernel update inhibits hibernate (/run/do-not-hibernate present)"
exit 1
fi
@@ -0,0 +1,24 @@
#!/bin/sh
# Launch plymouth daemon if necessary
. "${PM_FUNCTIONS}"
# Fail if no plymouthd
command_exists plymouthd || exit $NA
# Check for splash parameter in /proc/cmdline
grep -qw "splash" /proc/cmdline || exit $NA
launch_plymouthd()
{
/sbin/plymouthd --mode=suspend
return 0
}
case "$1" in
hibernate|suspend)
launch_plymouthd
;;
*) exit $NA
;;
esac
@@ -0,0 +1,71 @@
#!/bin/bash
# vim:noexpandtab
#
# Author: Till Maas <opensource till name>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
PATH=/sbin:/bin:/usr/sbin:/usr/bin
source "${PM_FUNCTIONS}"
source /etc/pm/config.d/hd-apm-restore.conf
HD_APM_DEVICES=""
for udi in $(hal-find-by-capability --capability storage)
do
drive_type=$(hal-get-property --udi "${udi}" --key storage.drive_type)
if [ "${drive_type}" == "disk" ]
then
HD_APM_DEVICES+="$(hal-get-property --udi "${udi}" --key block.device | sed 's,^/dev/,,') "
fi
done
case "$1" in
hibernate|suspend)
for DEVICE in ${HD_APM_DEVICES}
do
HD_APM_FEATURE=$(hdparm -I "/dev/${DEVICE}" | grep "Advanced Power Management feature set")
if [[ "${HD_APM_FEATURE}" != "" ]]
then
if (echo "${HD_APM_FEATURE}" | grep -q "*" )
then
HD_APM_LEVEL=$(hdparm -I "/dev/${DEVICE}" | grep "Advanced power management level" | cut -d" " -f 5)
else
HD_APM_LEVEL=255
fi
if [[ "${HD_APM_LEVEL}" != "unknown" ]]
then
echo "saving level ${HD_APM_LEVEL} for device ${DEVICE}"
savestate "${DEVICE}" "${HD_APM_LEVEL}"
else
echo "Advanced Power Management value of device ${DEVICE} unknown"
fi
else
echo "Advanced Power Management not supported by device ${DEVICE}."
fi
done
;;
thaw|resume)
for DEVICE in ${HD_APM_DEVICES}
do
HD_APM_LEVEL=$(restorestate "${DEVICE}")
if [[ "${HD_APM_LEVEL}" != "" ]]
then
echo "restoring level ${HD_APM_LEVEL} for device ${DEVICE}"
hdparm -B "${HD_APM_LEVEL}" "/dev/${DEVICE}"
fi
done
;;
*)
;;
esac
exit $?
@@ -0,0 +1,26 @@
Index: pm-utils-1.4.1/pm/module.d/uswsusp
===================================================================
--- pm-utils-1.4.1.orig/pm/module.d/uswsusp
+++ pm-utils-1.4.1/pm/module.d/uswsusp
@@ -82,6 +82,7 @@ fi
if [ -z "$HIBERNATE_MODULE" ] && \
[ -f /sys/power/disk ] && \
grep -q disk /sys/power/state && \
+ grep -q "resume=" /proc/cmdline && \
[ -c /dev/snapshot ] &&
command_exists s2disk; then
HIBERNATE_MODULE="uswsusp"
Index: pm-utils-1.4.1/pm/pm-functions.in
===================================================================
--- pm-utils-1.4.1.orig/pm/pm-functions.in
+++ pm-utils-1.4.1/pm/pm-functions.in
@@ -306,7 +306,8 @@ fi
if [ -z "$HIBERNATE_MODULE" ] && \
[ -f /sys/power/disk ] && \
- grep -q disk /sys/power/state; then
+ grep -q disk /sys/power/state && \
+ grep -q "resume=" /proc/cmdline; then
HIBERNATE_MODULE="kernel"
do_hibernate()
{
@@ -0,0 +1,99 @@
Index: pm-utils-1.4.1/configure.ac
===================================================================
--- pm-utils-1.4.1.orig/configure.ac
+++ pm-utils-1.4.1/configure.ac
@@ -41,7 +41,6 @@ man/Makefile
src/Makefile
pm/Makefile
pm/sleep.d/Makefile
-pm/power.d/Makefile
pm/module.d/Makefile
])
Index: pm-utils-1.4.1/man/Makefile.am
===================================================================
--- pm-utils-1.4.1.orig/man/Makefile.am
+++ pm-utils-1.4.1/man/Makefile.am
@@ -2,7 +2,6 @@ pm_mans = \
on_ac_power.1 \
pm-is-supported.1 \
pm-pmu.8 \
- pm-powersave.8 \
pm-action.8
if HAVE_XMLTO
@@ -13,7 +12,6 @@ EXTRA_DIST = \
on_ac_power.xml \
pm-pmu.xml \
pm-is-supported.xml \
- pm-powersave.xml \
pm-action.xml \
$(pm_mans)
Index: pm-utils-1.4.1/pm/sleep.d/Makefile.am
===================================================================
--- pm-utils-1.4.1.orig/pm/sleep.d/Makefile.am
+++ pm-utils-1.4.1/pm/sleep.d/Makefile.am
@@ -2,8 +2,7 @@ sleepdir = $(libdir)/pm-utils/sleep.d
sleep_SCRIPTS = \
00logging \
- 00powersave \
- 01grub \
+ 01grub \
49bluetooth \
55NetworkManager \
75modules \
Index: pm-utils-1.4.1/pm/Makefile.am
===================================================================
--- pm-utils-1.4.1.orig/pm/Makefile.am
+++ pm-utils-1.4.1/pm/Makefile.am
@@ -1,6 +1,5 @@
SUBDIRS = \
sleep.d \
- power.d \
module.d
pm_libdir = $(libdir)/pm-utils
Index: pm-utils-1.4.1/pm/HOWTO.hooks
===================================================================
--- pm-utils-1.4.1.orig/pm/HOWTO.hooks
+++ pm-utils-1.4.1/pm/HOWTO.hooks
@@ -24,12 +24,6 @@ The actual sleep method being used will
if your hook needs to handle suspend-hybrid (or any other platform-specific
sleep method), it should examine the second parameter.
-For hooks in power.d, the potential values of that parameter are:
-true -- the hook MUST perform whatever action is appropriate when the system
- transitions TO battery power.
-false -- The hook MUST perform whatever action is appropriate when the system
- transitions FROM battery power.
-
NAMING SCHEME
All hooks are run in lexical sort order according to the C locale.
@@ -44,8 +38,7 @@ Any other return code is interpreted by
from the hook that it should abort whatever it is doing. When running sleep.d
hooks, that means that pm-utils stops running hooks, aborts the suspend/resume
process, calls any hooks that ran successfully prior to this one with the
-appropriate wakeup options, and exits with a non-zero exit code. When running
-power.d hooks, any hooks after this one will be skipped.
+appropriate wakeup options, and exits with a non-zero exit code.
SLEEP.D SPECIFIC NOTES
Index: pm-utils-1.4.1/src/Makefile.am
===================================================================
--- pm-utils-1.4.1.orig/src/Makefile.am
+++ pm-utils-1.4.1/src/Makefile.am
@@ -16,9 +16,7 @@ bin_SCRIPTS = pm-is-supported
dist_bin_SCRIPTS = on_ac_power
-sbin_SCRIPTS = pm-powersave
-
-script_in_files = pm-action.in pm-is-supported.in pm-powersave.in service
+script_in_files = pm-action.in pm-is-supported.in service
CLEANFILES = $(script_in_files:.in=)
@@ -0,0 +1,12 @@
# Config file for hd-apm-restore hook
# Devices, where the hd apm value should be restored, separated by space
#HD_APM_DEVICES="sda"
# Use this to overwrite a value for a device in case hdparm reports
# "unknown value" for the apm level. This is ignored when hdparm
# returns an other value.
#savestate sda 192
#savestate sdb 192
#savestate sdc 192
#savestate sdd 192
@@ -0,0 +1,25 @@
# This file configures the ability to wake from suspend or hibernate
# at a given time. It is used in conjunction with the 02rtcwake hook.
# Whether to respect the user-passed-in num_seconds_to_sleep
# If off, then the system configuration (below) will be used even if
# the user passes in a num_seconds_to_sleep.
#USER_RTCWAKE_ALLOWED="no"
USER_RTCWAKE_ALLOWED="yes"
# Should we wake up from suspend on a given time?
# if those are set to "no", the configuration values below have no effect.
#SUSPEND_RTCWAKE_ENABLED="yes"
#HIBERNATE_RTCWAKE_ENABLED="yes"
SUSPEND_RTCWAKE_ENABLED="no"
HIBERNATE_RTCWAKE_ENABLED="no"
# Time to wake up in local, 24-hour time
#RTCWAKE_TIME="22:30"
#RTCWAKE_TIME="9:00"
# Days to wake up (1=monday, 7=sunday), in increasing order,
# with a single space between each day
#RTCWAKE_DAYS="1 2 3 4 5"
#RTCWAKE_DAYS="1 3 5"
#RTCWAKE_DAYS="1 2 3 4 5 6 7"
@@ -0,0 +1,202 @@
#!/bin/bash
#
# Stefan Seyfried, SUSE Linux Products GmbH 2006, GPL v2
# mostly taken from the powersave project.
GRUBONCE="/usr/sbin/grubonce"
GRUBDEFAULT="/boot/grub/default"
GRUBDEFSAVE="/run/suspend.grubonce.default"
#####################################################################
# gets a list of available kernels from /boot/grub/menu.lst
# kernels are in the array $KERNELS, output to stdout to be eval-ed.
getkernels()
{
# DEBUG "Running getkernels()" INFO
local MENU_LST="/boot/grub/menu.lst"
local I DUMMY MNT ROOTDEV
declare -i I=0 J=-1
# we need the root partition later to decide if this is the kernel to select
while read ROOTDEV MNT DUMMY; do
[ "$ROOTDEV" = "rootfs" ] && continue # not what we are searching for
if [ "$MNT" = "/" ]; then
break
fi
done < /proc/mounts
# build an array KERNELS with all the kernels in /boot/grub/menu.lst
# the array MENU_ENTRIES contains the corresponding menu entry numbers
# DEFAULT_BOOT contains the default entry.
while read LINE; do
case $LINE in
title*)
let J++ # increase for every menu entry, even for non-linux
# DEBUG "Found grub menu entry #${J}: '${LINE}'" INFO
;;
default*)
DUMMY=($LINE) # "default 0 #maybe a comment"
echo "DEFAULT_BOOT=${DUMMY[1]}" # ^^[0]^^ 1 ^^[2]^ 3 ^^[4]^^
# DEBUG "Default boot entry is '${DUMMY[1]}'" INFO
;;
kernel*noresume*)
# we probably found the "failsafe" kernel that won't resume...
echo " Skipping grub entry #${J}, because it has the noresume option" >&2
;;
kernel*root=*)
local ROOT
ROOT=${LINE#*root=}
DUMMY=($ROOT)
ROOT=${DUMMY[0]}
if [ "$(echo $ROOT | grep LABEL)" ]; then
LABEL=`echo $ROOT | cut -d"=" -f2`
ROOT=`readlink -f /dev/disk/by-label/$LABEL`
elif [ "$(echo $ROOT | grep UUID)" ]; then
UUID=`echo $ROOT | cut -d"=" -f2`
ROOT=`readlink -f /dev/disk/by-uuid/$UUID`
fi
if [ "$(stat -Lc '%t:%T' $ROOT)" != "$(stat -Lc '%t:%T' $ROOTDEV)" ]; then
echo " Skipping grub entry #${J}, because its root= parameter ($ROOT)" >&2
echo " does not match the current root device ($ROOTDEV)." >&2
continue
fi
DUMMY=($LINE) # kernel (hd0,1)/boot/latestkernel-ABC root=/dev/hda2
echo "KERNELS[$I]='${DUMMY[1]##*/}'" # latestkernel-ABC
echo "MENU_ENTRIES[$I]=$J"
# DEBUG "Found kernel entry #${I}: '${DUMMY[1]##*/}'" INFO
let I++
;;
kernel*)
# a kernel without "root="? We better skip that one...
echo " Skipping grub entry #${J}, because it has no root= option" >&2
;;
*) ;;
esac
done < $MENU_LST
}
#############################################################
# runs grubonce from the grub package to select which kernel
# to boot on next startup
grub-once()
{
if [ -x "$GRUBONCE" ]; then
rm -f "$GRUBDEFSAVE"
if [ -e "$GRUBDEFAULT" ]; then
echo " saving original $GRUBDEFAULT"
cp "$GRUBDEFAULT" "$GRUBDEFSAVE"
fi
echo " running '$GRUBONCE $1'"
$GRUBONCE $1
else
echo "WARNING: $GRUBONCE not found, not preparing bootloader"
fi
}
#############################################################
# restore grub default after (eventually failed) resume
grub-once-restore()
{
echo "INFO: running grub-once-restore"
rm -f "$GRUBDEFAULT"
if [ -e "$GRUBDEFSAVE" ]; then
echo " restoring original $GRUBDEFAULT"
mv "$GRUBDEFSAVE" "$GRUBDEFAULT"
fi
}
#############################################################################
# try to find a kernel image that matches the actually running kernel.
# We need this, if more than one kernel is installed. This works reasonably
# well with grub, if all kernels are named "kernel-`uname -r`" and are
# located in /boot. If they are not, good luck ;-)
find-kernel-entry()
{
NEXT_BOOT=-1
ARCH=`uname -m`
declare -i I=0
# DEBUG "running kernel: $RUNNING" DIAG
while [ -n "${KERNELS[$I]}" ]; do
BOOTING="${KERNELS[$I]}"
if IMAGE=`readlink /boot/$BOOTING` && [ -e "/boot/${IMAGE##*/}" ]; then
# DEBUG "Found kernel symlink $BOOTING => $IMAGE" INFO
BOOTING=$IMAGE
fi
case $ARCH in
ppc*) BOOTING="${BOOTING#*vmlinux-}" ;;
*) BOOTING="${BOOTING#*kernel-}" ;;
esac
if [ "$RUNNING" == "$BOOTING" ]; then
NEXT_BOOT=${MENU_ENTRIES[$I]}
echo " running kernel is grub menu entry $NEXT_BOOT (${KERNELS[$I]})"
break
fi
let I++
done
# if we have not found a kernel, issue a warning.
# if we have found a kernel, we'll do "grub-once" later, after
# prepare_suspend finished.
if [ $NEXT_BOOT -eq -1 ]; then
echo "WARNING: no kernelfile matching the running kernel found"
fi
}
#############################################################################
# if we did not find a kernel (or BOOT_LOADER is not GRUB) check,
# if the running kernel is still the one that will (probably) be booted for
# resume (default entry in menu.lst or, if there is none, the kernel file
# /boot/latestkernel points to.)
# This will only work, if you use "original" SUSE kernels.
# you can always override with the config variable set to "yes"
prepare-grub()
{
echo "INFO: running prepare-grub"
eval `getkernels`
RUNNING=`uname -r`
find-kernel-entry
RET=0
if [ $NEXT_BOOT -eq -1 ]; then
# which kernel is booted with the default entry?
BOOTING="${KERNELS[$DEFAULT_BOOT]}"
# if there is no default entry (no menu.lst?) we fall back to
# the default of /boot/latestkernel.
[ -z "$BOOTING" ] && BOOTING="latestkernel"
if IMAGE=`readlink /boot/$BOOTING` && [ -e "/boot/${IMAGE##*/}" ]; then
BOOTING=$IMAGE
fi
BOOTING="${BOOTING#*kernel-}"
echo "running kernel: '$RUNNING', probably booting kernel: '$BOOTING'"
if [ "$BOOTING" != "$RUNNING" ]; then
echo "ERROR: kernel version mismatch, cannot suspend to disk"
echo "running: $RUNNING booting: $BOOTING" >> $INHIBIT
RET=1
fi
else
# set the bootloader to the running kernel
echo " preparing boot-loader: selecting entry $NEXT_BOOT, kernel /boot/$BOOTING"
T1=`date +"%s%N"`
sync; sync; sync # this is needed to speed up grub-once on reiserfs
T2=`date +"%s%N"`
echo " grub-once: `grub-once $NEXT_BOOT`"
T3=`date +"%s%N"`
S=$(((T2-T1)/100000000)); S="$((S/10)).${S:0-1}"
G=$(((T3-T2)/100000000)); G="$((G/10)).${G:0-1}"
echo " time needed for sync: $S seconds, time needed for grub: $G seconds."
fi
return $RET
}
###### main()
case $1 in
hibernate)
prepare-grub
;;
thaw)
grub-once-restore
;;
esac
@@ -0,0 +1,106 @@
#!/bin/sh
#
# Written by Gabriel Burt <gburt@novell.com>
# Copyright 2008 Novell, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# Use rtcwake to wake the computer from sleep or hibernate
# as configured in /etc/pm/config.d/rtcwake.config
. "${PM_FUNCTIONS}"
rtcwake_cmd="/usr/sbin/rtcwake";
command_exists $rtcwake_cmd || exit $NA
rtcwake_config_file="/etc/pm/config.d/rtcwake.conf"
function start_of_day {
echo `date -d "$1" "+%D"`
}
function since_epoch {
echo `date -d "$1" "+%s"`
}
function day_of_week {
echo `date -d "$1" "+%u"`
}
function isAlarmDow {
is=0
for dow in $RTCWAKE_DAYS; do
if test "x$dow" = "x$1"; then
is=1;
break;
fi
done
echo $is
}
function set_alarm
{
# If USER_RTCWAKE_ALLOWED is yes and the user passed in a num_seconds_to_sleep variable, then
# we will respect it (and ignore the system config)
# Do require that the number of seconds is at least 30 though.
if test "x$USER_RTCWAKE_ALLOWED" != "xno" && test "x$NUM_SECONDS_TO_SLEEP" != "x" && test $(($NUM_SECONDS_TO_SLEEP > 30)) == 1; then
echo "Have NUM_SECONDS_TO_SLEEP: $NUM_SECONDS_TO_SLEEP";
# Actually set/configure the rtcwake
sh -c "$rtcwake_cmd -m on -s $NUM_SECONDS_TO_SLEEP &"
elif test "x$1" = "xyes"; then
echo "alarm enabled, configuring rtcwake...";
echo "RTCWAKE time: $RTCWAKE_TIME";
echo "RTCWAKE days: $RTCWAKE_DAYS";
next_alarm=0
now=$(since_epoch now);
# The next alarm has to be at most 7 days from now
for days_from_now in 0 1 2 3 4 5 6 7; do
# Get the date N days from now
alarm_day=$(start_of_day "$days_from_now day");
# Check that this day is an alarm-enabled day of the week
alarm_dow=$(day_of_week $alarm_day);
is_alarm_dow=$(isAlarmDow $alarm_dow);
if test "x$is_alarm_dow" = "x1"; then
# Get the actual alarm time on that day
alarm_time=$(since_epoch "$alarm_day $RTCWAKE_TIME");
# Ensure the alarm time is more than 15 minutes from now
# - otherwise we set the alarm for the next slot
# 900 seconds = 15 minutes * 60 seconds/minute
is_enough_in_future=$(($alarm_time - $now > 900));
if test "x$is_enough_in_future" = "x1"; then
next_alarm=$alarm_time
break;
fi
fi
done
if test "x$next_alarm" != "x0"; then
# Recalculate now to be as accurate as possible
now=$(since_epoch now);
seconds_from_now=$(($next_alarm - $now));
echo "Will set alarm for $seconds_from_now seconds from now, at $alarm_day $RTCWAKE_TIME ($next_alarm)"
# Actually set/configure the rtcwake
sh -c "$rtcwake_cmd -m on -s $seconds_from_now &"
else
echo "No acceptable time found to set the rtcwake alarm. Review your configuration in $rtcwake_config_file"
exit $NA
fi
else
echo "rtcwake alarm not enabled in $rtcwake_config_file, doing nothing...";
exit $NA
fi
}
case "$1" in
suspend) set_alarm $SUSPEND_RTCWAKE_ENABLED ;;
hibernate) set_alarm $HIBERNATE_RTCWAKE_ENABLED ;;
*) exit $NA ;;
esac
@@ -0,0 +1,162 @@
#!/bin/bash
#
# Stefan Seyfried, SUSE Linux Products GmbH, 2006
# mostly taken from the powersave project
. "${PM_FUNCTIONS}"
# sanity check the environment if resume will be possible after hibernate
checkhibernate()
{
echo "INFO: checking for suspend-to-disk prerequisites..."
if [ -z "$IMAGE_SIZE" ]; then
IMAGE_SIZE="`awk '/^MemTotal:/ { print int($2*1024*.45) }' /proc/meminfo`"
fi
# Default to partition style hibernation
SWAP_TYPE=partition
read CMDLINE < /proc/cmdline
for CMD in $CMDLINE; do
case $CMD in
resume=*)
RESUME=${CMD#*=}
;;
resume_offset=*)
# Swap type is file as resume_offset is given
SWAP_TYPE=file
;;
esac
done
if [ -z "$RESUME" ]; then
# No resume= given in /proc/cmdline, failing.
echo "ERROR: no resume parameter on kernel commandline, can not suspend"
echo "no resume parameter on kernel commandline" >> $INHIBIT
return 1
fi
if [ "$SWAP_TYPE" = file ] && [ "$SLEEP_MODULE" = "uswsusp" ]; then
# File-style hibernating is not supported by uswsusp
echo "ERROR: You must use the kernel hibernate method or tuxonice when suspending to swapfile, not uswsusp"
echo "suspend to swapfile with uswsusp method not kernel" >> $INHIBIT
return 1
fi
# the resume device can be a symlink, e.g. with LVM/EVMS or with
# /dev/disk/by-id/foo
RESUME=$(readlink -f $RESUME)
OK=
while read DEV TYPE SIZE USED PRI; do
if [ "$TYPE" = "file" ] && [ "$SWAP_TYPE" = "file" ] && [ "$RESUME" = "$(df "$DEV" | tail -n +2 | cut -d ' ' -f 1)" ]; then
OK=1
break
fi
[ "$TYPE" != "partition" ] && continue
[ "$DEV" != "$RESUME" ] && continue
FREE=$[($SIZE-$USED)*1024] # get free space on DEV
if [ $FREE -lt $IMAGE_SIZE ]; then
IMAGE_SIZE=$[$FREE-10*1024*1024]
fi
OK=1
break # we found the partition, no need to look further
done < /proc/swaps
if [ -z "$OK" ]; then
if [ "$SWAP_TYPE" = "file" ]; then
MSG_TYPE="swap file"
else
MSG_TYPE="resume partition"
fi
echo "ERROR: $MSG_TYPE '$RESUME' not active, can not suspend"
echo "$MSG_TYPE '$RESUME' not active" >> $INHIBIT
return 1
fi
if [ "$SLEEP_MODULE" = "kernel" ]; then
echo " using kernel suspend method"
read DEV < /sys/power/resume
if [ "$DEV" = "0:0" ]; then
echo "ERROR: no resume partition set up in /sys/power/resume"
# maybe "resume=..." was given, but initrd did not set up
# /sys/power/resume correctly.
echo "resume device not correctly setup in /sys/power/resume" >> \
$INHIBIT
return 1
fi
X=$(stat -Lc '$((0x%t)):$((0x%T))' $RESUME)
RDEV=$(eval echo $X)
if [ "$DEV" != "$RDEV" ]; then
echo "ERROR: /sys/power/resume ($DEV) disagrees with resume= parameter ($RDEV)"
echo " can not suspend."
echo "/sys/power/resume disagrees with resume= parameter" >> \
$INHIBIT
return 1
fi
if [ -n "$IMAGE_SIZE" -a -w /sys/power/image_size ]; then
echo " setting image size to $IMAGE_SIZE"
echo "$IMAGE_SIZE" > /sys/power/image_size 2>/dev/null
fi
fi
if [ "$SLEEP_MODULE" = "uswsusp" ]; then
echo " using userspace suspend method, temp. config file $S2DISK_CONF"
if [ "$S2DISK_CONF" != "/etc/suspend.conf" ]; then
rm -f $S2DISK_CONF
# Generate S2DISK_CONF
echo " setting resume device to $RESUME"
echo "resume device = $RESUME" >> $S2DISK_CONF
if [ -n "$IMAGE_SIZE" ]; then
echo " setting image size to $IMAGE_SIZE"
echo "image size = $IMAGE_SIZE" >> $S2DISK_CONF
fi
# add the parameters from /etc/suspend.conf to /var/lib/s2disk.conf
if [ -e /etc/suspend.conf ]; then
echo "# parameters taken from /etc/suspend.conf:" >> $S2DISK_CONF
sed '/^[[:space:]]*\(#\|$\)/d;' /etc/suspend.conf >> $S2DISK_CONF
echo " adding these parameters from /etc/suspend.conf:"
sed '/^[[:space:]]*\(#\|$\)/d;s/^/ /;' /etc/suspend.conf
fi
else
# don't overwrite the user's config file, but warn about the issue
echo "WARNING: S2DISK_CONF is set to /etc/suspend.conf"
echo " Disabling automatic generation of config file."
echo " This is most likely a configuration error and will cause problems"
echo " unless you configure /etc/suspend.conf completely on your own!"
fi
fi
return 0
}
# this only makes sense on hibernate or on suspend-hybrid
case $1 in
hibernate)
;;
suspend)
if [ "$2" != suspend_hybrid ]; then
exit 0
fi
;;
*)
exit $NA
;;
esac
[ -e /etc/pm/config.d/$1 ] && . /etc/pm/config.d/$1
if [ -z "$SLEEP_MODULE" ]; then
# Decide the SLEEP_MODULE if not given
if [ -x /usr/sbin/s2disk -a -c /dev/snapshot ]; then
SLEEP_MODULE="uswsusp"
else
SLEEP_MODULE="kernel"
fi
fi
if ! checkhibernate; then
echo "WARNING: $INHIBIT will be created to prevent suspending!"
touch $INHIBIT
exit 1
fi
exit 0
@@ -0,0 +1,21 @@
#!/bin/bash
. "${PM_FUNCTIONS}"
command_exists /sbin/pccardctl || exit $NA
case "$1" in
hibernate|suspend)
echo "ejecting PCMCIA cards..."
/sbin/pccardctl eject
;;
thaw|resume)
echo "inserting PCMCIA cards..."
/sbin/pccardctl insert
;;
*) exit $NA
;;
esac
exit 0
@@ -0,0 +1,15 @@
#!/bin/bash
# The ndiswrapper hook - relead the ndiswrapper module
. "${PM_FUNCTIONS}"
command_exists /usr/sbin/ndiswrapper || return $NA
case "$1" in
resume|thaw)
modprobe -r ndiswrapper
modprobe ndiswrapper
;;
*) exit $NA
;;
esac
@@ -0,0 +1,20 @@
Index: pm-utils-1.4.1/pm/sleep.d/55NetworkManager
===================================================================
--- pm-utils-1.4.1.orig/pm/sleep.d/55NetworkManager 2010-09-20 11:12:23.750155840 +0200
+++ pm-utils-1.4.1/pm/sleep.d/55NetworkManager 2010-09-20 11:12:25.610155850 +0200
@@ -13,6 +13,7 @@
# Tell NetworkManager to shut down networking
printf "Having NetworkManager put all interaces to sleep..."
dbus_send --system \
+ --print-reply --reply-timeout=200 \
--dest=org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager \
org.freedesktop.NetworkManager.sleep && \
@@ -25,6 +26,7 @@
printf "Having NetworkManager wake interfaces back up..."
dbus_send --system \
--dest=org.freedesktop.NetworkManager \
+ --print-reply --reply-timeout=200 \
/org/freedesktop/NetworkManager \
org.freedesktop.NetworkManager.wake && \
echo Done. || echo Failed.
@@ -0,0 +1,142 @@
---
pm/defaults | 20 +++++++++++++++-
pm/module.d/uswsusp | 64 +++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 78 insertions(+), 6 deletions(-)
Index: pm-utils-1.3.0/pm/defaults
===================================================================
--- pm-utils-1.3.0.orig/pm/defaults 2009-06-14 03:56:08.000000000 +0200
+++ pm-utils-1.3.0/pm/defaults 2010-05-06 09:27:09.228673127 +0200
@@ -27,8 +27,26 @@
# tuxonice If your system has support for tuxonice, use this.
#
# The system defaults to "kernel" if this is commented out.
-# SLEEP_MODULE="kernel"
+SLEEP_MODULE="uswsusp"
+#######################################################################
+# the variables below here are specific to the SUSE package right now
+# and are used only if SLEEP_MODULE is uswsusp
+
+# what options should be passed to s2ram?
+# see http://en.opensuse.org/S2ram for more information
+# If this option is set, it overrides S2RAM_QUIRKS_SOURCE below
+S2RAM_OPTS=""
+
+# where should pm-utils get the s2ram quirks from?
+# s2ram - use the whitelist in s2ram, if the machine is known.
+# hal - ignored, exists only for comparibility purposes pm-utils 1.3.0+ has
+# HAL quirks built-in
+# everything else: try to be smart in figuring out the correct quirks.
+# if S2RAM_OPTS is set, it overrides S2RAM_QUIRKS_SOURCE!
+S2RAM_QUIRKS_SOURCE=""
+
+#######################################################################
# These variables will be handled specially when we load files in
# /etc/pm/config.d.
# Multiple declarations of these environment variables will result in
Index: pm-utils-1.3.0/pm/module.d/uswsusp
===================================================================
--- pm-utils-1.3.0.orig/pm/module.d/uswsusp 2009-12-11 05:36:38.000000000 +0100
+++ pm-utils-1.3.0/pm/module.d/uswsusp 2010-05-06 09:27:37.540671614 +0200
@@ -5,6 +5,7 @@
uswsusp_hooks()
{
disablehook 99video "disabled by uswsusp"
+ disablehook 90chvt "disabled by uswsusp"
}
# Since we disabled 99video, we need to take responsibility for proper
@@ -35,8 +36,52 @@
# if we were told to ignore quirks, do so.
# This is arguably not the best way to do things, but...
[ "$QUIRK_NONE" = "true" ] && OPTS=""
+ S2RAM_OPTS="$S2RAM_OPTS $OPTS"
+ echo "INFO: S2RAM_OPTS from HAL quirks: '$S2RAM_OPTS'."
}
+# this function tries to assemble the best s2ram options from various sources, falling back
+# to other methods...
+get_s2ram_opts()
+{
+ # if S2RAM_OPTS is set - then use it. The user told us so. Obey his wish.
+ if [ -n "$S2RAM_OPTS" ]; then
+ echo "INFO: using user-supplied options: S2RAM_OPTS='$S2RAM_OPTS' for suspending."
+ return
+ fi
+
+ # ... try to use s2ram as a source
+ if [ "$S2RAM_QUIRKS_SOURCE" = "s2ram" ]; then
+ if /usr/sbin/s2ram -n >/dev/null; then
+ echo "INFO: using s2ram built-in database, machine is supported."
+ return
+ else
+ echo "WARN: S2RAM_QUIRKS_SOURCE=s2ram, but machine is unknown, continuing..."
+ fi
+ fi
+
+ # ... if is not known or not set as a source, use the built-in database
+ echo "INFO: using built-in quirks database from HAL."
+ uswsusp_get_quirks
+ if [ -n "$S2RAM_OPTS" ]; then
+ S2RAM_OPTS="--force "$S2RAM_OPTS
+ fi
+
+ # ... in a case we still don't have any quirk, try s2ram for sure
+ if [ -z "$S2RAM_OPTS" ]; then
+ # ... machine could be in s2ram whitelist
+ if /usr/sbin/s2ram -n >/dev/null; then
+ echo "INFO: machine is in s2ram database, using it."
+ return;
+ else
+ # if we came here and S2RAM_OPTS is empty, suspend won't work :-(
+ echo "WARNING: smart uswsusp did not found any appropriate option, suspend probably don't work"
+ fi
+ fi
+
+}
+
+
# Since we disabled 99video, we also need to handle displaying
# help info for the quirks we handle.
uswsusp_help()
@@ -70,8 +115,8 @@
SUSPEND_MODULE="uswsusp"
do_suspend()
{
- uswsusp_get_quirks
- s2ram --force $OPTS
+ get_s2ram_opts
+ s2ram $S2RAM_OPTS
}
if [ "$METHOD" = "suspend" ]; then
add_before_hooks uswsusp_hooks
@@ -87,7 +132,12 @@
HIBERNATE_MODULE="uswsusp"
do_hibernate()
{
- s2disk
+ get_s2ram_opts
+ if [ -z "${S2DISK_CONF}" ]; then
+ s2disk
+ else
+ s2disk --config $S2DISK_CONF
+ fi
}
fi
@@ -98,8 +148,12 @@
SUSPEND_HYBRID_MODULE="uswsusp"
do_suspend_hybrid()
{
- uswsusp_get_quirks
- s2both --force $OPTS
+ get_s2ram_opts
+ if [ -z "${S2DISK_CONF}" ]; then
+ s2both --force $S2RAM_OPTS
+ else
+ s2both --config $S2DISK_CONF $S2RAM_OPTS
+ fi
}
if [ "$METHOD" = "suspend_hybrid" ]; then
add_before_hooks uswsusp_hooks
@@ -0,0 +1,27 @@
---
pm/defaults | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
Index: pm-utils-1.4.1/pm/defaults
===================================================================
--- pm-utils-1.4.1.orig/pm/defaults 2010-09-20 11:42:59.214155594 +0200
+++ pm-utils-1.4.1/pm/defaults 2010-09-20 13:35:52.974279436 +0200
@@ -30,7 +30,7 @@
SLEEP_MODULE="uswsusp"
#######################################################################
-# the variables below here are specific to the SUSE package right now
+# those variables below SUSE pm-utils specific right now
# and are used only if SLEEP_MODULE is uswsusp
# what options should be passed to s2ram?
@@ -46,6 +46,9 @@
# if S2RAM_OPTS is set, it overrides S2RAM_QUIRKS_SOURCE!
S2RAM_QUIRKS_SOURCE=""
+# the location of the autogenerated s2disk (s2both) config file
+S2DISK_CONF="/var/lib/s2disk.conf"
+
#######################################################################
# These variables will be handled specially when we load files in
# /etc/pm/config.d.
@@ -0,0 +1,2 @@
d /run/pm-utils/locks 0755 root root
d /run/pm-utils/storage 0755 root root