From owner-freebsd-rc@FreeBSD.ORG Thu Oct 12 10:40:21 2006 Return-Path: X-Original-To: freebsd-rc@hub.freebsd.org Delivered-To: freebsd-rc@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B67B916A416 for ; Thu, 12 Oct 2006 10:40:21 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7059E43D81 for ; Thu, 12 Oct 2006 10:40:21 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k9CAeLGO080085 for ; Thu, 12 Oct 2006 10:40:21 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k9CAeLB8080084; Thu, 12 Oct 2006 10:40:21 GMT (envelope-from gnats) Date: Thu, 12 Oct 2006 10:40:21 GMT Message-Id: <200610121040.k9CAeLB8080084@freefall.freebsd.org> To: freebsd-rc@FreeBSD.org From: Andrey Simonenko Cc: Subject: Re: bin/104044: [patch] rc.d/cleartmp works incorrectly X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Andrey Simonenko List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Oct 2006 10:40:21 -0000 The following reply was made to PR bin/104044; it has been noted by GNATS. From: Andrey Simonenko To: Yar Tikhiy Cc: Florent Thoumie , bug-followup@freebsd.org Subject: Re: bin/104044: [patch] rc.d/cleartmp works incorrectly Date: Thu, 12 Oct 2006 13:36:29 +0300 On Tue, Oct 10, 2006 at 03:31:35PM +0400, Yar Tikhiy wrote: > On Tue, Oct 10, 2006 at 02:34:43PM +0400, Yar Tikhiy wrote: > > > > > 2. Ignore error code from rm and always run find, that is > > > use "rm ... ; find ..." instead of "rm ... && find ...": > > > one can create many files with long names and rm will not > > > be called because of "Argument list too long" error, so > > > find should do all of the work. > > > > By the way, did you consider omitting the first rm at all and just > > using "find ... -print0 | xargs -0 rm -rf" ? The first rm can be > > an optimization as long as we use find with -exec. OTOH, xargs -0 > > would buy us the same performance and robustness without hacks. > > Both find and xargs should be available to cleartmp. Here's the > > code. Note "type -d" omitted. > > > > if checkyesno ${rcvar1}; then > > # This is not needed with mfs /tmp, but doesn't hurt anything. > > echo "Clearing /tmp." > > find -x /tmp/. ! -name . \ > > ! \( -name lost+found -type d -user root \) \ > > ! \( \( -name quota.user -or -name quota.group \) \ > > -type f -user root \) \ > > -prune -print0 | xargs -0 rm -rf > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > elif ... > > It seems we can use just "-delete" here. If run as root, find > deletes entries with funny permissions or flags as well as rm does. > BTW, find will descend into lost+found and delete its contents in > both cases (rm w/ -prune, or -delete), which is good IMHO. --- cleartmp.orig Mon Apr 10 16:10:30 2006 +++ cleartmp Thu Oct 12 13:08:00 2006 @@ -10,47 +10,33 @@ . /etc/rc.subr name="cleartmp" -rcvar=`set_rcvar clear_tmp` - +rcvar1=`set_rcvar clear_tmp` start_cmd="${name}_start" -cleartmp_prestart() +cleartmp_start() { - checkyesno clear_tmp_X || return - local x11_socket_dirs="/tmp/.X11-unix /tmp/.ICE-unix /tmp/.font-unix \ /tmp/.XIM-unix" - # Remove X lock files, since they will prevent you from restarting X. - rm -f /tmp/.X[0-9]-lock - - # Create socket directories with correct permissions to avoid - # security problem. - # - rm -fr ${x11_socket_dirs} - mkdir -m 1777 ${x11_socket_dirs} -} - -cleartmp_start() -{ - echo "Clearing /tmp." - # - # 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). - # - (cd /tmp && rm -rf [a-km-pr-zA-Z]* && - find -x . ! -name . ! -name lost+found ! -name quota.user \ - ! -name quota.group ! -name .X11-unix ! -name .ICE-unix \ - ! -name .font-unix ! -name .XIM-unix \ - -exec rm -rf -- {} \; -type d -prune) + if checkyesno ${rcvar1}; then + # This is not needed for mfs /tmp, but doesn't hurt anything. + echo "Clearing /tmp." + find -x /tmp/. ! -name . \ + ! \( -name lost+found -type d -user root \) \ + ! \( \( -name quota.user -or -name quota.group \) \ + -type f -user root \) \ + -delete + elif checkyesno clear_tmp_X; then + # Remove X lock files, since they will prevent you from + # restarting X. Remove other X related directories. + echo "Clearing /tmp (X related)." + rm -rf /tmp/.X[0-9]-lock ${x11_socket_dirs} + fi + if checkyesno clear_tmp_X; then + # Create X related directories. + mkdir -m 1777 ${x11_socket_dirs} + fi } load_rc_config $name - -# The clear_tmp_X variable should be tested even if clear_tmp_enable is NO -case "$1" in -*start) cleartmp_prestart ;; -esac - run_rc_command "$1"