#!/bin/sh
#
# Copyright (c) 1999  Mitsuru IWASAKI
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD: src/etc/rc.suspend,v 1.3.2.3 2001/03/06 02:22:00 obrien Exp $
#

# sample run command file for APM Suspend Event

if [ -r /var/run/rc.suspend.pid ]; then
	exit 1
fi

echo $$ > /var/run/rc.suspend.pid

# If you have troubles on suspending with PC-CARD modem, try this.
# See also contrib/pccardq.c (Only for PAO users).
# pccardq | awk -F '~' '$5 == "filled" && $4 ~ /sio/ \
#	{ printf("pccardc power %d 0", $1); }' | sh

logger -t apmd suspend at `date +'%Y%m%d %H:%M:%S'`
sync && sync && sync
sleep 3

# unmount all NFS non-loopback file systems
mount -t nfs | grep -v localhost | awk '{print $3}' | xargs umount

DHPIDFILE=/var/run/dhclient.pid

if [ -e $DHPIDFILE ]; then
  DHPID=`cat $DHPIDFILE`
  kill $DHPID
  sleep 1
  if [ `ps -p $DHPID | tail -1 | wc -l` -eq 1 ]; then
    kill -9 $DHPID
  fi
  rm -f $DHPIDFILE
fi

# Switch from X to the console
vidcontrol -s 1 </dev/ttyv0

# Set to boot S2D partition
boot0cfg -onoupdate -s 1 ad0

rm -f /var/run/rc.suspend.pid
zzz

exit 0
