diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/kern_descrip.c | 24 | ||||
-rw-r--r-- | sys/kern/kern_sysctl.c | 23 | ||||
-rw-r--r-- | sys/sys/file.h | 3 | ||||
-rw-r--r-- | sys/sys/filedesc.h | 3 |
4 files changed, 31 insertions, 22 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; diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index c98f9d53d72..8299f50be6a 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.332 2018/02/19 08:59:52 mpi Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.333 2018/04/25 10:29:16 mpi Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -1250,7 +1250,7 @@ sysctl_file(int *name, u_int namelen, char *where, size_t *sizep, { struct kinfo_file *kf; struct filedesc *fdp; - struct file *fp, *nfp; + struct file *fp; struct process *pr; size_t buflen, elem_size, elem_count, outsize; char *dp = where; @@ -1318,14 +1318,8 @@ sysctl_file(int *name, u_int namelen, char *where, size_t *sizep, #endif NET_UNLOCK(); } - fp = LIST_FIRST(&filehead); - /* don't FREF when f_count == 0 to avoid race in fdrop() */ - while (fp != NULL && fp->f_count == 0) - fp = LIST_NEXT(fp, f_list); - if (fp == NULL) - break; - FREF(fp); - do { + fp = NULL; + while ((fp = fd_iterfile(fp, p)) != NULL) { if (fp->f_count > 1 && /* 0, +1 for our FREF() */ FILE_IS_USABLE(fp) && (arg == 0 || fp->f_type == arg)) { @@ -1339,14 +1333,7 @@ sysctl_file(int *name, u_int namelen, char *where, size_t *sizep, if (!skip) FILLIT(fp, NULL, 0, NULL, NULL); } - nfp = LIST_NEXT(fp, f_list); - while (nfp != NULL && nfp->f_count == 0) - nfp = LIST_NEXT(nfp, f_list); - if (nfp != NULL) - FREF(nfp); - FRELE(fp, p); - fp = nfp; - } while (fp != NULL); + } break; case KERN_FILE_BYPID: /* A arg of -1 indicates all processes */ diff --git a/sys/sys/file.h b/sys/sys/file.h index ef27cd5cc15..62985415f8f 100644 --- a/sys/sys/file.h +++ b/sys/sys/file.h @@ -1,4 +1,4 @@ -/* $OpenBSD: file.h,v 1.40 2018/02/10 05:24:23 deraadt Exp $ */ +/* $OpenBSD: file.h,v 1.41 2018/04/25 10:29:16 mpi Exp $ */ /* $NetBSD: file.h,v 1.11 1995/03/26 20:24:13 jtc Exp $ */ /* @@ -106,7 +106,6 @@ struct file { int fdrop(struct file *, struct proc *); LIST_HEAD(filelist, file); -extern struct filelist filehead; /* head of list of open files */ extern int maxfiles; /* kernel limit on number of open files */ extern int numfiles; /* actual number of open files */ extern struct fileops vnops; /* vnode operations for files */ diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index 8fd0dc38efc..39486fafd60 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: filedesc.h,v 1.34 2017/02/11 19:51:06 guenther Exp $ */ +/* $OpenBSD: filedesc.h,v 1.35 2018/04/25 10:29:17 mpi Exp $ */ /* $NetBSD: filedesc.h,v 1.14 1996/04/09 20:55:28 cgd Exp $ */ /* @@ -133,6 +133,7 @@ void fdfree(struct proc *p); int fdrelease(struct proc *p, int); void fdremove(struct filedesc *, int); void fdcloseexec(struct proc *); +struct file *fd_iterfile(struct file *, struct proc *); struct file *fd_getfile(struct filedesc *, int); struct file *fd_getfile_mode(struct filedesc *, int, int); |