https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=194985

--- Comment #4 from Mateusz Guzik <m...@freebsd.org> ---
+    p = td->td_proc;
+    PROC_LOCK(p);
+    fdp = p->p_fd;
+    FILEDESC_SLOCK(fdp);
+    td->td_retval[0] = fdp->fd_openfd;
+    FILEDESC_SUNLOCK(fdp);
+    PROC_UNLOCK(p);

proc lock has no useful purpose here. p_fd can change in some cases during
fork, but then the process is singlethreaded.

proc lock is a mutex with bound sleep, while filedesc lock has unbound sleep.
As such, they cannot be taken in this order anyway.

As a side note, they happen to be taken in the opposide order, so this code
gives 2 different opportunities for deadlocks.

The kernel would tell you that if you enabled WITNESS and INVARIANTS.

Lastly, I'm not a fan of counting fds if it can be avoided. As mentioned in my
previous comment, the kernel maintains a bitmap of open descriptors. I would
suspect counting set bits (= open descriptors) would be fast enough for real
life cases.

-- 
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
freebsd-bugs@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "freebsd-bugs-unsubscr...@freebsd.org"

Reply via email to