1#!/bin/sh 2# 3# $FreeBSD: releng/10.2/etc/rc.d/cleanvar 240336 2012-09-11 05:04:59Z obrien $ 4# 5 6# PROVIDE: cleanvar 7# REQUIRE: var 8 9. /etc/rc.subr 10 11name="cleanvar" 12rcvar="cleanvar_enable" 13 14start_precmd="${name}_prestart" 15start_cmd="${name}_start" 16stop_cmd=":" 17 18extra_commands="reload" 19reload_cmd="${name}_start" 20 21purgedir() 22{ 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 >/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