git: d7c0ab90cde1 - main - acct(2): add kern_acct

From: Brooks Davis <brooks_at_FreeBSD.org>
Date: Sat, 07 Nov 2026 12:11:01 UTC
The branch main has been updated by brooks:

URL: https://cgit.FreeBSD.org/src/commit/?id=d7c0ab90cde19e2184f2d76d0fe43e85c74785d4

commit d7c0ab90cde19e2184f2d76d0fe43e85c74785d4
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2026-11-07 12:10:45 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2026-11-07 12:10:45 +0000

    acct(2): add kern_acct
    
    Effort:         CHERI upstreaming
    Sponsored by:   Innovate UK
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/2284
---
 sys/kern/kern_acct.c  | 15 +++++++++++----
 sys/sys/syscallsubr.h |  1 +
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c
index 4aa0032b7290..6bf7e333358c 100644
--- a/sys/kern/kern_acct.c
+++ b/sys/kern/kern_acct.c
@@ -82,6 +82,7 @@
 #include <sys/priv.h>
 #include <sys/proc.h>
 #include <sys/resourcevar.h>
+#include <sys/syscallsubr.h>
 #include <sys/sched.h>
 #include <sys/sx.h>
 #include <sys/sysctl.h>
@@ -197,6 +198,12 @@ SYSCTL_INT(_kern, OID_AUTO, acct_suspended, CTLFLAG_RD, &acct_suspended, 0,
  */
 int
 sys_acct(struct thread *td, struct acct_args *uap)
+{
+	return (kern_acct(td, uap->path));
+}
+
+int
+kern_acct(struct thread *td, const char *path)
 {
 	struct nameidata nd;
 	int error, flags, replacing;
@@ -209,9 +216,9 @@ sys_acct(struct thread *td, struct acct_args *uap)
 	 * If accounting is to be started to a file, open that file for
 	 * appending and make sure it's a 'normal'.
 	 */
-	if (uap->path != NULL) {
+	if (path != NULL) {
 		NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, UIO_USERSPACE,
-		    uap->path);
+		    path);
 		flags = FWRITE | O_APPEND;
 		error = vn_open(&nd, &flags, 0, NULL);
 		if (error)
@@ -249,7 +256,7 @@ sys_acct(struct thread *td, struct acct_args *uap)
 	 * switching from one accounting file to another due to log
 	 * rotation.
 	 */
-	replacing = (acct_vp != NULL && uap->path != NULL);
+	replacing = (acct_vp != NULL && path != NULL);
 
 	/*
 	 * If accounting was previously enabled, kill the old space-watcher,
@@ -260,7 +267,7 @@ sys_acct(struct thread *td, struct acct_args *uap)
 	acct_suspended = 0;
 	if (acct_vp != NULL)
 		error = acct_disable(td, !replacing);
-	if (uap->path == NULL) {
+	if (path == NULL) {
 		if (acct_state & ACCT_RUNNING) {
 			acct_state |= ACCT_EXITREQ;
 			wakeup(&acct_state);
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index 1abd99438bce..c4e842d64893 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -121,6 +121,7 @@ int	kern_accept4(struct thread *td, int s, struct sockaddr *sa,
 	    int flags, struct file **fp);
 int	kern_accessat(struct thread *td, int fd, const char *path,
 	    enum uio_seg pathseg, int flags, int mode);
+int	kern_acct(struct thread *td, const char *path);
 int	kern_adjtime(struct thread *td, struct timeval *delta,
 	    struct timeval *olddelta);
 int	kern_audit(struct thread *td, const void *record, u_int length);