198184Sgordon#!/bin/sh 298184Sgordon# 398184Sgordon# $FreeBSD: releng/10.2/etc/rc.d/cleanvar 240336 2012-09-11 05:04:59Z obrien $ 498184Sgordon# 598184Sgordon 698184Sgordon# PROVIDE: cleanvar 7240336Sobrien# REQUIRE: var 898184Sgordon 9153537Sdougb. /etc/rc.subr 10153537Sdougb 11153537Sdougbname="cleanvar" 12230099Sdougbrcvar="cleanvar_enable" 13153537Sdougb 14153537Sdougbstart_precmd="${name}_prestart" 15153537Sdougbstart_cmd="${name}_start" 16153537Sdougbstop_cmd=":" 17153537Sdougb 18153537Sdougbextra_commands="reload" 19153537Sdougbreload_cmd="${name}_start" 20153537Sdougb 2198184Sgordonpurgedir() 2298184Sgordon{ 23104980Sschweikh local dir file 2498184Sgordon 2598184Sgordon if [ $# -eq 0 ]; then 2698184Sgordon purgedir . 2798184Sgordon else 2898184Sgordon for dir 2998184Sgordon do 3098184Sgordon ( 3198184Sgordon cd "$dir" && for file in .* * 3298184Sgordon do 33148849Spjd # Skip over logging sockets 34148849Spjd [ -S "$file" -a "$file" = "log" ] && continue 35148849Spjd [ -S "$file" -a "$file" = "logpriv" ] && continue 3698184Sgordon [ ."$file" = .. -o ."$file" = ... ] && continue 3798184Sgordon if [ -d "$file" -a ! -L "$file" ] 3898184Sgordon then 3998184Sgordon purgedir "$file" 4098184Sgordon else 4198184Sgordon rm -f -- "$file" 4298184Sgordon fi 4398184Sgordon done 4498184Sgordon ) 4598184Sgordon done 4698184Sgordon fi 4798184Sgordon} 4898184Sgordon 49153537Sdougbcleanvar_prestart() 50153537Sdougb{ 51153537Sdougb # These files must be removed only the first time this script is run 52153537Sdougb # on boot. 53153537Sdougb # 54153537Sdougb rm -f /var/run/clean_var /var/spool/lock/clean_var 55153537Sdougb} 56110907Smtm 57238416Skevlocleanvar_start() 58153537Sdougb{ 59153537Sdougb if [ -d /var/run -a ! -f /var/run/clean_var ]; then 60153537Sdougb purgedir /var/run 61153537Sdougb >/var/run/clean_var 62153537Sdougb fi 63153537Sdougb if [ -d /var/spool/lock -a ! -f /var/spool/lock/clean_var ]; then 64153537Sdougb purgedir /var/spool/lock 65153537Sdougb >/var/spool/lock/clean_var 66153537Sdougb fi 67153537Sdougb rm -rf /var/spool/uucp/.Temp/* 68153537Sdougb} 6998184Sgordon 70153537Sdougbload_rc_config $name 71153537Sdougbrun_rc_command "$1" 72