10696600cSBjoern A. Zeeb#!/bin/sh 20696600cSBjoern A. Zeeb# 30696600cSBjoern A. Zeeb# $FreeBSD$ 40696600cSBjoern A. Zeeb# 50696600cSBjoern A. Zeeb 60696600cSBjoern A. Zeeb# PROVIDE: cleartmp 70696600cSBjoern A. Zeeb# REQUIRE: mountcritremote tmp 80696600cSBjoern A. Zeeb# BEFORE: DAEMON 90696600cSBjoern A. Zeeb 100696600cSBjoern A. Zeeb. /etc/rc.subr 110696600cSBjoern A. Zeeb 120696600cSBjoern A. Zeebname="cleartmp" 130696600cSBjoern A. Zeebdesc="Purge /tmp directory" 140696600cSBjoern A. Zeeb# Disguise rcvar for the start method to run irrespective of its setting. 150696600cSBjoern A. Zeebrcvar1="clear_tmp_enable" 160696600cSBjoern A. Zeebstart_cmd="${name}_start" 170696600cSBjoern A. Zeebstop_cmd=":" 180696600cSBjoern A. Zeeb 190696600cSBjoern A. Zeebcleartmp_start() 200696600cSBjoern A. Zeeb{ 210696600cSBjoern A. Zeeb # Make /tmp location variable for easier debugging. 220696600cSBjoern A. Zeeb local tmp="/tmp" 230696600cSBjoern A. Zeeb 240696600cSBjoern A. Zeeb # X related directories to create in /tmp. 250696600cSBjoern A. Zeeb local x11_socket_dirs="${tmp}/.X11-unix ${tmp}/.XIM-unix \ 260696600cSBjoern A. Zeeb ${tmp}/.ICE-unix ${tmp}/.font-unix" 270696600cSBjoern A. Zeeb 280696600cSBjoern A. Zeeb if checkyesno ${rcvar1}; then 29*325ebf37SJose Luis Duran startmsg "Clearing ${tmp}." 300696600cSBjoern A. Zeeb 310696600cSBjoern A. Zeeb # This is not needed for mfs, but doesn't hurt anything. 320696600cSBjoern A. Zeeb # Things to note: 330696600cSBjoern A. Zeeb # + The dot in ${tmp}/. is important. 340696600cSBjoern A. Zeeb # + Put -prune before -exec so find never descends 350696600cSBjoern A. Zeeb # into a directory that was already passed to rm -rf. 360696600cSBjoern A. Zeeb # + "--" in rm arguments isn't strictly necessary, but 370696600cSBjoern A. Zeeb # it can prevent foot-shooting in future. 380696600cSBjoern A. Zeeb # + /tmp/lost+found is preserved, but its contents are removed. 390696600cSBjoern A. Zeeb # + lost+found and quota.* in subdirectories are removed. 400696600cSBjoern A. Zeeb # + .sujournal and .snap are preserved. 410696600cSBjoern A. Zeeb find -x ${tmp}/. ! -name . \ 420696600cSBjoern A. Zeeb ! \( -name .sujournal -type f -user root \) \ 430696600cSBjoern A. Zeeb ! \( -name .snap -type d -user root \) \ 440696600cSBjoern A. Zeeb ! \( -name lost+found -type d -user root \) \ 450696600cSBjoern A. Zeeb ! \( \( -name quota.user -or -name quota.group \) \ 460696600cSBjoern A. Zeeb -type f -user root \) \ 470696600cSBjoern A. Zeeb -prune -exec rm -rf -- {} + 480696600cSBjoern A. Zeeb elif checkyesno clear_tmp_X; then 490696600cSBjoern A. Zeeb # Remove X lock files, since they will prevent you from 500696600cSBjoern A. Zeeb # restarting X. Remove other X related directories. 51*325ebf37SJose Luis Duran startmsg "Clearing ${tmp} (X related)." 520696600cSBjoern A. Zeeb rm -rf ${tmp}/.X[0-9]-lock ${x11_socket_dirs} 530696600cSBjoern A. Zeeb fi 540696600cSBjoern A. Zeeb if checkyesno clear_tmp_X; then 550696600cSBjoern A. Zeeb # Create X related directories with proper permissions. 560696600cSBjoern A. Zeeb mkdir -m 1777 ${x11_socket_dirs} 570696600cSBjoern A. Zeeb fi 580696600cSBjoern A. Zeeb} 590696600cSBjoern A. Zeeb 600696600cSBjoern A. Zeebload_rc_config $name 610696600cSBjoern A. Zeebrun_rc_command "$1" 62