Skip to content
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

Fix process iterator when used with a custom root #204

Merged
merged 2 commits into from
Sep 27, 2022

Conversation

ludo-c
Copy link
Contributor

@ludo-c ludo-c commented Sep 18, 2022

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 creates Process with the "default" constructor instead of the one with with_root: https://github.com/eminence/procfs/blob/master/src/process/mod.rs#L1541
The 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:

The test sys::kernel::random::tests::test_poolsize fails but it seems that is was failing before these modifications too.

@ludo-c ludo-c force-pushed the fix-process-iterator branch 2 times, most recently from ca4166a to ca8cd6d Compare September 18, 2022 15:13
@ludo-c
Copy link
Contributor Author

ludo-c commented Sep 18, 2022

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.

@@ -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,
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

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)

Copy link
Contributor Author

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 !

@ludo-c ludo-c force-pushed the fix-process-iterator branch 2 times, most recently from 38bf2b5 to 979fa73 Compare September 22, 2022 09:39
@tatref
Copy link
Contributor

tatref commented Sep 23, 2022

I submitted a PR to fix CI #205

There's still some issue with a dependency, but it should be fixed soon

Copy link
Owner

@eminence eminence left a 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"
Copy link
Owner

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

Copy link
Contributor Author

@ludo-c ludo-c Sep 24, 2022

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.

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)),
Copy link
Owner

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.

Copy link
Contributor Author

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.

@@ -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)
Copy link
Owner

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

Copy link
Contributor Author

@ludo-c ludo-c Sep 24, 2022

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.

src/lib.rs Outdated Show resolved Hide resolved
@ludo-c ludo-c force-pushed the fix-process-iterator branch 6 times, most recently from ac22f3d to 934c46b Compare September 24, 2022 19:10
@eminence
Copy link
Owner

(Also, please rebase onto the last master branch)

@eminence
Copy link
Owner

Thanks again for the fix!

@eminence eminence merged commit 56fe4c7 into eminence:master Sep 27, 2022
@ludo-c ludo-c deleted the fix-process-iterator branch September 27, 2022 05:57
@ludo-c
Copy link
Contributor Author

ludo-c commented Nov 29, 2022

Hi @eminence .
As there have been some fixes, would it be possible to bump a 0.15 version please ?

Thank you !

@eminence
Copy link
Owner

eminence commented Dec 1, 2022

Sure, we can get a new release out in a few days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants