Bug 129697

Summary: [patch] fix misbehavior of periodic/daily/100.clean-disks vs. port lang/sbcl
Product: Base System Reporter: V.Chukharev <chukharev>
Component: confAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Only Me CC: bsd
Priority: Normal Keywords: patch
Version: 7.1-PRERELEASE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff
none
100.clean-disks.patch none

Description V.Chukharev 2008-12-16 23:10:01 UTC
FreebBSD port lang/sbcl installs a file /usr/local/lib/sbcl/sbcl.core
This file has the name corresponding to the core dumps and it gets
deleted by a cron job /etc/periodic/daily/100.clean-disks if enabled in
/etc/periodic.conf.

Fix: The attached patch introduces a new variable daily_clean_disks_ignore
where the port can put a list of files to be kept, e.g. in periodic.conf:
daily_clean_disks_ignore="sbcl.core"

I hope that the port maintainer will add this line e.g. to the port message
when the patch is applied.

Comments?

Patch attached with submission follows:
How-To-Repeat: Install the port lang/sbcl and enable the cron job by setting in
/etc/periodic.conf :

daily_clean_disks_enable="YES"
daily_clean_disks_days=0

As root, run /etc/periodic/daily/100.clean-disks
The file /usr/local/lib/sbcl/sbcl.core will be deleted.
Comment 1 V.Chukharev 2009-02-26 20:15:44 UTC
I have made a new patch. Now it uses full path to the preserved files.
Among other files, sbcl installs two a.out files, and preserving all
files with this name like the original patch did is too much I think.

I've used the patch with the following lines in /etc/periodic.conf for few days now.

daily_clean_disks_enable="YES"				# Delete files daily
#daily_clean_disks_files="[#,]* .#* a.out *.core *.CKP .emacs_[0-9]*"
daily_clean_disks_days=2				# If older than this
daily_clean_disks_ignore="$daily_clean_disks_ignore /usr/local/lib/sbcl/sbcl.core"		# lang/sbcl
daily_clean_disks_ignore="$daily_clean_disks_ignore /usr/local/lib/sbcl/sb-bsd-sockets/a.out"	# lang/sbcl
daily_clean_disks_ignore="$daily_clean_disks_ignore /usr/local/lib/sbcl/sb-posix/a.out"		# lang/sbcl
daily_clean_disks_ignore="$daily_clean_disks_ignore /usr/local/lib/maxima/5.*/binary-sbcl/maxima.core"	# math/maxima


Of course, all these changes to periodic is actially only a temporary amendment. The real 
solution is to enforce the ports policy of renaming all files corresponding to the special 
cases. I have filed another PR ports/131790 with a feature request to portlint that it warns 
about the name collisions like these.

I CC to port maintainers of math/maxima and lang/sbcl so that they know about the issue
and might try to rename the offending files.

-- 
V. Chukharev
Comment 2 V.Chukharev 2009-10-20 21:14:02 UTC
This PR is similar to http://www.FreeBSD.org/cgi/query-pr.cgi?pr=conf/35545
and http://www.freebsd.org/cgi/query-pr.cgi?pr=conf/84752

-- 
Vladimir Chukharev
Tampere University of Technology
Comment 3 V.Chukharev 2009-11-22 19:18:47 UTC
The old patch worked for me for at least six months with no problems. Then I made
something in Windows (the machine is dual boot notebook), and found the following.
The windows filesystem is automatically mounted by gnome, it is not marked as read-only
but write operations on it are not allowed. So it is scanned by 100.clean-disks
resulting in messages in mails like
     rm: #SharedObjects: Operation not supported

A new version of the patch includes one more variable, daily_clean_disks_prune,
containing a list of directories to ignore with all their subdirectories.
Additionally, the new variables get empty strings as default values and comments
document meaning of the variables in /etc/defaults/periodic.conf.

NB. The script is off by default, thus the patch is not changing the default behavior.
Perhaps, "/media" (or even "/media /mnt") is a better default for daily_clean_disks_prune.
The file has mixed tabs and spaces, this might be nice to fix in a separate cosmetic
patch.

===
--- etc/defaults/periodic.conf.orig	2009-06-25 16:49:49.000000000 +0300
+++ etc/defaults/periodic.conf	2009-11-17 12:28:35.000000000 +0200
@@ -40,6 +40,8 @@
   daily_clean_disks_files="[#,]* .#* a.out *.core *.CKP .emacs_[0-9]*"
   daily_clean_disks_days=3				# If older than this
   daily_clean_disks_verbose="YES"				# Mention files deleted
+daily_clean_disks_prune=""					# Directories to ignore
+daily_clean_disks_ignore=""					# Files to ignore

   # 110.clean-tmps
   daily_clean_tmps_enable="NO"				# Delete stuff daily
--- etc/periodic/daily/100.clean-disks.orig	2009-10-24 18:20:24.000000000 +0300
+++ etc/periodic/daily/100.clean-disks	2009-11-17 16:15:06.000000000 +0200
@@ -29,10 +29,18 @@
   	    echo ""
   	    echo "Cleaning disks:"
   	    set -f noglob
-	    args="-name "`echo "$daily_clean_disks_files" |
+	    args="( -name "`echo "$daily_clean_disks_files" |
   		sed -e 's/^[ 	]*//' \
   		    -e 's/[ 	]*$//' \
-		    -e 's/[ 	][ 	]*/ -o -name /g'`
+		    -e 's/[ 	][ 	]*/ -o -name /g'`" )"
+
+		if ! [ -z "$daily_clean_disks_ignore" ]
+		then
+			args="$args -a ! ( -path "`echo "$daily_clean_disks_ignore" |
+			sed -e 's/^[ 	]*//' \
+				-e 's/[ 	]*$//' \
+				-e 's/[ 	][ 	]*/ -o -path /g'`" )"
+		fi

   	    case "$daily_clean_disks_verbose" in
   		[Yy][Ee][Ss])
@@ -41,9 +49,19 @@
   		    print=;;
   	    esac

-	    rc=$(find / \( ! -fstype local -o -fstype rdonly \) -prune -o \
-		\( $args \) -atime +$daily_clean_disks_days \
-		-execdir rm -df {} \; $print | tee /dev/stderr | wc -l)
+		if ! [ -z "$daily_clean_disks_prune" ]
+		then
+			prune="-o -path "`echo "$daily_clean_disks_prune" |
+			sed -e 's/^[ 	]*//' \
+				-e 's/[ 	]*$//' \
+				-e 's/[ 	][ 	]*/ -o -path /g'`
+		else
+			prune=""
+		fi
+
+	    command="find / ( ! -fstype local -o -fstype rdonly $prune ) -prune -o ( \
+		( $args ) -atime +$daily_clean_disks_days -execdir rm -df {} ; $print )"
+	    rc=$($command | tee /dev/stderr | wc -l)
   	    [ -z "$print" ] && rc=0
   	    [ $rc -gt 1 ] && rc=1
   	    set -f glob

===

-- 
Vladimir Chukharev
Tampere University of Technology
Comment 4 Bruce Cran freebsd_committer freebsd_triage 2010-03-13 12:24:28 UTC
State Changed
From-To: open->closed

100.clean-disks is disabled by default, and the user needs to configure 
/etc/periodic.conf before it can be used.
Comment 5 V.Chukharev 2010-03-14 13:55:25 UTC
Very weird logic in the explanation why... With this logic, all ports which need *_enable="YES"
in rc.conf should never be fixed, which is definitely not the case.

If you just want to reduce the number of open PRs, put a reference to the one left open and a
back reference in that one. A good candidate is conf/35545. Sorry I found that and other related
PRs too late.


Vladimir Chukharev
Comment 6 Bruce Cran freebsd_committer freebsd_triage 2010-03-14 15:16:47 UTC
State Changed
From-To: closed->open

Re-open. 100.clean-disks should probably check that any .core files it removes 
are actually core files. 


Comment 7 Bruce Cran freebsd_committer freebsd_triage 2010-03-14 15:16:47 UTC
Responsible Changed
From-To: freebsd-bugs->brucec

Track.
Comment 8 Bruce Cran freebsd_committer freebsd_triage 2010-11-22 10:19:16 UTC
Responsible Changed
From-To: brucec->freebsd-bugs

Back to the pool.
Comment 9 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:18 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 10 Sam 2018-01-24 13:27:02 UTC
This is still affecting SBCL unfortunately.

Right now I am doing the core cleanup manually, but it would be nice to be able to rely on FreeBSD's Base System's mechanism.
Comment 11 Graham Perrin freebsd_committer freebsd_triage 2022-10-17 12:40:05 UTC
Keyword: 

    patch
or  patch-ready

– in lieu of summary line prefix: 

    [patch]

* bulk change for the keyword
* summary lines may be edited manually (not in bulk). 

Keyword descriptions and search interface: 

    <https://bugs.freebsd.org/bugzilla/describekeywords.cgi>