Skip to content

Commit

Permalink
Auto merge of #2315 - alexcrichton:decode-some-signals, r=brson
Browse files Browse the repository at this point in the history
Instead of text that looks like

    Process failed (signal: 11)

the text now looks like:

    Process failed (signal: 11, SIGSEGV: invalid memory reference)

Closes #2315
  • Loading branch information
bors committed Feb 5, 2016
2 parents b5e0a45 + b3a8bac commit 3e285ce
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/cargo/util/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ pub fn process_error(msg: &str,
status: Option<&ExitStatus>,
output: Option<&Output>) -> ProcessError {
let exit = match status {
Some(s) => s.to_string(),
Some(s) => status_to_string(s),
None => "never executed".to_string(),
};
let mut desc = format!("{} ({})", &msg, exit);
Expand All @@ -359,11 +359,45 @@ pub fn process_error(msg: &str,
}
}

ProcessError {
return ProcessError {
desc: desc,
exit: status.cloned(),
output: output.cloned(),
cause: cause,
};

#[cfg(unix)]
fn status_to_string(status: &ExitStatus) -> String {
use std::os::unix::process::*;
use libc;

if let Some(signal) = status.signal() {
let name = match signal as libc::c_int {
libc::SIGABRT => ", SIGABRT: process abort signal",
libc::SIGALRM => ", SIGALRM: alarm clock",
libc::SIGFPE => ", SIGFPE: erroneous arithmetic operation",
libc::SIGHUP => ", SIGHUP: hangup",
libc::SIGILL => ", SIGILL: illegal instruction",
libc::SIGINT => ", SIGINT: terminal interrupt signal",
libc::SIGKILL => ", SIGKILL: kill",
libc::SIGPIPE => ", SIGPIPE: write on a pipe with no one to read",
libc::SIGQUIT => ", SIGQUIT: terminal quite signal",
libc::SIGSEGV => ", SIGSEGV: invalid memory reference",
libc::SIGTERM => ", SIGTERM: termination signal",
libc::SIGBUS => ", SIGBUS: access to undefined memory",
libc::SIGSYS => ", SIGSYS: bad system call",
libc::SIGTRAP => ", SIGTRAP: trace/breakpoint trap",
_ => "",
};
format!("signal: {}{}", signal, name)
} else {
status.to_string()
}
}

#[cfg(windows)]
fn status_to_string(status: &ExitStatus) -> String {
status.to_string()
}
}

Expand Down

0 comments on commit 3e285ce

Please sign in to comment.