xref: /freebsd/libexec/rc/rc.suspend (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
10696600cSBjoern A. Zeeb#!/bin/sh
20696600cSBjoern A. Zeeb#
30696600cSBjoern A. Zeeb# Copyright (c) 1999  Mitsuru IWASAKI
40696600cSBjoern A. Zeeb# All rights reserved.
50696600cSBjoern A. Zeeb#
60696600cSBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without
70696600cSBjoern A. Zeeb# modification, are permitted provided that the following conditions
80696600cSBjoern A. Zeeb# are met:
90696600cSBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright
100696600cSBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer.
110696600cSBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright
120696600cSBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer in the
130696600cSBjoern A. Zeeb#    documentation and/or other materials provided with the distribution.
140696600cSBjoern A. Zeeb#
150696600cSBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
160696600cSBjoern A. Zeeb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
170696600cSBjoern A. Zeeb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
180696600cSBjoern A. Zeeb# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
190696600cSBjoern A. Zeeb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
200696600cSBjoern A. Zeeb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
210696600cSBjoern A. Zeeb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
220696600cSBjoern A. Zeeb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
230696600cSBjoern A. Zeeb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
240696600cSBjoern A. Zeeb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
250696600cSBjoern A. Zeeb# SUCH DAMAGE.
260696600cSBjoern A. Zeeb#
270696600cSBjoern A. Zeeb#
280696600cSBjoern A. Zeeb
290696600cSBjoern A. Zeeb# sample run command file for APM Suspend Event
300696600cSBjoern A. Zeeb
310696600cSBjoern A. Zeebif [ $# -ne 2 ]; then
320696600cSBjoern A. Zeeb	echo "Usage: $0 [apm|acpi] [standby,suspend|1-4]"
330696600cSBjoern A. Zeeb	exit 1
340696600cSBjoern A. Zeebfi
350696600cSBjoern A. Zeeb
360696600cSBjoern A. Zeebsubsystem=$1
370696600cSBjoern A. Zeebstate=$2
380696600cSBjoern A. Zeeb
390696600cSBjoern A. Zeebif [ -r /var/run/rc.suspend.pid ]; then
400696600cSBjoern A. Zeeb	exit 1
410696600cSBjoern A. Zeebfi
420696600cSBjoern A. Zeeb
430696600cSBjoern A. Zeebecho $$ 2> /dev/null > /var/run/rc.suspend.pid
440696600cSBjoern A. Zeeb
450696600cSBjoern A. Zeeb# If a device driver has problems suspending, try unloading it before
460696600cSBjoern A. Zeeb# suspend and reloading it on resume.  Example:
470696600cSBjoern A. Zeeb# kldunload usb
480696600cSBjoern A. Zeeb
49*2cf8ef59SJohannes Totz. /etc/rc.subr
50*2cf8ef59SJohannes Totz
51*2cf8ef59SJohannes Totzload_rc_config
52*2cf8ef59SJohannes Totz
53*2cf8ef59SJohannes Totzrcorder_opts="-k suspend"
54*2cf8ef59SJohannes Totz
55*2cf8ef59SJohannes Totzcase ${local_startup} in
56*2cf8ef59SJohannes Totz[Nn][Oo] | '') ;;
57*2cf8ef59SJohannes Totz*)     find_local_scripts_new ;;
58*2cf8ef59SJohannes Totzesac
59*2cf8ef59SJohannes Totz
60*2cf8ef59SJohannes Totzfiles=`rcorder ${rcorder_opts} /etc/rc.d/* ${local_rc} 2>/dev/null`
61*2cf8ef59SJohannes Totz
62*2cf8ef59SJohannes Totzfor _rc_elem in $files; do
63*2cf8ef59SJohannes Totz	debug "run_rc_script $_rc_elem suspend"
64*2cf8ef59SJohannes Totz	run_rc_script $_rc_elem suspend
65*2cf8ef59SJohannes Totzdone
66*2cf8ef59SJohannes Totz
670696600cSBjoern A. Zeeb/usr/bin/logger -t $subsystem suspend at `/bin/date +'%Y%m%d %H:%M:%S'`
680696600cSBjoern A. Zeeb/bin/sync && /bin/sync && /bin/sync
690696600cSBjoern A. Zeeb/bin/sleep 3
700696600cSBjoern A. Zeeb
710696600cSBjoern A. Zeeb/bin/rm -f /var/run/rc.suspend.pid
720696600cSBjoern A. Zeebif [ $subsystem = "apm" ]; then
730696600cSBjoern A. Zeeb	/usr/sbin/zzz
740696600cSBjoern A. Zeebelse
750696600cSBjoern A. Zeeb	# Notify the kernel to continue the suspend process
760696600cSBjoern A. Zeeb	/usr/sbin/acpiconf -k 0
770696600cSBjoern A. Zeebfi
780696600cSBjoern A. Zeeb
790696600cSBjoern A. Zeebexit 0
80