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

wait: Support ptrace events for Linux #438

Merged
merged 3 commits into from
Feb 14, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/sys/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ pub enum WaitStatus {
Exited(pid_t, i8),
Signaled(pid_t, Signal, bool),
Stopped(pid_t, Signal),
#[cfg(any(target_os = "linux", target_os = "android"))]
PtraceEvent(pid_t, Signal, c_int),
Continued(pid_t),
StillAlive
}
Expand All @@ -52,6 +54,7 @@ pub enum WaitStatus {
target_os = "android"))]
mod status {
use sys::signal::Signal;
use libc::c_int;

pub fn exited(status: i32) -> bool {
(status & 0x7F) == 0
Expand Down Expand Up @@ -81,6 +84,10 @@ mod status {
Signal::from_c_int((status & 0xFF00) >> 8).unwrap()
}

pub fn stop_additional(status: i32) -> c_int {
(status >> 16) as c_int
}

pub fn continued(status: i32) -> bool {
status == 0xFFFF
}
Expand Down Expand Up @@ -184,6 +191,12 @@ fn decode(pid : pid_t, status: i32) -> WaitStatus {
} else if status::signaled(status) {
WaitStatus::Signaled(pid, status::term_signal(status), status::dumped_core(status))
} else if status::stopped(status) {
#[cfg(any(target_os = "linux", target_os = "android"))] {
Copy link
Member

@kamalmarhubi kamalmarhubi Nov 4, 2016

Choose a reason for hiding this comment

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

I didn't know cfg on blocks was possible, even if nightly only.

To do this on stable, I think your best approach is going to be adding an inner function like this:

// ...
} else if status::stopped(status) {
cfg_if! {
    if #[cfg(any(target_os = "linux", target_os = "android"))] {
        fn decode_stopped(status) -> WaitStatus {
            // Linux code
        }
    } else {
        fn decode_stopped(status) -> WaitStatus {
            // Other platform code
        }
    }
}
decode_stopped(status)
} else {
    // ...

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Oh yeah, should have pointed out where that comes from. We already have it in nix, so it's not a risk to use it.

let status_additional = status::stop_additional(status);
if status_additional != 0 {
return WaitStatus::PtraceEvent(pid, status::stop_signal(status), status::stop_additional(status))
}
}
WaitStatus::Stopped(pid, status::stop_signal(status))
} else {
assert!(status::continued(status));
Expand Down