Repository navigation
Read the NetBSD open file count from pstat -T - #3820
Conversation
getOpenFileDescriptors() read kern.nfiles, which NetBSD does not have, so it always returned 0. NetBSD exposes no sysctl for the count. pstat -T reads the kernel's nfiles counter through kvm, and is setgid kmem, so it works without root and prints the system-wide total on its first line: 1100/10000 files pstat -f is not an alternative: it counts the KERN_FILE2 records, which the kernel filters to the files an unprivileged caller may see (179 of the same 1100 on cfarm428). pstat is run by its absolute path, since /usr/sbin is not always on the PATH of an unprivileged user. Verified on cfarm428 (NetBSD 10.1 aarch64) in all three configurations: File Descriptors 1100/10000, previously 0/10000.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📜 Recent review details
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
FileSystem.getOpenFileDescriptors()on NetBSD readkern.nfiles. NetBSD doesn't have that sysctl, so the method always returned 0.Change
NetBSD has no sysctl for this count at all.
pstat -Treads the kernel'snfilescounter through kvm, andpstatis setgid kmem, so it works without root. Its first line is the system-wide total:This is the same counter FreeBSD exposes as
kern.openfilesand OpenBSD askern.nfiles.pstatis run by its absolute path (/usr/sbin/pstat), since/usr/sbinisn't always on an unprivileged user's PATH.SolarisSensorscalls/usr/sbin/prtpiclthe same way.pstat -fis not an alternative. Its header countsKERN_FILE2records, and the kernel filters those down to the files an unprivileged caller is allowed to see. On cfarm428 it reported 179 open files against the true 1100. Seefilemode()in pstat.c.Verification
cfarm428 (NetBSD 10.1 evbarm aarch64, non-root):
All three configurations agree: JNA without the native library, JNA with it, and FFM. The count matches
pstat -Trun by hand.A fixture test covers:
pstat's%3dformatpstat -fheader, which must not be read as the totalSummary by CodeRabbit
kern.nfilessystem setting is unavailable.