cleanvar revision 208060
185957Sphk#!/bin/sh
285957Sphk#
385957Sphk# $FreeBSD: head/etc/rc.d/cleanvar 208060 2010-05-14 04:53:57Z dougb $
4319182Sngie#
585957Sphk
6122023Simp# PROVIDE: cleanvar
7122894Simp# REQUIRE: FILESYSTEMS var
885957Sphk
985957Sphk. /etc/rc.subr
1089244Smsmith
1189244Smsmithname="cleanvar"
1289244Smsmithrcvar=`set_rcvar`
1389244Smsmith
1489244Smsmithstart_precmd="${name}_prestart"
1589244Smsmithstart_cmd="${name}_start"
1689244Smsmithstop_cmd=":"
1789244Smsmith
1889244Smsmithextra_commands="reload"
1989244Smsmithreload_cmd="${name}_start"
2089244Smsmith
2189244Smsmithpurgedir()
2285957Sphk{
23	local dir file
24
25	if [ $# -eq 0 ]; then
26		purgedir .
27	else
28		for dir
29		do
30		(
31			cd "$dir" && for file in .* *
32			do
33				# Skip over logging sockets
34				[ -S "$file" -a "$file" = "log" ] && continue
35				[ -S "$file" -a "$file" = "logpriv" ] && continue
36				[ ."$file" = .. -o ."$file" = ... ] && continue
37				if [ -d "$file" -a ! -L "$file" ]
38				then
39					purgedir "$file"
40				else
41					rm -f -- "$file"
42				fi
43			done
44		)
45		done
46	fi
47}
48
49cleanvar_prestart()
50{
51	# These files must be removed only the first time this script is run
52	# on boot.
53	#
54	rm -f /var/run/clean_var /var/spool/lock/clean_var
55}
56
57cleanvar_start ()
58{
59	if [ -d /var/run -a ! -f /var/run/clean_var ]; then
60		purgedir /var/run
61		# And an initial utmpx active session file
62		(cd /var/run && cp /dev/null utx.active && chmod 644 utx.active)
63		>/var/run/clean_var
64	fi
65	if [ -d /var/spool/lock -a ! -f /var/spool/lock/clean_var ]; then
66		purgedir /var/spool/lock
67		>/var/spool/lock/clean_var
68	fi
69	rm -rf /var/spool/uucp/.Temp/*
70}
71
72load_rc_config $name
73run_rc_command "$1"
74