Home | History | Annotate | Line # | Download | only in rc.d
      1   1.1     lukem #!/bin/sh
      2   1.1     lukem #
      3  1.13    martin # $NetBSD: cleartmp,v 1.13 2018/09/30 10:38:05 martin 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.12  dholland 			/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.13    martin 
     49  1.13    martin 	# if requested, create symlink for /var/shm
     50  1.13    martin 	if [ -n "${var_shm_symlink}" ]; then
     51  1.13    martin 		/bin/rm -rf /var/shm
     52  1.13    martin 		/bin/mkdir -m 1777 "${var_shm_symlink}"
     53  1.13    martin 		/bin/ln -s "${var_shm_symlink}" /var/shm
     54  1.13    martin 	fi
     55   1.1     lukem }
     56   1.1     lukem 
     57   1.2     lukem load_rc_config $name
     58   1.1     lukem run_rc_command "$1"
     59