rc.suspend revision 211291
148734Siwasaki#!/bin/sh 248734Siwasaki# 366830Sobrien# Copyright (c) 1999 Mitsuru IWASAKI 466830Sobrien# All rights reserved. 566830Sobrien# 666830Sobrien# Redistribution and use in source and binary forms, with or without 766830Sobrien# modification, are permitted provided that the following conditions 866830Sobrien# are met: 966830Sobrien# 1. Redistributions of source code must retain the above copyright 1066830Sobrien# notice, this list of conditions and the following disclaimer. 1166830Sobrien# 2. Redistributions in binary form must reproduce the above copyright 1266830Sobrien# notice, this list of conditions and the following disclaimer in the 1366830Sobrien# documentation and/or other materials provided with the distribution. 1466830Sobrien# 1566830Sobrien# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1666830Sobrien# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1766830Sobrien# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1866830Sobrien# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1966830Sobrien# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2066830Sobrien# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2166830Sobrien# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2266830Sobrien# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2366830Sobrien# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2466830Sobrien# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2566830Sobrien# SUCH DAMAGE. 2666830Sobrien# 2750472Speter# $FreeBSD: head/etc/rc.suspend 211291 2010-08-13 21:23:13Z jkim $ 2848734Siwasaki# 2966830Sobrien 3048734Siwasaki# sample run command file for APM Suspend Event 3148734Siwasaki 32124001Snjlif [ $# -ne 2 ]; then 33170976Snjl echo "Usage: $0 [apm|acpi] [standby,suspend|1-4]" 34124001Snjl exit 1 35124001Snjlfi 36124001Snjl 37124001Snjlsubsystem=$1 38124001Snjlstate=$2 39124001Snjl 4051231Ssheldonhif [ -r /var/run/rc.suspend.pid ]; then 4148734Siwasaki exit 1 4248734Siwasakifi 4348734Siwasaki 44124766Snjlecho $$ 2> /dev/null > /var/run/rc.suspend.pid 4548734Siwasaki 46211288Sjkim_t=`/sbin/sysctl -n kern.timecounter.hardware 2> /dev/null` 47211288Sjkimcase ${_t#ACPI-} in 48211288Sjkimfast|safe) 49211288Sjkim /bin/rm -f /var/run/rc.suspend.tch 50211288Sjkim ;; 51211288Sjkim*) 52211289Sjkim { /sbin/sysctl -n kern.timecounter.hardware=ACPI-fast || \ 53211289Sjkim /sbin/sysctl -n kern.timecounter.hardware=ACPI-safe; } \ 54211288Sjkim > /dev/null 2>&1 && echo $_t > /var/run/rc.suspend.tch 55211288Sjkim ;; 56211288Sjkimesac 57211288Sjkim 5848734Siwasaki# If you have troubles on suspending with PC-CARD modem, try this. 5948734Siwasaki# See also contrib/pccardq.c (Only for PAO users). 60180620Smarcel# pccardq | awk -F '~' '$5 == "filled" && $4 ~ /uart/ \ 6148734Siwasaki# { printf("pccardc power %d 0", $1); }' | sh 6248734Siwasaki 63170976Snjl# If a device driver has problems suspending, try unloading it before 64170976Snjl# suspend and reloading it on resume. Example: 65124001Snjl# kldunload usb 66124001Snjl 67211291Sjkim/usr/bin/logger -t $subsystem suspend at `/bin/date +'%Y%m%d %H:%M:%S'` 68211291Sjkim/bin/sync && /bin/sync && /bin/sync 69211291Sjkim/bin/sleep 3 7048734Siwasaki 71211291Sjkim/bin/rm -f /var/run/rc.suspend.pid 72170976Snjlif [ $subsystem = "apm" ]; then 73170976Snjl /usr/sbin/zzz 74170976Snjlelse 75170976Snjl # Notify the kernel to continue the suspend process 76170976Snjl /usr/sbin/acpiconf -k 0 77170976Snjlfi 7848734Siwasaki 7948734Siwasakiexit 0 80