-
Notifications
You must be signed in to change notification settings - Fork 123
Fix process iterator when used with a custom root #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ca4166a
to
ca8cd6d
Compare
I removed the commit with the documentation change. -#![deny(broken_intra_doc_links)]
+#![deny(rustdoc::broken_intra_doc_links)] but it brokes the build, the commit has been removed from the PR. |
src/process/mod.rs
Outdated
@@ -1528,6 +1531,7 @@ pub fn all_processes_with_root(root: impl AsRef<Path>) -> ProcResult<ProcessesIt | |||
/// for more information. | |||
#[derive(Debug)] | |||
pub struct ProcessesIter { | |||
root: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be PathBuf
or OsString
, because a path on Linux can be any bytes, whereas a String is valid UTF-8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, PathBuf
is better, I changed it, thank you !
If you are ok with the last commit I will squash it into the "Fix process iterator with a custom root" one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I squashed it !
CI is broken because of the version in Cargo.toml, I don't think I can change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are multiple issues in CI atm, but not related to your changes
- rust 1.48 has an issue with the manifest format
- stable and nightly have an issue with sys::kernel::random::tests::test_poolsize. It seems related to a recent change in the kernel, see https://unix.stackexchange.com/questions/704737/kernel-5-10-119-caused-the-values-of-proc-sys-kernel-random-entropy-avail-and-p
However, I don't know if the change of failure to anyhow should be handled in this PR (I'm not the repo owner, though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As "failure" is used only in test and is deprecated, I thought it worst nothing to add it here.
If it is a problem I will of course remove it from the PR. The main issue is the real important thing to fix.
Thank you for your review !
38bf2b5
to
979fa73
Compare
I submitted a PR to fix CI #205 There's still some issue with a dependency, but it should be fixed soon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this fix @ludo-c ! The bug fix looks good to me in general, but I did leave two comments on things that need changing before merging.
Cargo.toml
Outdated
@@ -30,7 +30,7 @@ serde = { version = "1.0", features = ["derive"], optional = true } | |||
[dev-dependencies] | |||
criterion = "0.3" | |||
procinfo = "0.4.2" | |||
failure = "0.1" | |||
anyhow = "1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK with adding a new test for anyhow
, but I don't see a reason to remove the test for failure
. I would weakly prefer this to be in its own PR, though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this because failure
has been marked as deprecated : https://github.com/rust-lang-deprecated/failure
As it is not a big deal I didn't want to open a PR only for that.
I remove it from this PR.
src/process/mod.rs
Outdated
break Some(Ok(proc)); | ||
match Process::new_with_root(self.root.join(pid.to_string())) { | ||
Ok(proc) => break Some(Ok(proc)), | ||
Err(e) => break Some(Err(e)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documented behavior of the all_processes
function is that Process
objects that fail to be constructed won't be returned in the iterator. Your code here would modify that, and I don't think I want to do that right now.
If you have a use-case where you want to know about these failures, please let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was useful only to find why I didn't have all the processes I expected (in my case /proc
has less process than /proc-full
)
With this fix it is not needed anymore, I remove it.
src/sys/kernel/random.rs
Outdated
@@ -73,7 +73,7 @@ mod tests { | |||
// The kernel support section in the root lib.rs file says that we only aim to support >= 2.6 kernels, | |||
// so only test that case | |||
let poolsize = poolsize().unwrap(); | |||
assert!(poolsize == 4096) | |||
assert_eq!(poolsize, 4096) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will conflict with #205. That's OK, just FYI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remove it too, that was only to have the value in CI.
ac22f3d
to
934c46b
Compare
(Also, please rebase onto the last master branch) |
934c46b
to
0516f66
Compare
Thanks again for the fix! |
Hi @eminence . Thank you ! |
Sure, we can get a new release out in a few days |
Hello,
My context is a lxc container with a limited version of
/proc
containing only processes that are running in the container.The full proc mounted in another directory,
/proc-full
.When I call
all_processes_with_root
with the root/proc-full
, the iterator createsProcess
with the "default" constructor instead of the one withwith_root
: https://github.com/eminence/procfs/blob/master/src/process/mod.rs#L1541The creation of the Process fails silently as there is no check for that and
all_processes_with_root
returns successfully, but without processes.If I change that call with
Process::new_with_root
, it works.As Rust is quite new to me I'm not sure that it is a good solution, can you have a look at it please ?
Thank you very much !
PS: I left some few commits from my last PR:
failure
crate toanyhow
.failure
has been marked as deprecated : https://github.com/rust-lang-deprecated/failureloadavg_from_reader
cargo clippy
warningThe test
sys::kernel::random::tests::test_poolsize
fails but it seems that is was failing before these modifications too.