Summary: | Fix broken KERN_PROC_FILEDESC sysctl | ||||||||
---|---|---|---|---|---|---|---|---|---|
Product: | Base System | Reporter: | Niall Douglas <s_bugzilla> | ||||||
Component: | kern | Assignee: | freebsd-bugs (Nobody) <bugs> | ||||||
Status: | Closed FIXED | ||||||||
Severity: | Affects Many People | CC: | crest, emaste, jilles | ||||||
Priority: | --- | ||||||||
Version: | CURRENT | ||||||||
Hardware: | Any | ||||||||
OS: | Any | ||||||||
See Also: |
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=197778 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=198570 |
||||||||
Attachments: |
|
Description
Niall Douglas
2015-02-16 00:50:54 UTC
Created attachment 153164 [details]
test case
Created attachment 153165 [details]
test case output
It turns out that I It turns out that I was wrong about there being no method of retrieving a canonical path for an open file descriptor on FreeBSD. There in fact is, and it is called KERN_PROC_FILEDESC. Unfortunately, KERN_PROC_FILEDESC is broken for regular files, but not directories where it works perfectly - even tracking renames and deletions with ease. The attached test case and its output shows the broken behaviour: 1. Files opened with O_CREAT never get a path. Creating the file, closing it and opening it again gets the file descriptor its path. 2. As soon as the process does its first rename() all the paths for all the regular file descriptors get reset to null, but not directory file descriptors. 3. Directory file descriptors work correctly. This was tested on FreeBSD 10.1 with ZFS on root. Other filing systems may vary. Niall As it is now, KERN_PROC_FILEDESC is designed for debugging only. The namecache is best-effort. See for example SVN r275897, which states that newly created files are deliberately not entered into the namecache (as part of a change to enter core dump filenames into the namecache). A second problem is that KERN_PROC_FILEDESC processes all file descriptors at once and may therefore be slow. I think directory file descriptors always know their names because directories have a single "..", all the way up to the root. (In reply to Jilles Tjoelker from comment #5) I appreciate the explanation. What I'll do is open a new feature request, this time to add a F_GETPATH implementation. Thanks. Niall Superseded by #198570, so closing. |