git: 304d02fc2e43 - stable/15 - kern/kern_fork.c: define the exterror category for fork

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Sun, 01 Feb 2026 21:40:49 UTC
The branch stable/15 has been updated by kib:

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

commit 304d02fc2e43ed8ae1661a83641f92882741ff6c
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-01-08 00:31:22 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-02-01 21:38:48 +0000

    kern/kern_fork.c: define the exterror category for fork
    
    (cherry picked from commit 7211cd2cce746972af2d60d4b5bf0c087f016731)
---
 sys/kern/kern_fork.c | 35 ++++++++++++++++++-----------------
 sys/sys/exterr_cat.h |  1 +
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 0a5f6d20dad1..d5f446ff59b0 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -37,10 +37,12 @@
 #include "opt_ktrace.h"
 #include "opt_kstack_pages.h"
 
+#define EXTERR_CATEGORY	EXTERR_CAT_FORK
 #include <sys/systm.h>
 #include <sys/acct.h>
 #include <sys/bitstring.h>
 #include <sys/eventhandler.h>
+#include <sys/exterrvar.h>
 #include <sys/fcntl.h>
 #include <sys/filedesc.h>
 #include <sys/jail.h>
@@ -164,10 +166,11 @@ sys_rfork(struct thread *td, struct rfork_args *uap)
 
 	/* Don't allow kernel-only flags. */
 	if ((uap->flags & RFKERNELONLY) != 0)
-		return (EINVAL);
+		return (EXTERROR(EINVAL, "Kernel-only flags %#jx", uap->flags));
 	/* RFSPAWN must not appear with others */
 	if ((uap->flags & RFSPAWN) != 0 && uap->flags != RFSPAWN)
-		return (EINVAL);
+		return (EXTERROR(EINVAL, "RFSPAWN must be the only flag %#jx",
+		    uap->flags));
 
 	AUDIT_ARG_FFLAGS(uap->flags);
 	bzero(&fr, sizeof(fr));
@@ -867,34 +870,32 @@ fork1(struct thread *td, struct fork_req *fr)
 	else
 		MPASS(fr->fr_procp == NULL);
 
-	/* Check for the undefined or unimplemented flags. */
 	if ((flags & ~(RFFLAGS | RFTSIGFLAGS(RFTSIGMASK))) != 0)
-		return (EINVAL);
+		return (EXTERROR(EINVAL,
+		    "Undef or unimplemented flags %#jx", flags));
 
-	/* Signal value requires RFTSIGZMB. */
 	if ((flags & RFTSIGFLAGS(RFTSIGMASK)) != 0 && (flags & RFTSIGZMB) == 0)
-		return (EINVAL);
+		return (EXTERROR(EINVAL,
+		    "Signal value requires RFTSIGZMB", flags));
 
-	/* Can't copy and clear. */
-	if ((flags & (RFFDG|RFCFDG)) == (RFFDG|RFCFDG))
-		return (EINVAL);
+	if ((flags & (RFFDG | RFCFDG)) == (RFFDG | RFCFDG))
+		return (EXTERROR(EINVAL, "Can not copy and clear"));
 
-	/* Check the validity of the signal number. */
 	if ((flags & RFTSIGZMB) != 0 && (u_int)RFTSIGNUM(flags) > _SIG_MAXSIG)
-		return (EINVAL);
+		return (EXTERROR(EINVAL, "Invalid signal", RFTSIGNUM(flags)));
 
 	if ((flags & RFPROCDESC) != 0) {
-		/* Can't not create a process yet get a process descriptor. */
 		if ((flags & RFPROC) == 0)
-			return (EINVAL);
+			return (EXTERROR(EINVAL,
+	    "Can not not create a process yet get a process descriptor"));
 
-		/* Must provide a place to put a procdesc if creating one. */
 		if (fr->fr_pd_fd == NULL)
-			return (EINVAL);
+			return (EXTERROR(EINVAL,
+		    "Must provide a place to put a procdesc if creating one"));
 
-		/* Check if we are using supported flags. */
 		if ((fr->fr_pd_flags & ~PD_ALLOWED_AT_FORK) != 0)
-			return (EINVAL);
+			return (EXTERROR(EINVAL,
+			    "Invallid pdflags at fork %#jx", fr->fr_pd_flags));
 	}
 
 	p1 = td->td_proc;
diff --git a/sys/sys/exterr_cat.h b/sys/sys/exterr_cat.h
index 24f07539fe35..daf0419754b7 100644
--- a/sys/sys/exterr_cat.h
+++ b/sys/sys/exterr_cat.h
@@ -37,6 +37,7 @@
 #define	EXTERR_CAT_GEOM		12
 #define	EXTERR_CAT_FUSE_VFS	13
 #define	EXTERR_CAT_FUSE_DEVICE	14
+#define	EXTERR_CAT_FORK		15
 
 #endif