cleartmp revision 1.12
11.1Slukem#!/bin/sh 21.1Slukem# 31.12Sdholland# $NetBSD: cleartmp,v 1.12 2015/07/03 18:36:54 dholland Exp $ 41.1Slukem# 51.1Slukem 61.1Slukem# PROVIDE: cleartmp 71.1Slukem# REQUIRE: mountall 81.4Sthorpej# BEFORE: DAEMON 91.1Slukem 101.5Smycroft$_rc_subr_loaded . /etc/rc.subr 111.1Slukem 121.1Slukemname="cleartmp" 131.3Slukemrcvar="clear_tmp" 141.1Slukemstart_cmd="cleartmp_start" 151.1Slukemstop_cmd=":" 161.1Slukem 171.1Slukemcleartmp_start() 181.1Slukem{ 191.8Selad echo "Clearing temporary files." 201.9Sxtraeme if checkyesno per_user_tmp && [ -d ${per_user_tmp_dir} ]; then 211.8Selad tmp_dir=${per_user_tmp_dir} 221.8Selad else 231.8Selad tmp_dir="/tmp" 241.9Sxtraeme # Check if /tmp was created by the perusertmp rc.d 251.9Sxtraeme # script and recreate it if necessary. 261.10Smjf if [ "$(/usr/bin/readlink /tmp)" = ${per_user_tmp_dir}/@ruid ]; then 271.9Sxtraeme /bin/rm -rf ${tmp_dir} 281.9Sxtraeme /bin/mkdir ${tmp_dir} 291.12Sdholland /sbin/chown root:wheel ${tmp_dir} 301.9Sxtraeme /bin/chmod 1777 ${tmp_dir} 311.9Sxtraeme fi 321.8Selad fi 331.8Selad 341.11Sapb # 351.11Sapb # Delete almost everything, except lost+found, quota.user, 361.11Sapb # and quota.group in the top level. (This is not needed 371.11Sapb # with mfs or tmpfs /tmp, but doesn't hurt anything). 381.11Sapb # 391.11Sapb # The find command, with "-exec ... +" instead of "-exec 401.11Sapb # ... \;", will pass many file or dir names to each 411.11Sapb # invocation of "rm -rf". We avoid using any glob 421.11Sapb # patterns because of the risk of "Arg list too long" 431.11Sapb # errors when there are very many files. 441.11Sapb # 451.11Sapb (cd ${tmp_dir} && 461.1Slukem find -x . ! -name . ! -name lost+found ! -name quota.user \ 471.11Sapb ! -name quota.group -exec rm -rf -- {} \+ -type d -prune) 481.1Slukem} 491.1Slukem 501.2Slukemload_rc_config $name 511.1Slukemrun_rc_command "$1" 52