summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorVisa Hankala <visa@cvs.openbsd.org>2023-08-20 15:13:44 +0000
committerVisa Hankala <visa@cvs.openbsd.org>2023-08-20 15:13:44 +0000
commit2edca112cd156d9eb76918d23dd7b752b504aeac (patch)
tree0c5990379df06e6d412cffa4712661089a5c6740 /sys/kern
parent760ee81d8908250cb71452aecbbf761cf41781a9 (diff)
Add kqueue1() system call
kqueue1() takes the flags argument. This lets the kqueue file descriptor be opened with O_CLOEXEC. Adapted from NetBSD. OK guenther@
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_event.c31
-rw-r--r--sys/kern/kern_pledge.c3
-rw-r--r--sys/kern/syscalls.master4
3 files changed, 30 insertions, 8 deletions
diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
index a2933832b2c..7e3ae6eae3a 100644
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_event.c,v 1.197 2023/08/13 08:29:28 visa Exp $ */
+/* $OpenBSD: kern_event.c,v 1.198 2023/08/20 15:13:43 visa Exp $ */
/*-
* Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
@@ -60,6 +60,7 @@
#define KLIST_ASSERT_LOCKED(kl) ((void)(kl))
#endif
+int dokqueue(struct proc *, int, register_t *);
struct kqueue *kqueue_alloc(struct filedesc *);
void kqueue_terminate(struct proc *p, struct kqueue *);
void KQREF(struct kqueue *);
@@ -912,12 +913,14 @@ kqueue_alloc(struct filedesc *fdp)
}
int
-sys_kqueue(struct proc *p, void *v, register_t *retval)
+dokqueue(struct proc *p, int flags, register_t *retval)
{
struct filedesc *fdp = p->p_fd;
struct kqueue *kq;
struct file *fp;
- int fd, error;
+ int cloexec, error, fd;
+
+ cloexec = (flags & O_CLOEXEC) ? UF_EXCLOSE : 0;
kq = kqueue_alloc(fdp);
@@ -925,14 +928,14 @@ sys_kqueue(struct proc *p, void *v, register_t *retval)
error = falloc(p, &fp, &fd);
if (error)
goto out;
- fp->f_flag = FREAD | FWRITE;
+ fp->f_flag = FREAD | FWRITE | (flags & FNONBLOCK);
fp->f_type = DTYPE_KQUEUE;
fp->f_ops = &kqueueops;
fp->f_data = kq;
*retval = fd;
LIST_INSERT_HEAD(&fdp->fd_kqlist, kq, kq_next);
kq = NULL;
- fdinsert(fdp, fd, 0, fp);
+ fdinsert(fdp, fd, cloexec, fp);
FRELE(fp, p);
out:
fdpunlock(fdp);
@@ -942,6 +945,24 @@ out:
}
int
+sys_kqueue(struct proc *p, void *v, register_t *retval)
+{
+ return (dokqueue(p, 0, retval));
+}
+
+int
+sys_kqueue1(struct proc *p, void *v, register_t *retval)
+{
+ struct sys_kqueue1_args /* {
+ syscallarg(int) flags;
+ } */ *uap = v;
+
+ if (SCARG(uap, flags) & ~(O_CLOEXEC | FNONBLOCK))
+ return (EINVAL);
+ return (dokqueue(p, SCARG(uap, flags), retval));
+}
+
+int
sys_kevent(struct proc *p, void *v, register_t *retval)
{
struct kqueue_scan_state scan;
diff --git a/sys/kern/kern_pledge.c b/sys/kern/kern_pledge.c
index de98202776c..8dcf97b7a33 100644
--- a/sys/kern/kern_pledge.c
+++ b/sys/kern/kern_pledge.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_pledge.c,v 1.306 2023/06/02 17:44:29 cheloha Exp $ */
+/* $OpenBSD: kern_pledge.c,v 1.307 2023/08/20 15:13:43 visa Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
@@ -209,6 +209,7 @@ const uint64_t pledge_syscalls[SYS_MAXSYSCALL] = {
[SYS_ppoll] = PLEDGE_STDIO,
[SYS_kevent] = PLEDGE_STDIO,
[SYS_kqueue] = PLEDGE_STDIO,
+ [SYS_kqueue1] = PLEDGE_STDIO,
[SYS_select] = PLEDGE_STDIO,
[SYS_pselect] = PLEDGE_STDIO,
diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master
index d6278aeb703..2ed318508f0 100644
--- a/sys/kern/syscalls.master
+++ b/sys/kern/syscalls.master
@@ -1,4 +1,4 @@
-; $OpenBSD: syscalls.master,v 1.249 2023/07/24 19:32:23 miod Exp $
+; $OpenBSD: syscalls.master,v 1.250 2023/08/20 15:13:43 visa Exp $
; $NetBSD: syscalls.master,v 1.32 1996/04/23 10:24:21 mycroft Exp $
; @(#)syscalls.master 8.2 (Berkeley) 1/13/94
@@ -462,7 +462,7 @@
267 OBSOL pad_preadv
268 OBSOL pad_pwritev
269 STD NOLOCK { int sys_kqueue(void); }
-270 OBSOL t32_kevent
+270 STD NOLOCK { int sys_kqueue1(int flags); }
271 STD { int sys_mlockall(int flags); }
272 STD { int sys_munlockall(void); }
273 UNIMPL sys_getpeereid