166830Sobrien#!/bin/sh
266830Sobrien#
366830Sobrien# Copyright (c) 1999  Matt Dillon
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
25100280Sgordon# SUCH DAMAGE.
2651231Ssheldonh#
2766830Sobrien# $FreeBSD$
2866830Sobrien#
2943803Sdillon
30127345Sbrooks# PROVIDE: tmp
31153028Sdougb# REQUIRE: mountcritremote
3275931Simp
33127345Sbrooks. /etc/rc.subr
3476409Sbsd
35127345Sbrooksname="tmp"
36174464Sdougbstop_cmd=':'
3776409Sbsd
38127345Sbrooksload_rc_config $name
3943803Sdillon
40221007Sdougbmount_tmpmfs ()
41221007Sdougb{
42221007Sdougb	if ! /bin/df /tmp | grep -q "^/dev/md[0-9]"; then
43221007Sdougb		mount_md ${tmpsize} /tmp "${tmpmfs_flags}"
44221007Sdougb		chmod 01777 /tmp
45221007Sdougb	fi
46221007Sdougb}
47221007Sdougb
48127345Sbrooks# If we do not have a writable /tmp, create a memory
49127345Sbrooks# filesystem for /tmp.  If /tmp is a symlink (e.g. to /var/tmp,
50127345Sbrooks# then it should already be writable).
5191074Sobrien#
52127345Sbrookscase "${tmpmfs}" in
53221007Sdougb[Aa][Uu][Tt][Oo])
54205121Sjh	if _tmpdir=$(mktemp -d -q /tmp/.diskless.XXXXXX); then
55205121Sjh		rmdir ${_tmpdir}
56127345Sbrooks	else
57127345Sbrooks		if [ -h /tmp ]; then
58127345Sbrooks			echo "*** /tmp is a symlink to a non-writable area!"
59127345Sbrooks			echo "dropping into shell, ^D to continue anyway."
60127345Sbrooks			/bin/sh
61127345Sbrooks		else
62221007Sdougb			mount_tmpmfs
63127345Sbrooks		fi
64127345Sbrooks	fi
65124149Sbrooks	;;
66221007Sdougb*)
67221007Sdougb	if checkyesno tmpmfs; then
68221007Sdougb		mount_tmpmfs
69221007Sdougb	fi
70221007Sdougb	;;
71124149Sbrooksesac
72