Subject: accounting spuriously disabled (#381)
Index:	sys/kern_acct.c 2.11BSD

Description:
	Accounting would be spuriously (and without notice) be turned off.

Repeat-By:
	Notice the "accounting resumed" message that comes out even though
	no "accounting disabled" message was seen.

Fix:
	Accounting is disabled by the kernel if the free space falls below 
	4% on the partition which holds the accounting file.  At
	that time a warning message "accounting disabled" is issued.
	
	The only other time the kernel will disable accounting is if an error
	is encountered when writing an accounting record to the file.  The
	error message was ifdef'd out because it kept appearing for no apparent
	reason.  This reason has been discovered and the _correct_ fix made.

	There was a path thru rdwri() which would return the current contents
	of u.u_error.  The u.u_error variable should have been cleared in
	acct() before calling rdwri() because the error location has no 
	meaning when the kernel initiates I/O (especially for an exited 
	process).

	Several of the error messages have been trimmed to save D-space.  It
	should be obvious that "Acct resume" means the same thing as the
	longer "Accounting resumed" ;)

	To install this update, cut where indicated saving to a file (/tmp/381).

	Then:

		patch -p0 < /tmp/381

		cd /sys/YOUR_KERNEL
		make
		make install

	If you keep a current GENERIC kernel present (in /genunix for example)
	then:

		cd /sys/GENERIC
		make
		mv unix /genunix

	As always this and previous updates to 2.11BSD are available via
	anonymous FTP to either FTP.IIPO.GTEGSC.COM or MOE.2BSD.COM in the
	directory /pub/2.11BSD.

------------------------------cut here-------------------------
*** /usr/src/sys/sys/kern_acct.c.old	Sun Feb 16 16:53:50 1997
--- /usr/src/sys/sys/kern_acct.c	Sat Aug  2 21:51:39 1997
***************
*** 3,9 ****
   * All rights reserved.  The Berkeley software License Agreement
   * specifies the terms and conditions for redistribution.
   *
!  *	@(#)kern_acct.c	2.5 (2.11BSD) 1997/2/16
   *
   * This module is a real mishmash of FreeBSD, 4.3BSD, and home brewed code.
   */
--- 3,9 ----
   * All rights reserved.  The Berkeley software License Agreement
   * specifies the terms and conditions for redistribution.
   *
!  *	@(#)kern_acct.c	2.6 (2.11BSD) 1997/8/1
   *
   * This module is a real mishmash of FreeBSD, 4.3BSD, and home brewed code.
   */
***************
*** 107,113 ****
  		if	(chkfreesp(fs, acctresume) > 0)
  			{
  			acctdisabled = 0;
! 			log(LOG_NOTICE, "Accounting resumed\n");
  			}
  		}
  	else
--- 107,113 ----
  		if	(chkfreesp(fs, acctresume) > 0)
  			{
  			acctdisabled = 0;
! 			log(LOG_NOTICE, "Acct resume\n");
  			}
  		}
  	else
***************
*** 114,120 ****
  		{
  		if	(chkfreesp(fs, acctsuspend) <= 0)
  			{
! 			log(LOG_NOTICE, "Accounting suspended\n");
  			acctdisabled = 1;
  			}
  		}
--- 114,120 ----
  		{
  		if	(chkfreesp(fs, acctsuspend) <= 0)
  			{
! 			log(LOG_NOTICE, "Acct suspend\n");
  			acctdisabled = 1;
  			}
  		}
***************
*** 128,133 ****
--- 128,134 ----
  	struct	acct acctbuf;
  	register struct inode *ip;
  	register struct acct *ap = &acctbuf;
+ 	int	resid;
  
  	acctwatch();
  
***************
*** 156,176 ****
  	else
  		ap->ac_tty = NODEV;
  	ap->ac_flag = u.u_acflag;
  	u.u_error = rdwri(UIO_WRITE, ip, ap, sizeof(acctbuf), ip->i_size,
! 			UIO_SYSSPACE, IO_UNIT|IO_APPEND, (int *)0);
  	if	(u.u_error)
  		{
  /*
   * The only time this should happen is when a physical error occurs on the
!  *  disk drive or the space is exhausted.  The diagnostic message is not
!  * enabled by default to save space and also because there's apparently a
!  * race condition during 'reboot'/'fastboot' that would elicit the (harmless
!  * I hope) warning message.
  */
  		acctdisabled = 1;
- #ifdef	DIAGNOSTIC
- 		log(LOG_NOTICE, "acct rdwri=%d\n", u.u_error);
- #endif
  		}
  	iunlock(ip);
  	}
--- 157,175 ----
  	else
  		ap->ac_tty = NODEV;
  	ap->ac_flag = u.u_acflag;
+ 	u.u_error = 0;			/* XXX */
  	u.u_error = rdwri(UIO_WRITE, ip, ap, sizeof(acctbuf), ip->i_size,
! 			UIO_SYSSPACE, IO_UNIT|IO_APPEND, (int *)&resid);
  	if	(u.u_error)
  		{
  /*
   * The only time this should happen is when a physical error occurs on the
!  * disk drive.  The freespace check has been made earlier so an error at this
!  * time is I/O related.  The message is terse to save space (D-space doesn't
!  * grow on trees you know ;)).
  */
+ 		log(LOG_NOTICE,"acct %d %d\n", u.u_error, resid);
  		acctdisabled = 1;
  		}
  	iunlock(ip);
  	}
*** /VERSION.old	Sun Jul 20 11:16:46 1997
--- /VERSION	Sat Aug  2 21:26:20 1997
***************
*** 1,5 ****
! Current Patch Level: 380
! Date: July 20, 1997
  
  2.11 BSD
  ============
--- 1,5 ----
! Current Patch Level: 381
! Date: August 2, 1997
  
  2.11 BSD
  ============
