From 410421ee21d6d0d89b3548b9a74796dbb6d1caaf Mon Sep 17 00:00:00 2001 From: apb Date: Wed, 24 Oct 2012 21:23:55 +0000 Subject: [PATCH] Avoid using glob patterns that might match enough files to give "Arg list too long" errors. Change the "find" command to use "-exec ... +" instead of "-exec ... \;" to make it more efficient. --- etc/rc.d/cleartmp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/etc/rc.d/cleartmp b/etc/rc.d/cleartmp index 384bfa973d22..ec1a94198905 100755 --- a/etc/rc.d/cleartmp +++ b/etc/rc.d/cleartmp @@ -1,6 +1,6 @@ #!/bin/sh # -# $NetBSD: cleartmp,v 1.10 2007/12/04 22:09:01 mjf Exp $ +# $NetBSD: cleartmp,v 1.11 2012/10/24 21:23:55 apb Exp $ # # PROVIDE: cleartmp @@ -17,11 +17,6 @@ stop_cmd=":" cleartmp_start() { echo "Clearing temporary files." - # - # Prune quickly with one rm, then use find to clean up - # /tmp/[lq]* (this is not needed with mfs /tmp, but - # doesn't hurt anything). - # if checkyesno per_user_tmp && [ -d ${per_user_tmp_dir} ]; then tmp_dir=${per_user_tmp_dir} else @@ -36,9 +31,20 @@ cleartmp_start() fi fi - (cd ${tmp_dir} && rm -rf [a-km-pr-zA-Z]* && + # + # Delete almost everything, except lost+found, quota.user, + # and quota.group in the top level. (This is not needed + # with mfs or tmpfs /tmp, but doesn't hurt anything). + # + # The find command, with "-exec ... +" instead of "-exec + # ... \;", will pass many file or dir names to each + # invocation of "rm -rf". We avoid using any glob + # patterns because of the risk of "Arg list too long" + # errors when there are very many files. + # + (cd ${tmp_dir} && find -x . ! -name . ! -name lost+found ! -name quota.user \ - ! -name quota.group -exec rm -rf -- {} \; -type d -prune) + ! -name quota.group -exec rm -rf -- {} \+ -type d -prune) } load_rc_config $name