cleanvar revision 231534
178344Sobrien#!/bin/sh
278344Sobrien#
378344Sobrien# $FreeBSD: head/etc/rc.d/cleanvar 231534 2012-02-11 20:47:16Z ed $
478344Sobrien#
578344Sobrien
678344Sobrien# PROVIDE: cleanvar
778344Sobrien# REQUIRE: FILESYSTEMS var
878344Sobrien
978344Sobrien. /etc/rc.subr
1078344Sobrien
1178344Sobrienname="cleanvar"
1278344Sobrienrcvar="cleanvar_enable"
1378344Sobrien
1478344Sobrienstart_precmd="${name}_prestart"
1578344Sobrienstart_cmd="${name}_start"
1678344Sobrienstop_cmd=":"
1778344Sobrien
1878344Sobrienextra_commands="reload"
1978344Sobrienreload_cmd="${name}_start"
2078344Sobrien
2178344Sobrienpurgedir()
2278344Sobrien{
2378344Sobrien	local dir file
2478344Sobrien
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		>/var/run/clean_var
62	fi
63	if [ -d /var/spool/lock -a ! -f /var/spool/lock/clean_var ]; then
64		purgedir /var/spool/lock
65		>/var/spool/lock/clean_var
66	fi
67	rm -rf /var/spool/uucp/.Temp/*
68}
69
70load_rc_config $name
71run_rc_command "$1"
72