From 9993f0810c37bcb4d895221b28217dbbf690d315 Mon Sep 17 00:00:00 2001 From: David Hou Date: Sun, 16 Oct 2016 14:31:46 -0700 Subject: [PATCH 1/3] wait: Support ptrace events for Linux --- src/sys/wait.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/sys/wait.rs b/src/sys/wait.rs index 259efb7092..018937a1c0 100644 --- a/src/sys/wait.rs +++ b/src/sys/wait.rs @@ -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 } @@ -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 @@ -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 } @@ -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) { + 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)); From 8de4cfbb4c78542836110b74dd0919d69d95c155 Mon Sep 17 00:00:00 2001 From: David Hou Date: Sun, 16 Oct 2016 15:08:08 -0700 Subject: [PATCH 2/3] Attempt to fix build for non-{android,linux} platforms --- src/sys/wait.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys/wait.rs b/src/sys/wait.rs index 018937a1c0..c3ae815f1c 100644 --- a/src/sys/wait.rs +++ b/src/sys/wait.rs @@ -191,7 +191,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) { - if cfg!(any(target_os = "linux", target_os = "android")) { + #[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)) From e6bfbbb810ee1c86138ebb6ce8610e403cb83945 Mon Sep 17 00:00:00 2001 From: David Hou Date: Sat, 5 Nov 2016 14:48:15 -0700 Subject: [PATCH 3/3] Use cfg_if to branch code in WaitStatus decode --- src/sys/wait.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/sys/wait.rs b/src/sys/wait.rs index c3ae815f1c..7e21339d69 100644 --- a/src/sys/wait.rs +++ b/src/sys/wait.rs @@ -191,13 +191,23 @@ 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"))] { - let status_additional = status::stop_additional(status); - if status_additional != 0 { - return WaitStatus::PtraceEvent(pid, status::stop_signal(status), status::stop_additional(status)) + cfg_if! { + if #[cfg(any(target_os = "linux", target_os = "android"))] { + fn decode_stopped(pid: pid_t, status: i32) -> WaitStatus { + let status_additional = status::stop_additional(status); + if status_additional == 0 { + WaitStatus::Stopped(pid, status::stop_signal(status)) + } else { + WaitStatus::PtraceEvent(pid, status::stop_signal(status), status::stop_additional(status)) + } + } + } else { + fn decode_stopped(pid: pid_t, status: i32) -> WaitStatus { + WaitStatus::Stopped(pid, status::stop_signal(status)) + } } } - WaitStatus::Stopped(pid, status::stop_signal(status)) + decode_stopped(pid, status) } else { assert!(status::continued(status)); WaitStatus::Continued(pid)