summaryrefslogtreecommitdiff
path: root/sys/kern/kern_descrip.c
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2018-04-25 10:29:18 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2018-04-25 10:29:18 +0000
commitec7e43aefcda873a97c0c50cf0dbbff5d3b71083 (patch)
treeb4d222f87f9a55dbd395797d855fe7f9969d5dba /sys/kern/kern_descrip.c
parent0098a9a988ed297535e7630d0f7453b2791a5a6b (diff)
Introduce fd_iterfile() a new helper function to iterate over `filehead'.
This turns `filehead' into a local variable, that will make it easier to protect it. ok visa@
Diffstat (limited to 'sys/kern/kern_descrip.c')
-rw-r--r--sys/kern/kern_descrip.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 863ee824c19..100d86f4c49 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_descrip.c,v 1.151 2018/04/18 09:59:09 mpi Exp $ */
+/* $OpenBSD: kern_descrip.c,v 1.152 2018/04/25 10:29:16 mpi Exp $ */
/* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */
/*
@@ -180,6 +180,28 @@ fd_unused(struct filedesc *fdp, int fd)
}
struct file *
+fd_iterfile(struct file *fp, struct proc *p)
+{
+ struct file *nfp;
+
+ if (fp == NULL)
+ nfp = LIST_FIRST(&filehead);
+ else
+ nfp = LIST_NEXT(fp, f_list);
+
+ /* don't FREF when f_count == 0 to avoid race in fdrop() */
+ while (nfp != NULL && nfp->f_count == 0)
+ nfp = LIST_NEXT(nfp, f_list);
+ if (nfp != NULL)
+ FREF(nfp);
+
+ if (fp != NULL)
+ FRELE(fp, p);
+
+ return nfp;
+}
+
+struct file *
fd_getfile(struct filedesc *fdp, int fd)
{
struct file *fp;