kern/167321: Implement sysctl to control kernel accounting log messages (e.g. acct(2))

Jeremy Chadwick jdc at koitsu.org
Thu Apr 26 12:01:14 UTC 2012


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 at 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");
 		}
 	}
 }


More information about the freebsd-bugs mailing list