RFC: Change Process to use directory fd#127
Closed
Conversation
All data accessors now use openat and readlinkat when reading procfs entries, to prevent PID reuse.
Owner
|
I'm sorry I haven't gotten a chance to look at this yet. I'm going to try to take a look within a week. |
Author
|
No rush. 😃 This is still a very rough draft. |
Contributor
|
This patch was incorporated into #171, which is now merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All data accessors now use openat and readlinkat when reading procfs entries, to protect against PID reuse. Also, iterators are now used instead of
Vecin any place where a file descriptor is held open. This is an API break, see examples/netstat.rs and examples/process_hierarchy.rs for the most obvious effects on library consumers. I also removed thestatfield as suggested in #69. I haven't made any documentation changes yet, but I can if the approach here looks good. I used a few functions from thenixlibrary for convenience, but those are simple enough that they can potentially be re-implemented here if the dependency isn't desired.A downside of this is that simple cases using
statare now slower. If all you need during iteration is the information from/proc/<pid>/stat, that now takes two additional syscalls to open and close the directory fd. We could speed that up by adding another function to iterate over the pids, and then adding more constructors to the relevant structures (Stat,MemoryMap,Status...) that directly read from/proc/<pid>/<name>.It would have to be noted in the documentation that it's only safe to use one of those constructors while iterating, because of PID recycling; for cases where two or more files need to be read from within an individual/proc/<pid>directory, the fd-holding iterator fromall_processes()must be used.On second thought, a better way to handle those types of iterations would be to put the pid in a separate
Pidstructure that then gets consumed by a move into a newStatconstructor. That way it can't accidentally be used twice.If this all sounds good, I'd like to use this as a base to add pidfd support as well, to support race-free waiting and signaling on procfs processes.
Fixes #125