Skip to content

Commit

Permalink
wait: support ptrace events for Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
abbradar committed Feb 19, 2016
1 parent 7fa7206 commit b2d3b4a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/sys/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const WSTOPPED: WaitPidFlag = WUNTRACED;
pub enum WaitStatus {
Exited(pid_t, i8),
Signaled(pid_t, signal::SigNum, bool),
Stopped(pid_t, signal::SigNum),
Stopped(pid_t, signal::SigNum, c_int),
Continued(pid_t),
StillAlive
}
Expand All @@ -51,6 +51,7 @@ pub enum WaitStatus {
target_os = "android"))]
mod status {
use sys::signal;
use libc::c_int;

pub fn exited(status: i32) -> bool {
(status & 0x7F) == 0
Expand Down Expand Up @@ -80,6 +81,10 @@ mod status {
((status & 0xFF00) >> 8) as signal::SigNum
}

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

pub fn continued(status: i32) -> bool {
status == 0xFFFF
}
Expand All @@ -89,6 +94,7 @@ mod status {
target_os = "ios"))]
mod status {
use sys::signal;
use libc::c_int;

const WCOREFLAG: i32 = 0x80;
const WSTOPPED: i32 = 0x7f;
Expand All @@ -105,6 +111,10 @@ mod status {
(status >> 8) as signal::SigNum
}

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

pub fn continued(status: i32) -> bool {
wstatus(status) == WSTOPPED && stop_signal(status) == 0x13
}
Expand Down Expand Up @@ -136,6 +146,7 @@ mod status {
target_os = "netbsd"))]
mod status {
use sys::signal;
use libc::c_int;

const WCOREFLAG: i32 = 0x80;
const WSTOPPED: i32 = 0x7f;
Expand All @@ -152,6 +163,10 @@ mod status {
(status >> 8) as signal::SigNum
}

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

pub fn signaled(status: i32) -> bool {
wstatus(status) != WSTOPPED && wstatus(status) != 0 && status != 0x13
}
Expand Down Expand Up @@ -183,7 +198,7 @@ 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) {
WaitStatus::Stopped(pid, status::stop_signal(status))
WaitStatus::Stopped(pid, status::stop_signal(status), status::stop_additional(status))
} else {
assert!(status::continued(status));
WaitStatus::Continued(pid)
Expand Down

3 comments on commit b2d3b4a

@kamalmarhubi
Copy link

Choose a reason for hiding this comment

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

Could you link to the relevant part bit of documentation? I didn't see anything specific in either wait(2) or ptrace(2) man pages.

I'm also a bit put off by adding a meaningless member on non-Linux systems. Trying to think of alternatives...

@abbradar
Copy link
Owner Author

Choose a reason for hiding this comment

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

http://man7.org/linux/man-pages/man2/ptrace.2.html , see PTRACE_O_TRACEEXEC or PTRACE_O_TRACECLONE.

I don't like this too, but the only other way I thought of was to conditionally have the third value in Stopped based on a host system, and this renders any code that uses it unportable.

@kamalmarhubi
Copy link

Choose a reason for hiding this comment

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

I'll take a look, but will comment on the individual PR when it's opened. Thanks for the link!

Please sign in to comment.