From jdc@koitsu.dyndns.org  Thu Apr 26 11:37:30 2012
Return-Path: <jdc@koitsu.dyndns.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id D040B106566C
	for <freebsd-gnats-submit@freebsd.org>; Thu, 26 Apr 2012 11:37:30 +0000 (UTC)
	(envelope-from jdc@koitsu.dyndns.org)
Received: from qmta06.emeryville.ca.mail.comcast.net (qmta06.emeryville.ca.mail.comcast.net [76.96.30.56])
	by mx1.freebsd.org (Postfix) with ESMTP id 7B03B8FC14
	for <freebsd-gnats-submit@freebsd.org>; Thu, 26 Apr 2012 11:37:30 +0000 (UTC)
Received: from omta17.emeryville.ca.mail.comcast.net ([76.96.30.73])
	by qmta06.emeryville.ca.mail.comcast.net with comcast
	id 2bDl1j0051afHeLA6bdQzA; Thu, 26 Apr 2012 11:37:24 +0000
Received: from koitsu.dyndns.org ([67.180.84.87])
	by omta17.emeryville.ca.mail.comcast.net with comcast
	id 2bdQ1j0071t3BNj8dbdQFS; Thu, 26 Apr 2012 11:37:24 +0000
Received: by icarus.home.lan (Postfix, from userid 1000)
	id C5D39102C1E; Thu, 26 Apr 2012 04:37:23 -0700 (PDT)
Message-Id: <20120426113723.C5D39102C1E@icarus.home.lan>
Date: Thu, 26 Apr 2012 04:37:23 -0700 (PDT)
From: Jeremy Chadwick <jdc@koitsu.org>
Reply-To: Jeremy Chadwick <jdc@koitsu.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc: dougb@FreeBSD.org
Subject: Implement sysctl to control kernel accounting log messages (e.g. acct(2))
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         167321
>Category:       kern
>Synopsis:       [sysctl] [patch] Implement sysctl to control kernel accounting log messages (e.g. acct(2))
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    jhb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Apr 26 11:40:08 UTC 2012
>Closed-Date:    Tue Feb 26 16:58:51 UTC 2013
>Last-Modified:  Tue Feb 26 17:00:02 UTC 2013
>Originator:     Jeremy Chadwick
>Release:        FreeBSD 8.2-STABLE amd64
>Organization:
>Environment:
System: FreeBSD icarus.home.lan 8.2-STABLE FreeBSD 8.2-STABLE #0: Fri Feb 10 17:43:50 PST 2012 root@icarus.home.lan:/usr/obj/usr/src/sys/X7SBA_RELENG_8_amd64 amd64
>Description:
	The periodic script daily/310.accounting results in accounting
	being fully stopped then fully started every day.  This causes
	the message "Accounting disabled" followed by "Accounting enabled"
	being printed on the console (syslog level kern.notice).

	This happens because daily/310.accounting calls /etc/rc.d/accounting
	with the argument rotate_log.  This function quite literally calls
	/usr/sbin/accton twice.  See accounting_rotate_log() (read it slowly)
	to see what's going on.

	The messages comes from src/sys/kern/kern_acct.c, where
	log(LOG_NOTICE, "...") is called every time accounting is toggled
	via the acct(2) syscall (accomplished via accton(8)).

	The end result is a kernel message buffer that will eventually
	be filled with the above two messages.  This is extremely annoying,
	and unecessary for something like accounting log rotation.

	We wanted to use accounting (mainly for tracking disk I/O on a
	per-user and per-process level), but because of this problem, we
	had to cease use of it.
>How-To-Repeat:
	1. Set accounting_enabled="yes" in /etc/rc.conf
	2. Start accounting via "/etc/rc.d/accounting start"
	3. Look at "dmesg" or /var/log/messages
	4. Run /etc/periodic/daily/310.accounting
	5. Look at "dmesg" or /var/log/messages
>Fix:
	There's a couple ways to fix this, but I'm of the opinion this is
	the best choice with the least breakage:

	Implement a sysctl called kern.acct_logging which would control
	whether or not the log() statements are called.  1=enable logging,
	0=disable logging.  Default value would be 1 (to remain fully
	compatible with the existing model).

	Toggling this sysctl WOULD NOT result in any log() message being
	generated (i.e. no "Account logging disabled" message or similar),
	because if it did, we've solved absolutely nothing.

	Key point for those concerned about security ("wait, what if
	someone turns off logging?  Wouldn't you want to know that?"):
	acct(2) can only be called by root, and sysctls can only be
	modified by root.  An attacker who wanted to circumvent accounting
	would have to already have root.  Thus, the sysctl variable poses
	no security concern.

	If there are still somehow security concerns, then this could
	be made into a loader-adjustable-only tunable.

	I'd be happy to write the kernel code for this (it can't be that
	complex), but I would need someone senior to make sure it's
	safe/wouldn't cause problems.  The kernel is not my most familiar
	of playgrounds.
>Release-Note:
>Audit-Trail:

From: Jeremy Chadwick <jdc@koitsu.org>
To: FreeBSD-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org
Cc:  
Subject: Re: kern/167321: Implement sysctl to control kernel accounting log
 messages (e.g. acct(2))
Date: Thu, 26 Apr 2012 05:00:08 -0700

 Proposed patch is attached, as well as available at the below URL.
 Please note I HAVE NOT tested this, but it seems simple enough.
 
 http://jdc.koitsu.org/freebsd/167321/
 
 Patch written for RELENG_8, may/may not patch cleanly on others.
 
 -- 
 | Jeremy Chadwick                                   jdc@koitsu.org |
 | UNIX Systems Administrator                http://jdc.koitsu.org/ |
 | Mountain View, CA, US                                            |
 | Making life hard for others since 1977.             PGP 4BD6C0CB |
 
 --- SNIP ---
 
 --- src/sys/kern/kern_acct.c.orig	2009-08-03 01:13:06.000000000 -0700
 +++ src/sys/kern/kern_acct.c	2012-04-26 04:53:31.428339406 -0700
 @@ -146,6 +146,9 @@
  #define	ACCT_RUNNING	1	/* Accounting kthread is running. */
  #define	ACCT_EXITREQ	2	/* Accounting kthread should exit. */
  
 +/* sysctl variable used for controlling non-critical log() calls */
 +static int		 acct_logging = 1;
 +
  /*
   * Values associated with enabling and disabling accounting
   */
 @@ -188,6 +191,9 @@
  SYSCTL_INT(_kern, OID_AUTO, acct_suspended, CTLFLAG_RD, &acct_suspended, 0,
  	"Accounting suspended or not");
  
 +SYSCTL_INT(_kern, OID_AUTO, acct_logging, CTLFLAG_RW, &acct_logging, 0
 +	"Log non-critical accounting messages");
 +
  /*
   * Accounting system call.  Written based on the specification and previous
   * implementation done by Mark Tinguely.
 @@ -299,7 +305,8 @@
  	}
  	acct_configured = 1;
  	sx_xunlock(&acct_sx);
 -	log(LOG_NOTICE, "Accounting enabled\n");
 +	if (acct_logging)
 +		log(LOG_NOTICE, "Accounting enabled\n");
  	return (error);
  }
  
 @@ -319,7 +326,8 @@
  	acct_vp = NULL;
  	acct_cred = NULL;
  	acct_flags = 0;
 -	log(LOG_NOTICE, "Accounting disabled\n");
 +	if (acct_logging)
 +		log(LOG_NOTICE, "Accounting disabled\n");
  	return (error);
  }
  
 @@ -593,13 +601,15 @@
  		if (sb.f_bavail > (int64_t)(acctresume * sb.f_blocks /
  		    100)) {
  			acct_suspended = 0;
 -			log(LOG_NOTICE, "Accounting resumed\n");
 +			if (acct_logging)
 +				log(LOG_NOTICE, "Accounting resumed\n");
  		}
  	} else {
  		if (sb.f_bavail <= (int64_t)(acctsuspend * sb.f_blocks /
  		    100)) {
  			acct_suspended = 1;
 -			log(LOG_NOTICE, "Accounting suspended\n");
 +			if (acct_logging)
 +				log(LOG_NOTICE, "Accounting suspended\n");
  		}
  	}
  }

From: Jeremy Chadwick <jdc@koitsu.org>
To: FreeBSD-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org
Cc:  
Subject: Re: kern/167321: Implement sysctl to control kernel accounting log
 messages (e.g. acct(2))
Date: Thu, 26 Apr 2012 05:18:02 -0700

 ...and also the patch for the acct(2) man page, documenting this
 variable.
 
 -- 
 | Jeremy Chadwick                                   jdc@koitsu.org |
 | UNIX Systems Administrator                http://jdc.koitsu.org/ |
 | Mountain View, CA, US                                            |
 | Making life hard for others since 1977.             PGP 4BD6C0CB |
 
 --- SNIP ---
 
 --- src/lib/libc/sys/acct.2.orig	2009-08-03 01:13:06.000000000 -0700
 +++ src/lib/libc/sys/acct.2	2012-04-26 05:11:42.670706272 -0700
 @@ -87,6 +87,16 @@
  .It Va kern.acct_suspend
  The percentage of free disk space below which process
  accounting will suspend.
 +.It Va kern.acct_logging
 +If set to 0, the kernel will inhibit console messages indicating when
 +accounting is enabled, disabled, suspended, or resumed.  This can be
 +useful when the
 +.Xr periodic.conf 5
 +variable
 +.Va daily_accounting_enable
 +is set to
 +.Dq YES .
 +The default value is 1 (enabled).
  .El
  .Sh RETURN VALUES
  On error -1 is returned.

From: John Baldwin <jhb@freebsd.org>
To: bug-followup@freebsd.org,
 jdc@koitsu.org
Cc: dougb@freebsd.org
Subject: Re: kern/167321: [sysctl] [patch] Implement sysctl to control kernel accounting log messages (e.g. acct(2))
Date: Thu, 26 Apr 2012 09:30:01 -0400

 Hmm, reading the rc.d script and the kernel code, it is not clear to me why 
 you are seeing "Accounting disabled" messages at all.  You should be seeing 
 two "Accounting enabled" messages, but no disabled.  However, it seems that 
 the 'rotate_log' command in /etc/rc.d/accounting can be simplified.  The 
 kernel doesn't care about the pathname, so it doesn't need to have accton re-
 run when the file is renamed from its temporary filename to it's full name.
 
 You could then update the acct() system call to not log the message when 
 accounting is switched from one file to another atomically.  I think these two 
 changes will address your problem while preserving the useful logging:
 
 Index: etc/rc.d/accounting
 ===================================================================
 --- etc/rc.d/accounting	(revision 234685)
 +++ etc/rc.d/accounting	(working copy)
 @@ -65,9 +65,7 @@
  	mv ${accounting_file} ${accounting_file}.0
  
  	if checkyesno accounting_enable; then
 -		ln $_file ${accounting_file##*/}
 -		${accounting_command} ${accounting_file}
 -		unlink $_file
 +		mv $_file ${accounting_file}
  	fi
  }
  
 Index: sys/kern/kern_acct.c
 ===================================================================
 --- sys/kern/kern_acct.c	(revision 234685)
 +++ sys/kern/kern_acct.c	(working copy)
 @@ -297,9 +297,11 @@
  			return (error);
  		}
  	}
 -	acct_configured = 1;
 +	if (!acct_configured) {
 +		acct_configured = 1;
 +		log(LOG_NOTICE, "Accounting enabled\n");
 +	}
  	sx_xunlock(&acct_sx);
 -	log(LOG_NOTICE, "Accounting enabled\n");
  	return (error);
  }
  
 
 -- 
 John Baldwin

From: Jeremy Chadwick <jdc@koitsu.org>
To: FreeBSD-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org
Cc:  
Subject: Re: kern/167321: Implement sysctl to control kernel accounting log
 messages (e.g. acct(2))
Date: Thu, 26 Apr 2012 22:19:13 -0700

 Note for readers/committer: hold off on doing anything quite yet.
 I'm in conversation with John Baldwin (jhb@) about this issue, and
 he's given me a patch (to both the periodic script and the kernel)
 that may rectify the entire "excess logging" situation entirely.
 
 Will report back in the next few weeks (have health things/doctors
 visits going on, so please be patient).  Thanks.
 
 -- 
 | Jeremy Chadwick                                   jdc@koitsu.org |
 | UNIX Systems Administrator                http://jdc.koitsu.org/ |
 | Mountain View, CA, US                                            |
 | Making life hard for others since 1977.             PGP 4BD6C0CB |
 

From: Jeremy Chadwick <jdc@koitsu.org>
To: John Baldwin <jhb@freebsd.org>
Cc:  
Subject: Re: kern/167321: [sysctl] [patch] Implement sysctl to control kernel
 accounting log messages (e.g. acct(2))
Date: Thu, 26 Apr 2012 22:17:56 -0700

 On Thu, Apr 26, 2012 at 09:30:01AM -0400, John Baldwin wrote:
 > Hmm, reading the rc.d script and the kernel code, it is not clear to me why 
 > you are seeing "Accounting disabled" messages at all.  You should be seeing 
 > two "Accounting enabled" messages, but no disabled.
 
 Taken from our logs on one box (but they all show the same behaviour):
 
 /var/log/messages:Apr 26 00:39:47 ra kernel: Accounting enabled
 /var/log/messages:Apr 26 03:01:00 ra kernel: Accounting disabled
 /var/log/messages:Apr 26 03:01:00 ra kernel: Accounting enabled
 /var/log/messages:Apr 26 03:01:00 ra kernel: Accounting disabled
 /var/log/messages:Apr 26 03:01:00 ra kernel: Accounting enabled
 /var/log/messages:Apr 26 04:38:40 ra kernel: Accounting disabled
 
 00:39 = when we enabled accounting for the very first time
 03:01 = entries caused by periodic script
 04:38 = when we disabled accounting due to this problem.
 
 > However, it seems that the 'rotate_log' command in
 > /etc/rc.d/accounting can be simplified.  The kernel doesn't care about
 > the pathname, so it doesn't need to have accton re- run when the file
 > is renamed from its temporary filename to it's full name.
 > 
 > You could then update the acct() system call to not log the message
 > when accounting is switched from one file to another atomically.  I
 > think these two changes will address your problem while preserving the
 > useful logging:
 
 Your kernel patch looks a *lot* more elegant and logical (yep I
 understand it :-) ).  I'll give it a try on my home machine here and
 report back the results.  Might be a few days though given health
 problems and doctors visits going on.
 
 Thanks as usual, John!
 
 -- 
 | Jeremy Chadwick                                   jdc@koitsu.org |
 | UNIX Systems Administrator                http://jdc.koitsu.org/ |
 | Mountain View, CA, US                                            |
 | Making life hard for others since 1977.             PGP 4BD6C0CB |
 
 
 > Index: etc/rc.d/accounting
 > ===================================================================
 > --- etc/rc.d/accounting	(revision 234685)
 > +++ etc/rc.d/accounting	(working copy)
 > @@ -65,9 +65,7 @@
 >  	mv ${accounting_file} ${accounting_file}.0
 >  
 >  	if checkyesno accounting_enable; then
 > -		ln $_file ${accounting_file##*/}
 > -		${accounting_command} ${accounting_file}
 > -		unlink $_file
 > +		mv $_file ${accounting_file}
 >  	fi
 >  }
 >  
 > Index: sys/kern/kern_acct.c
 > ===================================================================
 > --- sys/kern/kern_acct.c	(revision 234685)
 > +++ sys/kern/kern_acct.c	(working copy)
 > @@ -297,9 +297,11 @@
 >  			return (error);
 >  		}
 >  	}
 > -	acct_configured = 1;
 > +	if (!acct_configured) {
 > +		acct_configured = 1;
 > +		log(LOG_NOTICE, "Accounting enabled\n");
 > +	}
 >  	sx_xunlock(&acct_sx);
 > -	log(LOG_NOTICE, "Accounting enabled\n");
 >  	return (error);
 >  }
 >  
 > 
 > -- 
 > John Baldwin

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/167321: commit references a PR
Date: Wed,  2 May 2012 14:25:53 +0000 (UTC)

 Author: jhb
 Date: Wed May  2 14:25:39 2012
 New Revision: 234927
 URL: http://svn.freebsd.org/changeset/base/234927
 
 Log:
   - Don't log messages saying that accounting is being disabled and enabled
     if the accounting log file is atomically replaced with a new file
     (such as during log rotation).
   - Simplify accounting log rotation a bit.  There is no need to re-run
     accton(8) after renaming the new log file to it's real name.
   
   PR:		kern/167321
   Tested by:	Jeremy Chadwick
 
 Modified:
   head/etc/rc.d/accounting
   head/sys/kern/kern_acct.c
 
 Modified: head/etc/rc.d/accounting
 ==============================================================================
 --- head/etc/rc.d/accounting	Wed May  2 12:15:34 2012	(r234926)
 +++ head/etc/rc.d/accounting	Wed May  2 14:25:39 2012	(r234927)
 @@ -65,9 +65,7 @@ accounting_rotate_log()
  	mv ${accounting_file} ${accounting_file}.0
  
  	if checkyesno accounting_enable; then
 -		ln $_file ${accounting_file##*/}
 -		${accounting_command} ${accounting_file}
 -		unlink $_file
 +		mv $_file ${accounting_file}
  	fi
  }
  
 
 Modified: head/sys/kern/kern_acct.c
 ==============================================================================
 --- head/sys/kern/kern_acct.c	Wed May  2 12:15:34 2012	(r234926)
 +++ head/sys/kern/kern_acct.c	Wed May  2 14:25:39 2012	(r234927)
 @@ -122,7 +122,7 @@ static uint32_t	encode_timeval(struct ti
  static uint32_t	encode_long(long);
  static void	acctwatch(void);
  static void	acct_thread(void *);
 -static int	acct_disable(struct thread *);
 +static int	acct_disable(struct thread *, int);
  
  /*
   * Accounting vnode pointer, saved vnode pointer, and flags for each.
 @@ -196,7 +196,7 @@ int
  sys_acct(struct thread *td, struct acct_args *uap)
  {
  	struct nameidata nd;
 -	int error, flags, vfslocked;
 +	int error, flags, vfslocked, replacing;
  
  	error = priv_check(td, PRIV_ACCT);
  	if (error)
 @@ -246,6 +246,13 @@ sys_acct(struct thread *td, struct acct_
  	sx_xlock(&acct_sx);
  
  	/*
 +	 * Don't log spurious disable/enable messages if we are
 +	 * switching from one accounting file to another due to log
 +	 * rotation.
 +	 */
 +	replacing = (acct_vp != NULL && uap->path != NULL);
 +
 +	/*
  	 * If accounting was previously enabled, kill the old space-watcher,
  	 * close the file, and (if no new file was specified, leave).  Reset
  	 * the suspended state regardless of whether accounting remains
 @@ -254,7 +261,7 @@ sys_acct(struct thread *td, struct acct_
  	acct_suspended = 0;
  	if (acct_vp != NULL) {
  		vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount);
 -		error = acct_disable(td);
 +		error = acct_disable(td, !replacing);
  		VFS_UNLOCK_GIANT(vfslocked);
  	}
  	if (uap->path == NULL) {
 @@ -299,7 +306,8 @@ sys_acct(struct thread *td, struct acct_
  	}
  	acct_configured = 1;
  	sx_xunlock(&acct_sx);
 -	log(LOG_NOTICE, "Accounting enabled\n");
 +	if (!replacing)
 +		log(LOG_NOTICE, "Accounting enabled\n");
  	return (error);
  }
  
 @@ -308,7 +316,7 @@ sys_acct(struct thread *td, struct acct_
   * our reference to the credential, and clearing the vnode's flags.
   */
  static int
 -acct_disable(struct thread *td)
 +acct_disable(struct thread *td, int logging)
  {
  	int error;
  
 @@ -319,7 +327,8 @@ acct_disable(struct thread *td)
  	acct_vp = NULL;
  	acct_cred = NULL;
  	acct_flags = 0;
 -	log(LOG_NOTICE, "Accounting disabled\n");
 +	if (logging)
 +		log(LOG_NOTICE, "Accounting disabled\n");
  	return (error);
  }
  
 @@ -574,7 +583,7 @@ acctwatch(void)
  	 */
  	vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount);
  	if (acct_vp->v_type == VBAD) {
 -		(void) acct_disable(NULL);
 +		(void) acct_disable(NULL, 1);
  		VFS_UNLOCK_GIANT(vfslocked);
  		acct_state |= ACCT_EXITREQ;
  		return;
 _______________________________________________
 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: open->patched 
State-Changed-By: jhb 
State-Changed-When: Wed May 2 16:57:32 UTC 2012 
State-Changed-Why:  
Fix committed to HEAD. 


Responsible-Changed-From-To: freebsd-bugs->jhb 
Responsible-Changed-By: jhb 
Responsible-Changed-When: Wed May 2 16:57:32 UTC 2012 
Responsible-Changed-Why:  
Fix committed to HEAD. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=167321 
State-Changed-From-To: patched->closed 
State-Changed-By: jhb 
State-Changed-When: Tue Feb 26 16:56:06 UTC 2013 
State-Changed-Why:  
Fix merged to 8 and 9. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/167321: commit references a PR
Date: Tue, 26 Feb 2013 16:56:02 +0000 (UTC)

 Author: jhb
 Date: Tue Feb 26 16:55:44 2013
 New Revision: 247321
 URL: http://svnweb.freebsd.org/changeset/base/247321
 
 Log:
   MFC 234927:
   - Don't log messages saying that accounting is being disabled and enabled
     if the accounting log file is atomically replaced with a new file
     (such as during log rotation).
   - Simplify accounting log rotation a bit.  There is no need to re-run
     accton(8) after renaming the new log file to it's real name.
   
   PR:		kern/167321
 
 Modified:
   stable/9/etc/rc.d/accounting
   stable/9/sys/kern/kern_acct.c
 Directory Properties:
   stable/9/etc/   (props changed)
   stable/9/sys/   (props changed)
 
 Modified: stable/9/etc/rc.d/accounting
 ==============================================================================
 --- stable/9/etc/rc.d/accounting	Tue Feb 26 15:51:46 2013	(r247320)
 +++ stable/9/etc/rc.d/accounting	Tue Feb 26 16:55:44 2013	(r247321)
 @@ -65,9 +65,7 @@ accounting_rotate_log()
  	mv ${accounting_file} ${accounting_file}.0
  
  	if checkyesno accounting_enable; then
 -		ln $_file ${accounting_file##*/}
 -		${accounting_command} ${accounting_file}
 -		unlink $_file
 +		mv $_file ${accounting_file}
  	fi
  }
  
 
 Modified: stable/9/sys/kern/kern_acct.c
 ==============================================================================
 --- stable/9/sys/kern/kern_acct.c	Tue Feb 26 15:51:46 2013	(r247320)
 +++ stable/9/sys/kern/kern_acct.c	Tue Feb 26 16:55:44 2013	(r247321)
 @@ -122,7 +122,7 @@ static uint32_t	encode_timeval(struct ti
  static uint32_t	encode_long(long);
  static void	acctwatch(void);
  static void	acct_thread(void *);
 -static int	acct_disable(struct thread *);
 +static int	acct_disable(struct thread *, int);
  
  /*
   * Accounting vnode pointer, saved vnode pointer, and flags for each.
 @@ -196,7 +196,7 @@ int
  sys_acct(struct thread *td, struct acct_args *uap)
  {
  	struct nameidata nd;
 -	int error, flags, vfslocked;
 +	int error, flags, vfslocked, replacing;
  
  	error = priv_check(td, PRIV_ACCT);
  	if (error)
 @@ -246,6 +246,13 @@ sys_acct(struct thread *td, struct acct_
  	sx_xlock(&acct_sx);
  
  	/*
 +	 * Don't log spurious disable/enable messages if we are
 +	 * switching from one accounting file to another due to log
 +	 * rotation.
 +	 */
 +	replacing = (acct_vp != NULL && uap->path != NULL);
 +
 +	/*
  	 * If accounting was previously enabled, kill the old space-watcher,
  	 * close the file, and (if no new file was specified, leave).  Reset
  	 * the suspended state regardless of whether accounting remains
 @@ -254,7 +261,7 @@ sys_acct(struct thread *td, struct acct_
  	acct_suspended = 0;
  	if (acct_vp != NULL) {
  		vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount);
 -		error = acct_disable(td);
 +		error = acct_disable(td, !replacing);
  		VFS_UNLOCK_GIANT(vfslocked);
  	}
  	if (uap->path == NULL) {
 @@ -299,7 +306,8 @@ sys_acct(struct thread *td, struct acct_
  	}
  	acct_configured = 1;
  	sx_xunlock(&acct_sx);
 -	log(LOG_NOTICE, "Accounting enabled\n");
 +	if (!replacing)
 +		log(LOG_NOTICE, "Accounting enabled\n");
  	return (error);
  }
  
 @@ -308,7 +316,7 @@ sys_acct(struct thread *td, struct acct_
   * our reference to the credential, and clearing the vnode's flags.
   */
  static int
 -acct_disable(struct thread *td)
 +acct_disable(struct thread *td, int logging)
  {
  	int error;
  
 @@ -319,7 +327,8 @@ acct_disable(struct thread *td)
  	acct_vp = NULL;
  	acct_cred = NULL;
  	acct_flags = 0;
 -	log(LOG_NOTICE, "Accounting disabled\n");
 +	if (logging)
 +		log(LOG_NOTICE, "Accounting disabled\n");
  	return (error);
  }
  
 @@ -574,7 +583,7 @@ acctwatch(void)
  	 */
  	vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount);
  	if (acct_vp->v_type == VBAD) {
 -		(void) acct_disable(NULL);
 +		(void) acct_disable(NULL, 1);
  		VFS_UNLOCK_GIANT(vfslocked);
  		acct_state |= ACCT_EXITREQ;
  		return;
 _______________________________________________
 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"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/167321: commit references a PR
Date: Tue, 26 Feb 2013 16:56:13 +0000 (UTC)

 Author: jhb
 Date: Tue Feb 26 16:55:59 2013
 New Revision: 247322
 URL: http://svnweb.freebsd.org/changeset/base/247322
 
 Log:
   MFC 234927:
   - Don't log messages saying that accounting is being disabled and enabled
     if the accounting log file is atomically replaced with a new file
     (such as during log rotation).
   - Simplify accounting log rotation a bit.  There is no need to re-run
     accton(8) after renaming the new log file to it's real name.
   
   PR:		kern/167321
 
 Modified:
   stable/8/etc/rc.d/accounting
   stable/8/sys/kern/kern_acct.c
 Directory Properties:
   stable/8/etc/   (props changed)
   stable/8/sys/   (props changed)
   stable/8/sys/kern/   (props changed)
 
 Modified: stable/8/etc/rc.d/accounting
 ==============================================================================
 --- stable/8/etc/rc.d/accounting	Tue Feb 26 16:55:44 2013	(r247321)
 +++ stable/8/etc/rc.d/accounting	Tue Feb 26 16:55:59 2013	(r247322)
 @@ -65,9 +65,7 @@ accounting_rotate_log()
  	mv ${accounting_file} ${accounting_file}.0
  
  	if checkyesno accounting_enable; then
 -		ln $_file ${accounting_file##*/}
 -		${accounting_command} ${accounting_file}
 -		unlink $_file
 +		mv $_file ${accounting_file}
  	fi
  }
  
 
 Modified: stable/8/sys/kern/kern_acct.c
 ==============================================================================
 --- stable/8/sys/kern/kern_acct.c	Tue Feb 26 16:55:44 2013	(r247321)
 +++ stable/8/sys/kern/kern_acct.c	Tue Feb 26 16:55:59 2013	(r247322)
 @@ -122,7 +122,7 @@ static uint32_t	encode_timeval(struct ti
  static uint32_t	encode_long(long);
  static void	acctwatch(void);
  static void	acct_thread(void *);
 -static int	acct_disable(struct thread *);
 +static int	acct_disable(struct thread *, int);
  
  /*
   * Accounting vnode pointer, saved vnode pointer, and flags for each.
 @@ -196,7 +196,7 @@ int
  acct(struct thread *td, struct acct_args *uap)
  {
  	struct nameidata nd;
 -	int error, flags, vfslocked;
 +	int error, flags, vfslocked, replacing;
  
  	error = priv_check(td, PRIV_ACCT);
  	if (error)
 @@ -246,6 +246,13 @@ acct(struct thread *td, struct acct_args
  	sx_xlock(&acct_sx);
  
  	/*
 +	 * Don't log spurious disable/enable messages if we are
 +	 * switching from one accounting file to another due to log
 +	 * rotation.
 +	 */
 +	replacing = (acct_vp != NULL && uap->path != NULL);
 +
 +	/*
  	 * If accounting was previously enabled, kill the old space-watcher,
  	 * close the file, and (if no new file was specified, leave).  Reset
  	 * the suspended state regardless of whether accounting remains
 @@ -254,7 +261,7 @@ acct(struct thread *td, struct acct_args
  	acct_suspended = 0;
  	if (acct_vp != NULL) {
  		vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount);
 -		error = acct_disable(td);
 +		error = acct_disable(td, !replacing);
  		VFS_UNLOCK_GIANT(vfslocked);
  	}
  	if (uap->path == NULL) {
 @@ -299,7 +306,8 @@ acct(struct thread *td, struct acct_args
  	}
  	acct_configured = 1;
  	sx_xunlock(&acct_sx);
 -	log(LOG_NOTICE, "Accounting enabled\n");
 +	if (!replacing)
 +		log(LOG_NOTICE, "Accounting enabled\n");
  	return (error);
  }
  
 @@ -308,7 +316,7 @@ acct(struct thread *td, struct acct_args
   * our reference to the credential, and clearing the vnode's flags.
   */
  static int
 -acct_disable(struct thread *td)
 +acct_disable(struct thread *td, int logging)
  {
  	int error;
  
 @@ -319,7 +327,8 @@ acct_disable(struct thread *td)
  	acct_vp = NULL;
  	acct_cred = NULL;
  	acct_flags = 0;
 -	log(LOG_NOTICE, "Accounting disabled\n");
 +	if (logging)
 +		log(LOG_NOTICE, "Accounting disabled\n");
  	return (error);
  }
  
 @@ -574,7 +583,7 @@ acctwatch(void)
  	 */
  	vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount);
  	if (acct_vp->v_type == VBAD) {
 -		(void) acct_disable(NULL);
 +		(void) acct_disable(NULL, 1);
  		VFS_UNLOCK_GIANT(vfslocked);
  		acct_state |= ACCT_EXITREQ;
  		return;
 _______________________________________________
 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"
 
>Unformatted:
