diff options
Diffstat (limited to 'sys/kern/kern_descrip.c')
-rw-r--r-- | sys/kern/kern_descrip.c | 24 |
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; |