git: fcfa6bf40d99 - stable/13 - Add kqueue1() syscall

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Sun, 16 Apr 2023 11:10:27 UTC
The branch stable/13 has been updated by kib:

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

commit fcfa6bf40d99fa28ff4feb461a6e90e4d1643819
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-03-25 23:39:02 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-04-16 10:59:43 +0000

    Add kqueue1() syscall
    
    (cherry picked from commit 61194e9852e641d1533cd04a5679d6042ff975d3)
---
 sys/kern/kern_event.c    | 13 +++++++++++++
 sys/kern/syscalls.master |  5 +++++
 sys/sys/event.h          |  3 +++
 3 files changed, 21 insertions(+)

diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
index 90a725b6e0f0..29485f3a39db 100644
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -1058,6 +1058,19 @@ sys_kqueue(struct thread *td, struct kqueue_args *uap)
 	return (kern_kqueue(td, 0, NULL));
 }
 
+int
+sys_kqueue1(struct thread *td, struct kqueue1_args *uap)
+{
+	int flags;
+
+	if ((uap->flags & ~(KQUEUE_CLOEXEC)) != 0)
+		return (EINVAL);
+	flags = 0;
+	if ((uap->flags & KQUEUE_CLOEXEC) != 0)
+		flags |= O_CLOEXEC;
+	return (kern_kqueue(td, flags, NULL));
+}
+
 static void
 kqueue_init(struct kqueue *kq)
 {
diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master
index 5b46ee6c2839..7705cab0da77 100644
--- a/sys/kern/syscalls.master
+++ b/sys/kern/syscalls.master
@@ -3283,6 +3283,11 @@
 		    u_int flags,
 		);
 	}
+583	AUE_KQUEUE	STD|CAPENABLED {
+		int kqueue1(
+		    u_int flags
+		);
+	}
 
 ; Please copy any additions and changes to the following compatability tables:
 ; sys/compat/freebsd32/syscalls.master
diff --git a/sys/sys/event.h b/sys/sys/event.h
index b6704f4b4b50..1220ee5343e7 100644
--- a/sys/sys/event.h
+++ b/sys/sys/event.h
@@ -216,6 +216,9 @@ struct kevent32_freebsd11 {
 #define NOTE_NSECONDS		0x00000008	/* data is nanoseconds */
 #define	NOTE_ABSTIME		0x00000010	/* timeout is absolute */
 
+/* Flags for kqueue1(2) */
+#define	KQUEUE_CLOEXEC	0x00000001	/* close on exec */
+
 struct knote;
 SLIST_HEAD(klist, knote);
 struct kqueue;