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

treewide: Modernize nix::sys::ptrace usage #2

Merged
merged 1 commit into from Oct 15, 2020
Merged

treewide: Modernize nix::sys::ptrace usage #2

merged 1 commit into from Oct 15, 2020

Conversation

woodruffw
Copy link
Contributor

@woodruffw woodruffw commented Oct 7, 2020

Hi there! Thanks for making this crate.

I was looking at using it on a research project that I'm working on, and I noticed that it was no longer compiling correctly. I've taken the liberty of bringing it up to date with the latest nix release and giving it a pass through cargo fmt. I confirmed locally that the tests still pass.

The external-facing API hasn't changed at all.

Please let me know if there's anything else I can do!

let child = unsafe {
self.pre_exec(|| {
// Opt-in to ptrace.
match ptrace::traceme() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N.B.: ptrace::traceme() is the replacement for ptrace(PTRACE_TRACEME, ...). It no longer returns an io::Result (or something directly convertible to an io::Result), so I unrolled it a bit here: system errors (i.e., errno results) get propagated via from_raw_os_error, while everything else acts like the waitpid below and becomes an io::ErrorKind::Other.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could write this more concisely as ptrace::traceme().map_err(|e| { // the err case you have below }) I'm not hung up on it enough to even use the review suggestion tool to rewrite it for you, so you can fix it in a followup if you're motivated or it can be what it is. :)

ptrace(PTRACE_TRACEME, 0, ptr::null_mut(), ptr::null_mut())?;
Ok(())
}).spawn()?;
let child = unsafe {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N.B.: This unsafe is required because of a deprecation: before_exec is now deprecated, and its replacement, pre_exec, is correctly marked as unsafe.

@woodruffw
Copy link
Contributor Author

ping @luser -- any chance of this getting reviewed? Apologies if you're busy or don't have the bandwidth for it right now 🙂

Copy link
Owner

@luser luser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad you've found this crate useful, thanks for the fixes! Would you like me to push a new release to crates.io or are you just using it as a git dependency anyway? I figure I should release a new version with this, but if you are actively using it and think you might find other issues that need fixing it can wait a bit.

FWIW, I mostly wrote this crate so I could write this little tool: https://github.com/luser/tracetree

@@ -6,11 +6,19 @@ use std::process::Command;
#[test]
fn readme_test() {
let rustdoc = Path::new("rustdoc").with_extension(EXE_EXTENSION);
let readme = Path::new(file!()).parent().unwrap().parent().unwrap().join("README.md");
let readme = Path::new(file!())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, we should remove this whole file and replace it with the doc-comment crate:
https://crates.io/crates/doc-comment (you don't have to do that now, but I just noted this on a PR on another crate of mine so it's in my head).

let child = unsafe {
self.pre_exec(|| {
// Opt-in to ptrace.
match ptrace::traceme() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could write this more concisely as ptrace::traceme().map_err(|e| { // the err case you have below }) I'm not hung up on it enough to even use the review suggestion tool to rewrite it for you, so you can fix it in a followup if you're motivated or it can be what it is. :)

@luser luser merged commit e136193 into luser:master Oct 15, 2020
@woodruffw
Copy link
Contributor Author

Thanks for the merge!

I'm glad you've found this crate useful, thanks for the fixes! Would you like me to push a new release to crates.io or are you just using it as a git dependency anyway? I figure I should release a new version with this, but if you are actively using it and think you might find other issues that need fixing it can wait a bit.

I'm currently using it as a git dependency, but I wouldn't mind a release! I'm happy to do some of the follow-up work that you noted before you cut it, though 🙂

@woodruffw woodruffw deleted the ww/modernize branch October 15, 2020 22:12
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.

None yet

2 participants