cleartmp revision 153764
1#!/bin/sh
2#
3# $FreeBSD: head/etc/rc.d/cleartmp 153764 2005-12-27 23:08:58Z dougb $
4#
5
6# PROVIDE: cleartmp
7# REQUIRE: mountcritremote tmp
8# BEFORE: DAEMON
9
10. /etc/rc.subr
11
12name="cleartmp"
13rcvar=`set_rcvar clear_tmp`
14
15start_cmd="${name}_start"
16
17cleartmp_prestart()
18{
19	checkyesno clear_tmp_X || return
20
21	local x11_socket_dirs="/tmp/.X11-unix /tmp/.ICE-unix /tmp/.font-unix /tmp/.XIM-unix"
22
23	# Remove X lock files, since they will prevent you from restarting X.
24	rm -f /tmp/.X[0-9]-lock
25
26	# Create socket directories with correct permissions to avoid
27	# security problem.
28	#
29	rm -fr ${x11_socket_dirs}
30	mkdir -m 1777 ${x11_socket_dirs}
31}
32
33cleartmp_start()
34{
35	echo "Clearing /tmp."
36	#
37	#	Prune quickly with one rm, then use find to clean up
38	#	/tmp/[lq]* (this is not needed with mfs /tmp, but
39	#	doesn't hurt anything).
40	#
41	(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
42	    find -x . ! -name . ! -name lost+found ! -name quota.user \
43		! -name quota.group -exec rm -rf -- {} \; -type d -prune)
44}
45
46load_rc_config $name
47
48# The clear_tmp_X variable should be tested even if clear_tmp_enable is NO
49case "$1" in
50*start)	cleartmp_prestart ;;
51esac
52
53run_rc_command "$1"
54