Home | History | Annotate | Line # | Download | only in rc.d
cleartmp revision 1.11
      1   1.1    lukem #!/bin/sh
      2   1.1    lukem #
      3  1.11      apb # $NetBSD: cleartmp,v 1.11 2012/10/24 21:23:55 apb Exp $
      4   1.1    lukem #
      5   1.1    lukem 
      6   1.1    lukem # PROVIDE: cleartmp
      7   1.1    lukem # REQUIRE: mountall
      8   1.4  thorpej # BEFORE:  DAEMON
      9   1.1    lukem 
     10   1.5  mycroft $_rc_subr_loaded . /etc/rc.subr
     11   1.1    lukem 
     12   1.1    lukem name="cleartmp"
     13   1.3    lukem rcvar="clear_tmp"
     14   1.1    lukem start_cmd="cleartmp_start"
     15   1.1    lukem stop_cmd=":"
     16   1.1    lukem 
     17   1.1    lukem cleartmp_start()
     18   1.1    lukem {
     19   1.8     elad 	echo "Clearing temporary files."
     20   1.9  xtraeme 	if checkyesno per_user_tmp && [ -d ${per_user_tmp_dir} ]; then
     21   1.8     elad 		tmp_dir=${per_user_tmp_dir}
     22   1.8     elad 	else
     23   1.8     elad 		tmp_dir="/tmp"
     24   1.9  xtraeme 		# Check if /tmp was created by the perusertmp rc.d
     25   1.9  xtraeme 		# script and recreate it if necessary.
     26  1.10      mjf 		if [ "$(/usr/bin/readlink /tmp)" = ${per_user_tmp_dir}/@ruid ]; then
     27   1.9  xtraeme 			/bin/rm -rf ${tmp_dir}
     28   1.9  xtraeme 			/bin/mkdir ${tmp_dir}
     29   1.9  xtraeme 			/usr/sbin/chown root:wheel ${tmp_dir}
     30   1.9  xtraeme 			/bin/chmod 1777 ${tmp_dir}
     31   1.9  xtraeme 		fi
     32   1.8     elad 	fi
     33   1.8     elad 
     34  1.11      apb 	#
     35  1.11      apb 	#	Delete almost everything, except lost+found, quota.user,
     36  1.11      apb 	#	and quota.group in the top level.  (This is not needed
     37  1.11      apb 	#	with mfs or tmpfs /tmp, but doesn't hurt anything).
     38  1.11      apb 	#
     39  1.11      apb 	#	The find command, with "-exec ... +" instead of "-exec
     40  1.11      apb 	#	... \;", will pass many file or dir names to each
     41  1.11      apb 	#	invocation of "rm -rf".  We avoid using any glob
     42  1.11      apb 	#	patterns because of the risk of "Arg list too long"
     43  1.11      apb 	#	errors when there are very many files.
     44  1.11      apb 	#
     45  1.11      apb 	(cd ${tmp_dir} &&
     46   1.1    lukem 	    find -x . ! -name . ! -name lost+found ! -name quota.user \
     47  1.11      apb 		! -name quota.group -exec rm -rf -- {} \+ -type d -prune)
     48   1.1    lukem }
     49   1.1    lukem 
     50   1.2    lukem load_rc_config $name
     51   1.1    lukem run_rc_command "$1"
     52