From: visa Date: Sun, 20 Aug 2023 15:13:43 +0000 (+0000) Subject: Add kqueue1() system call X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=eaac6367f874bb2b24159a1fa5251562c1f97715;p=openbsd 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@ --- 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 @@ -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); @@ -941,6 +944,24 @@ out: return (error); } +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) { 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 @@ -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 diff --git a/sys/sys/event.h b/sys/sys/event.h index cc5a69e6a8b..6d052d23b4b 100644 --- a/sys/sys/event.h +++ b/sys/sys/event.h @@ -1,4 +1,4 @@ -/* $OpenBSD: event.h,v 1.70 2023/08/13 08:29:28 visa Exp $ */ +/* $OpenBSD: event.h,v 1.71 2023/08/20 15:13:43 visa Exp $ */ /*- * Copyright (c) 1999,2000,2001 Jonathan Lemon @@ -369,6 +369,7 @@ struct timespec; __BEGIN_DECLS int kqueue(void); +int kqueue1(int flags); int kevent(int kq, const struct kevent *changelist, int nchanges, struct kevent *eventlist, int nevents, const struct timespec *timeout);