rc.suspend revision 180620
174462Salfred#!/bin/sh
274462Salfred#
3261046Smav# Copyright (c) 1999  Mitsuru IWASAKI
4261046Smav# All rights reserved.
5261046Smav#
61901Swollman# Redistribution and use in source and binary forms, with or without
7261046Smav# modification, are permitted provided that the following conditions
8261046Smav# are met:
9261046Smav# 1. Redistributions of source code must retain the above copyright
10261046Smav#    notice, this list of conditions and the following disclaimer.
11261046Smav# 2. Redistributions in binary form must reproduce the above copyright
12261046Smav#    notice, this list of conditions and the following disclaimer in the
13261046Smav#    documentation and/or other materials provided with the distribution.
14261046Smav#
15261046Smav# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16261046Smav# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17261046Smav# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18261046Smav# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19261046Smav# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20261046Smav# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21261046Smav# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22261046Smav# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23261046Smav# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24261046Smav# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25261046Smav# SUCH DAMAGE.
26261046Smav#
27261046Smav# $FreeBSD: head/etc/rc.suspend 180620 2008-07-19 20:12:33Z marcel $
28261046Smav#
291901Swollman
301901Swollman# sample run command file for APM Suspend Event
311901Swollman
3274462Salfredif [ $# -ne 2 ]; then
331901Swollman	echo "Usage: $0 [apm|acpi] [standby,suspend|1-4]"
3492990Sobrien	exit 1
3592990Sobrienfi
361901Swollman
371901Swollmansubsystem=$1
381901Swollmanstate=$2
391901Swollman
401901Swollmanif [ -r /var/run/rc.suspend.pid ]; then
41158115Sume	exit 1
4274462Salfredfi
43158115Sume
4474462Salfredecho $$ 2> /dev/null > /var/run/rc.suspend.pid
4574462Salfred
46158115Sume# If you have troubles on suspending with PC-CARD modem, try this.
47158115Sume# See also contrib/pccardq.c (Only for PAO users).
48158115Sume# pccardq | awk -F '~' '$5 == "filled" && $4 ~ /uart/ \
491901Swollman#	{ printf("pccardc power %d 0", $1); }' | sh
50158115Sume
51158115Sume# If a device driver has problems suspending, try unloading it before
5211666Sphk# suspend and reloading it on resume.  Example:
531901Swollman# kldunload usb
541901Swollman
551901Swollmanlogger -t $subsystem suspend at `date +'%Y%m%d %H:%M:%S'`
561901Swollmansync && sync && sync
571901Swollmansleep 3
58158115Sume
59158115Sumerm -f /var/run/rc.suspend.pid
60158115Sumeif [ $subsystem = "apm" ]; then
6174462Salfred	/usr/sbin/zzz
62111618Snectarelse
63158115Sume	# Notify the kernel to continue the suspend process
64158115Sume	/usr/sbin/acpiconf -k 0
65158115Sumefi
66158115Sume
671901Swollmanexit 0
68158115Sume