2001-06-16 07:16:14 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2002-06-13 22:14:37 +00:00
|
|
|
# $FreeBSD$
|
2001-06-16 07:16:14 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: cleartmp
|
2004-03-23 23:22:35 +00:00
|
|
|
# REQUIRE: mountcritremote tmp
|
2002-06-13 22:14:37 +00:00
|
|
|
# BEFORE: DAEMON
|
2001-06-16 07:16:14 +00:00
|
|
|
|
|
|
|
. /etc/rc.subr
|
|
|
|
|
|
|
|
name="cleartmp"
|
2016-04-23 16:10:54 +00:00
|
|
|
desc="Purge /tmp directory"
|
2006-10-16 13:01:45 +00:00
|
|
|
# Disguise rcvar for the start method to run irrespective of its setting.
|
2012-01-14 02:18:41 +00:00
|
|
|
rcvar1="clear_tmp_enable"
|
2005-12-19 10:57:00 +00:00
|
|
|
start_cmd="${name}_start"
|
2006-10-16 13:01:45 +00:00
|
|
|
stop_cmd=":"
|
2001-06-16 07:16:14 +00:00
|
|
|
|
2005-12-20 20:36:48 +00:00
|
|
|
cleartmp_start()
|
|
|
|
{
|
2006-10-16 13:01:45 +00:00
|
|
|
# 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
|
2009-10-10 22:17:03 +00:00
|
|
|
check_startmsgs && echo "Clearing ${tmp}."
|
2006-10-16 13:01:45 +00:00
|
|
|
|
|
|
|
# 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.
|
2010-09-05 05:44:40 +00:00
|
|
|
# + .sujournal and .snap are preserved.
|
2006-10-16 13:01:45 +00:00
|
|
|
find -x ${tmp}/. ! -name . \
|
2010-09-05 05:44:40 +00:00
|
|
|
! \( -name .sujournal -type f -user root \) \
|
|
|
|
! \( -name .snap -type d -user root \) \
|
2006-10-16 13:01:45 +00:00
|
|
|
! \( -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.
|
2009-10-10 22:17:03 +00:00
|
|
|
check_startmsgs && echo "Clearing ${tmp} (X related)."
|
2006-10-16 13:01:45 +00:00
|
|
|
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
|
2005-12-20 20:36:48 +00:00
|
|
|
}
|
|
|
|
|
2001-06-16 07:16:14 +00:00
|
|
|
load_rc_config $name
|
|
|
|
run_rc_command "$1"
|