diff --git a/plist b/plist index 3dbebcc63..336598a5c 100644 --- a/plist +++ b/plist @@ -134,6 +134,7 @@ /usr/local/etc/rc.subr.d/livemode /usr/local/etc/rc.subr.d/recover /usr/local/etc/rc.subr.d/swapon +/usr/local/etc/rc.subr.d/tmp /usr/local/etc/rc.subr.d/var /usr/local/etc/rc.syshook /usr/local/etc/rc.syshook.d/05-beep.stop diff --git a/src/etc/rc b/src/etc/rc index 215428d04..554402a7a 100755 --- a/src/etc/rc +++ b/src/etc/rc @@ -134,14 +134,8 @@ fi # write /var/run/dmesg.boot /etc/rc.d/dmesg onestart -USE_MFS_TMP=$(/usr/bin/grep -c 'use_mfs_tmp[^_]' /conf/config.xml) - -if [ ${USE_MFS_TMP} -ne 0 ]; then - mount -t tmpfs -o mode=01777 tmpfs /tmp -else - rm -rf /tmp/* - chmod 1777 /tmp -fi +# all sorts of maintenance tasks for /tmp +/usr/local/etc/rc.subr.d/tmp # set up and recover a crash dump before activating swap /usr/local/etc/rc.subr.d/crashdump diff --git a/src/etc/rc.subr.d/tmp b/src/etc/rc.subr.d/tmp new file mode 100755 index 000000000..19a975238 --- /dev/null +++ b/src/etc/rc.subr.d/tmp @@ -0,0 +1,46 @@ +#!/bin/sh + +# Copyright (c) 2014-2018 Franco Fichtner +# Copyright (c) 2004-2010 Scott Ullrich +# Copyright (c) 2003-2004 Manuel Kasper +# 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. + +USE_MFS_TMP=$(/usr/bin/grep -c 'use_mfs_tmp[^_]' /conf/config.xml) + +# see if / is writable (aka. non-LiveCD boot) +if _tmpdir=$(mktemp -d -q /.diskless.XXXXXX); then + # only remove the directory + rmdir ${_tmpdir} +else + USE_MFS_TMP=0 +fi + +if [ ${USE_MFS_TMP} -ne 0 ]; then + mount -t tmpfs -o mode=01777 tmpfs /tmp +else + rm -rf /tmp/* + chmod 1777 /tmp +fi