[Bug 194985] getdtablecount new syscall from openbsd

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Thu Nov 13 14:14:29 UTC 2014


--- Comment #4 from Mateusz Guzik <mjg at FreeBSD.org> ---
+    p = td->td_proc;
+    PROC_LOCK(p);
+    fdp = p->p_fd;
+    td->td_retval[0] = fdp->fd_openfd;
+    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.

More information about the freebsd-bugs mailing list