Skip to content

Commit

Permalink
Use exec on Unix to propagate signals
Browse files Browse the repository at this point in the history
This is only possible when telemetry is disabled, but almost all of the time it
is! This should help fix lots of common rustup-related issues related to signals
and such.

Closes rust-lang#31
Closes rust-lang#806
  • Loading branch information
alexcrichton committed Aug 22, 2017
1 parent c4e7616 commit e13247f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/rustup-cli/proxy_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,3 @@ fn direct_proxy(cfg: &Cfg, arg0: &str, toolchain: Option<&str>, args: &[OsString
};
Ok(try!(run_command_for_dir(cmd, arg0, args, &cfg)))
}

29 changes: 16 additions & 13 deletions src/rustup/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn run_command_for_dir<S: AsRef<OsStr>>(cmd: Command,
return telemetry_rustc(cmd, arg0, args, cfg);
}

run_command_for_dir_without_telemetry(cmd, arg0, args)
exec_command_for_dir_without_telemetry(cmd, arg0, args)
}

fn telemetry_rustc<S: AsRef<OsStr>>(mut cmd: Command,
Expand Down Expand Up @@ -132,7 +132,7 @@ fn telemetry_rustc<S: AsRef<OsStr>>(mut cmd: Command,
}
}

fn run_command_for_dir_without_telemetry<S: AsRef<OsStr>>(
fn exec_command_for_dir_without_telemetry<S: AsRef<OsStr>>(
mut cmd: Command, arg0: &str, args: &[S]) -> Result<()>
{
cmd.args(args);
Expand All @@ -141,17 +141,20 @@ fn run_command_for_dir_without_telemetry<S: AsRef<OsStr>>(
// when and why this is needed.
cmd.stdin(process::Stdio::inherit());

match cmd.status() {
Ok(status) => {
// Ensure correct exit code is returned
let code = status.code().unwrap_or(1);
process::exit(code);
}
Err(e) => {
Err(e).chain_err(|| rustup_utils::ErrorKind::RunningCommand {
name: OsStr::new(arg0).to_owned(),
})
}
return exec(&mut cmd).chain_err(|| rustup_utils::ErrorKind::RunningCommand {
name: OsStr::new(arg0).to_owned(),
});

#[cfg(unix)]
fn exec(cmd: &mut Command) -> io::Result<()> {
use std::os::unix::prelude::*;
Err(cmd.exec())
}

#[cfg(windows)]
fn exec(cmd: &mut Command) -> io::Result<()> {
let status = cmd.status()?;
process::exit(status.code.unwrap());
}
}

Expand Down

0 comments on commit e13247f

Please sign in to comment.