From nobody@FreeBSD.org  Tue Sep 20 12:19:03 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 1F83F1065672
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 20 Sep 2011 12:19:03 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 0F0768FC1A
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 20 Sep 2011 12:19:03 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p8KCJ2f5002466
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 20 Sep 2011 12:19:02 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p8KCJ2cd002465;
	Tue, 20 Sep 2011 12:19:02 GMT
	(envelope-from nobody)
Message-Id: <201109201219.p8KCJ2cd002465@red.freebsd.org>
Date: Tue, 20 Sep 2011 12:19:02 GMT
From: Andrey Zonov <andrey@zonov.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] [etc/periodic] 310.accounting ignore $daily_accounting_save
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         160848
>Category:       conf
>Synopsis:       [patch] [periodic] 310.accounting ignore $daily_accounting_save
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    dougb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 20 12:20:08 UTC 2011
>Closed-Date:    Thu Dec 01 07:35:11 UTC 2011
>Last-Modified:  Thu Dec 01 07:35:11 UTC 2011
>Originator:     Andrey Zonov
>Release:        8.2-STABLE
>Organization:
>Environment:
>Description:
Last commit to /etc/periodic/daily/310.accounting broke rotation accounting logs.
>How-To-Repeat:
Turn on accouting:
echo 'accounting_enable="YES"' > /etc/rc.conf.d/accounting

Check /var/account/ after few days. You will find that there's only one `acct' file.
>Fix:
Patch is in attach.

Patch attached with submission follows:

Index: 310.accounting
===================================================================
--- 310.accounting	(revision 225579)
+++ 310.accounting	(working copy)
@@ -44,13 +44,12 @@
 
 	    /etc/rc.d/accounting rotate_log || rc=3
 
+	    sa $daily_accounting_flags /var/account/acct.0 || rc=3
+
 	    case "$daily_accounting_compress" in
 		[Yy][Ee][Ss])
-		    gzip --keep -f acct.0 || rc=3;;
+		    gzip -f acct.0 || rc=3;;
 	    esac
-
-	    sa -s $daily_accounting_flags /var/account/acct.0 &&
-		unlink acct.0 || rc=3
 	fi;;
 
     *)  rc=0;;


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->dougb 
Responsible-Changed-By: dougb 
Responsible-Changed-When: Fri Oct 21 22:28:31 UTC 2011 
Responsible-Changed-Why:  

My changes, so I'll take a look at this. 

FYI, I don't see the problems you're seeing. I dug into this problem 
initialy because I'm using accounting on some busy servers. All the 
systems I have it enabled on save the appropriate number of logs. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=160848 
State-Changed-From-To: open->closed 
State-Changed-By: dougb 
State-Changed-When: Mon Nov 7 06:32:18 UTC 2011 
State-Changed-Why:  

Sorry I didn't catch this sooner. The scripts in /etc/periodic 
are not rc.d scripts. You need to put daily_accounting_enable="YES" 
in /etc/periodic.conf. 

Doug 

http://www.freebsd.org/cgi/query-pr.cgi?pr=160848 

From: Andrey Zonov <andrey@zonov.org>
To: bug-followup@FreeBSD.org, andrey@zonov.org
Cc:  
Subject: Re: conf/160848: [patch] [periodic] 310.accounting ignore $daily_accounting_save
Date: Mon, 07 Nov 2011 23:36:13 +0400

 Hi,
 
 daily_accounting_enable="YES" already is in /etc/defaults/periodic.conf 
 and by default the number of saved files is 3.
 Maybe you didn't catch the problem because you use 
 daily_accounting_compress="YES" which is not turned on by default.
 
 So if you look in the end of 310.accounting you'll see:
 
 sa -s $daily_accounting_flags /var/account/acct.0 &&
 unlink acct.0 || rc=3
 
 does it make sense? You always truncate and then delete previous file.
 
 -- 
 Andrey Zonov
 
State-Changed-From-To: closed->analyzed 
State-Changed-By: dougb 
State-Changed-When: Fri Nov 11 01:27:28 UTC 2011 
State-Changed-Why:  

I see what you're saying now, sorry I missed it previously. 

Your patch looks like it's going in the right direction, I will need 
to do some testing to be sure. 

Thanks for being patient, 

Doug 

http://www.freebsd.org/cgi/query-pr.cgi?pr=160848 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: conf/160848: commit references a PR
Date: Sun, 13 Nov 2011 03:02:13 +0000 (UTC)

 Author: dougb
 Date: Sun Nov 13 03:01:58 2011
 New Revision: 227482
 URL: http://svn.freebsd.org/changeset/base/227482
 
 Log:
   The default setting, daily_accounting_compress="NO", was causing
   only 1 old file to be saved, so fix this. Problem raised in the PR,
   but actually required a different solution.
   
   While I'm here, fix a very old off-by-one error causing 1 more file
   than specified in daily_accounting_save to be saved because acct.0
   was not taken into account (pun intended). Change that, and use a more
   thorough method of finding old files to delete. Partly just because this
   is the right thing to do, but also to silently fix the extra log that
   would have been left behind forever with the previous method.
   
   PR:		conf/160848
   Submitted by:	Andrey Zonov <andrey@zonov.org>
 
 Modified:
   head/etc/periodic/daily/310.accounting
 
 Modified: head/etc/periodic/daily/310.accounting
 ==============================================================================
 --- head/etc/periodic/daily/310.accounting	Sun Nov 13 02:32:10 2011	(r227481)
 +++ head/etc/periodic/daily/310.accounting	Sun Nov 13 03:01:58 2011	(r227482)
 @@ -30,8 +30,13 @@ case "$daily_accounting_enable" in
  	    cd /var/account
  	    rc=0
  
 -	    n=$daily_accounting_save
 -	    rm -f acct.$n.gz acct.$n || rc=3
 +	    n=$(( $daily_accounting_save - 1 ))
 +	    for f in acct.*; do
 +	    	case "$f" in acct.\*) continue ;; esac	# No files match
 +	    	m=${f%.gz} ; m=${m#acct.}
 +		[ $m -ge $n ] && { rm $f || rc=3; }
 +	    done
 +
  	    m=$n
  	    n=$(($n - 1))
  	    while [ $n -ge 0 ]
 @@ -44,13 +49,14 @@ case "$daily_accounting_enable" in
  
  	    /etc/rc.d/accounting rotate_log || rc=3
  
 +	    rm -f acct.merge && cp acct.0 acct.merge || rc=3
 +	    sa -s $daily_accounting_flags /var/account/acct.merge || rc=3
 +	    rm acct.merge
 +
  	    case "$daily_accounting_compress" in
  		[Yy][Ee][Ss])
 -		    gzip --keep -f acct.0 || rc=3;;
 +		    gzip -f acct.0 || rc=3;;
  	    esac
 -
 -	    sa -s $daily_accounting_flags /var/account/acct.0 &&
 -		unlink acct.0 || rc=3
  	fi;;
  
      *)  rc=0;;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: analyzed->patched 
State-Changed-By: dougb 
State-Changed-When: Sun Nov 13 03:26:17 UTC 2011 
State-Changed-Why:  

I have identified, and I believe fixed the problem. Please try the 
version in HEAD to confirm that it fixes the problem for you. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=160848 

From: Andrey Zonov <andrey@zonov.org>
To: bug-followup@FreeBSD.org, andrey@zonov.org
Cc:  
Subject: Re: conf/160848: [patch] [periodic] 310.accounting ignore $daily_accounting_save
Date: Sun, 13 Nov 2011 21:51:39 +0400

 Hi,
 
 Version from HEAD fixes the problem, but I didn't get why we need this 
 "extra-copy"?
 
 + rm -f acct.merge && cp acct.0 acct.merge || rc=3
 
 -- 
 Andrey Zonov
 
State-Changed-From-To: patched->closed 
State-Changed-By: dougb 
State-Changed-When: Thu Dec 1 07:33:52 UTC 2011 
State-Changed-Why:  

Ok, closed for real this time, as in, MFC is complete. 

Thanks again, 

Doug 

http://www.freebsd.org/cgi/query-pr.cgi?pr=160848 
>Unformatted:
