Home | History | Annotate | Line # | Download | only in rc.d
cleartmp revision 1.10
      1   1.1    lukem #!/bin/sh
      2   1.1    lukem #
      3  1.10      mjf # $NetBSD: cleartmp,v 1.10 2007/12/04 22:09:01 mjf 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.1    lukem 	#
     21   1.1    lukem 	#	Prune quickly with one rm, then use find to clean up
     22   1.7     elad 	#	/tmp/[lq]* (this is not needed with mfs /tmp, but
     23   1.1    lukem 	#	doesn't hurt anything).
     24   1.1    lukem 	#
     25   1.9  xtraeme 	if checkyesno per_user_tmp && [ -d ${per_user_tmp_dir} ]; then
     26   1.8     elad 		tmp_dir=${per_user_tmp_dir}
     27   1.8     elad 	else
     28   1.8     elad 		tmp_dir="/tmp"
     29   1.9  xtraeme 		# Check if /tmp was created by the perusertmp rc.d
     30   1.9  xtraeme 		# script and recreate it if necessary.
     31  1.10      mjf 		if [ "$(/usr/bin/readlink /tmp)" = ${per_user_tmp_dir}/@ruid ]; then
     32   1.9  xtraeme 			/bin/rm -rf ${tmp_dir}
     33   1.9  xtraeme 			/bin/mkdir ${tmp_dir}
     34   1.9  xtraeme 			/usr/sbin/chown root:wheel ${tmp_dir}
     35   1.9  xtraeme 			/bin/chmod 1777 ${tmp_dir}
     36   1.9  xtraeme 		fi
     37   1.8     elad 	fi
     38   1.8     elad 
     39   1.8     elad 	(cd ${tmp_dir} && rm -rf [a-km-pr-zA-Z]* &&
     40   1.1    lukem 	    find -x . ! -name . ! -name lost+found ! -name quota.user \
     41   1.7     elad 		! -name quota.group -exec rm -rf -- {} \; -type d -prune)
     42   1.1    lukem }
     43   1.1    lukem 
     44   1.2    lukem load_rc_config $name
     45   1.1    lukem run_rc_command "$1"
     46