cleanvar revision 145043
11590Srgrimes#!/bin/sh
21590Srgrimes#
31590Srgrimes# $FreeBSD: head/etc/rc.d/cleanvar 145043 2005-04-14 03:56:06Z csjp $
41590Srgrimes#
51590Srgrimes
61590Srgrimes# PROVIDE: cleanvar
71590Srgrimes# REQUIRE: mountcritlocal var
81590Srgrimes
91590Srgrimespurgedir()
101590Srgrimes{
111590Srgrimes	local dir file
121590Srgrimes
131590Srgrimes	if [ $# -eq 0 ]; then
141590Srgrimes		purgedir .
151590Srgrimes	else
161590Srgrimes		for dir
171590Srgrimes		do
181590Srgrimes		(
191590Srgrimes			cd "$dir" && for file in .* *
201590Srgrimes			do
211590Srgrimes				# Skip over logging sockets
221590Srgrimes				[ -S "$file" -a "$file" = "log" ] && continue
231590Srgrimes				[ ."$file" = .. -o ."$file" = ... ] && continue
241590Srgrimes				if [ -d "$file" -a ! -L "$file" ]
251590Srgrimes				then
261590Srgrimes					purgedir "$file"
271590Srgrimes				else
281590Srgrimes					rm -f -- "$file"
291590Srgrimes				fi
301590Srgrimes			done
311590Srgrimes		)
321590Srgrimes		done
331590Srgrimes	fi
341590Srgrimes}
3574769Smikeh
3688150Smikeh# These files must be removed only the first time this script is run
3774769Smikeh# on boot.
3874769Smikeh#
3974769Smikeh[ "$1" != "reload" ] && rm -f /var/run/clean_var /var/spool/lock/clean_var
401590Srgrimes
411590Srgrimesif [ -d /var/run -a ! -f /var/run/clean_var ]; then
421590Srgrimes	purgedir /var/run
431590Srgrimes	# And an initial utmp file
441590Srgrimes	(cd /var/run && cp /dev/null utmp && chmod 644 utmp;)
451590Srgrimes	>/var/run/clean_var
461590Srgrimesfi
471590Srgrimesif [ -d /var/spool/lock -a ! -f /var/spool/lock/clean_var ]; then
481590Srgrimes	purgedir /var/spool/lock
491590Srgrimes	>/var/spool/lock/clean_var
501590Srgrimesfi
511590Srgrimesrm -rf /var/spool/uucp/.Temp/*
521590Srgrimes
531590Srgrimes