freebsd-dev/etc/rc.d/cleartmp
Doug Barton 888d94cf9b MFC r197947:
In regards to the "Starting foo:" type messages at boot time, create
and employ a more generic solution, and use it in the individual rc.d
scripts that also have an $rc_quiet test:

1. Add check_startmsgs() to rc.subr.
2. In the rc.d scripts that use rc_quiet (and rc.subr) substitute
variations of [ -z "$rc_quiet" ] with check_startmsgs
3. In savecore add a trailing '.' to the end of the message to make it
more consistent with other scripts.
4. In newsyslog remove a : before the terminal '.' since we do not
expect there to be anything printed out in between to make it more
consistent.
5. In the following scripts change "quotes" to 'quotes' where no
variables exist in the message: savecore pf newsyslog
6. [Does not apply in RELENG_8]
7. In the following scripts separate the "Starting foo:" from the
terminal '.' to make them more consistent: moused hostname pf
8. In nfsclient move the message to its own line to avoid a style bug
9. In pf rc_quiet does not apply to the _stop method, so remove the
test there.
10. In motd add 'quotes' around the terminal '.' for consistency

Approved by:	re (kib)
2009-10-16 00:17:09 +00:00

58 lines
1.6 KiB
Bash
Executable File

#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: cleartmp
# REQUIRE: mountcritremote tmp
# BEFORE: DAEMON
. /etc/rc.subr
name="cleartmp"
# Disguise rcvar for the start method to run irrespective of its setting.
rcvar1=`set_rcvar clear_tmp`
start_cmd="${name}_start"
stop_cmd=":"
cleartmp_start()
{
# Make /tmp location variable for easier debugging.
local tmp="/tmp"
# X related directories to create in /tmp.
local x11_socket_dirs="${tmp}/.X11-unix ${tmp}/.XIM-unix \
${tmp}/.ICE-unix ${tmp}/.font-unix"
if checkyesno ${rcvar1}; then
check_startmsgs && echo "Clearing ${tmp}."
# This is not needed for mfs, but doesn't hurt anything.
# Things to note:
# + The dot in ${tmp}/. is important.
# + Put -prune before -exec so find never descends
# into a directory that was already passed to rm -rf.
# + "--" in rm arguments isn't strictly necessary, but
# it can prevent foot-shooting in future.
# + /tmp/lost+found is preserved, but its contents are removed.
# + lost+found and quota.* in subdirectories are removed.
find -x ${tmp}/. ! -name . \
! \( -name lost+found -type d -user root \) \
! \( \( -name quota.user -or -name quota.group \) \
-type f -user root \) \
-prune -exec rm -rf -- {} +
elif checkyesno clear_tmp_X; then
# Remove X lock files, since they will prevent you from
# restarting X. Remove other X related directories.
check_startmsgs && echo "Clearing ${tmp} (X related)."
rm -rf ${tmp}/.X[0-9]-lock ${x11_socket_dirs}
fi
if checkyesno clear_tmp_X; then
# Create X related directories with proper permissions.
mkdir -m 1777 ${x11_socket_dirs}
fi
}
load_rc_config $name
run_rc_command "$1"