On Mon, May 07, 2018 at 05:47:58PM +0200, Martin Pieuchot wrote:
> Instead of returning a `fp' that we won't look at, skip it in the
> iterator function. Non mature `fp' shouldn't be on the global list
> anyway, but that's for a later diff.
>
> ok?
OK bluhm@
> Index: kern/kern_descrip.c
> ===================================================================
> RCS file: /cvs/src/sys/kern/kern_descrip.c,v
> retrieving revision 1.156
> diff -u -p -r1.156 kern_descrip.c
> --- kern/kern_descrip.c 2 May 2018 02:24:56 -0000 1.156
> +++ kern/kern_descrip.c 7 May 2018 15:47:22 -0000
> @@ -190,7 +190,7 @@ fd_iterfile(struct file *fp, struct proc
> 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)
> + while (nfp != NULL && (nfp->f_count == 0 || !FILE_IS_USABLE(nfp)))
> nfp = LIST_NEXT(nfp, f_list);
> if (nfp != NULL)
> FREF(nfp);
> Index: kern/kern_sysctl.c
> ===================================================================
> RCS file: /cvs/src/sys/kern/kern_sysctl.c,v
> retrieving revision 1.333
> diff -u -p -r1.333 kern_sysctl.c
> --- kern/kern_sysctl.c 25 Apr 2018 10:29:16 -0000 1.333
> +++ kern/kern_sysctl.c 7 May 2018 15:41:02 -0000
> @@ -1320,9 +1320,7 @@ sysctl_file(int *name, u_int namelen, ch
> }
> 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)) {
> + if ((arg == 0 || fp->f_type == arg)) {
> int af, skip = 0;
> if (arg == DTYPE_SOCKET && fp->f_type == arg) {
> af = ((struct socket *)fp->f_data)->