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
chaosagent committed Oct 16, 2016
1 parent bf00bf2 commit ad62647
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/sys/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ 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 +55,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 +85,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 +192,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) {
if cfg!(any(target_os = "linux", target_os = "android")) {
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

0 comments on commit ad62647

Please sign in to comment.