Stop swallowing signals in build_system when running sub-commands
This commit is contained in:
parent
0f87072fdf
commit
766f59d7f2
@ -1,10 +1,42 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
#[cfg(unix)]
|
||||||
|
use std::ffi::c_int;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
#[cfg(unix)]
|
||||||
|
use std::os::unix::process::ExitStatusExt;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::{Command, ExitStatus, Output};
|
use std::process::{Command, ExitStatus, Output};
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
extern "C" {
|
||||||
|
fn raise(signal: c_int) -> c_int;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn exec_command(
|
||||||
|
input: &[&dyn AsRef<OsStr>],
|
||||||
|
cwd: Option<&Path>,
|
||||||
|
env: Option<&HashMap<String, String>>,
|
||||||
|
) -> Result<ExitStatus, String> {
|
||||||
|
let status = get_command_inner(input, cwd, env)
|
||||||
|
.spawn()
|
||||||
|
.map_err(|e| command_error(input, &cwd, e))?
|
||||||
|
.wait()
|
||||||
|
.map_err(|e| command_error(input, &cwd, e))?;
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
if let Some(signal) = status.signal() {
|
||||||
|
unsafe {
|
||||||
|
raise(signal as _);
|
||||||
|
}
|
||||||
|
// In case the signal didn't kill the current process.
|
||||||
|
return Err(command_error(input, &cwd, format!("Process received signal {}", signal)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(status)
|
||||||
|
}
|
||||||
|
|
||||||
fn get_command_inner(
|
fn get_command_inner(
|
||||||
input: &[&dyn AsRef<OsStr>],
|
input: &[&dyn AsRef<OsStr>],
|
||||||
cwd: Option<&Path>,
|
cwd: Option<&Path>,
|
||||||
@ -89,11 +121,7 @@ pub fn run_command_with_output(
|
|||||||
input: &[&dyn AsRef<OsStr>],
|
input: &[&dyn AsRef<OsStr>],
|
||||||
cwd: Option<&Path>,
|
cwd: Option<&Path>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let exit_status = get_command_inner(input, cwd, None)
|
let exit_status = exec_command(input, cwd, None)?;
|
||||||
.spawn()
|
|
||||||
.map_err(|e| command_error(input, &cwd, e))?
|
|
||||||
.wait()
|
|
||||||
.map_err(|e| command_error(input, &cwd, e))?;
|
|
||||||
check_exit_status(input, cwd, exit_status, None, true)?;
|
check_exit_status(input, cwd, exit_status, None, true)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -103,11 +131,7 @@ pub fn run_command_with_output_and_env(
|
|||||||
cwd: Option<&Path>,
|
cwd: Option<&Path>,
|
||||||
env: Option<&HashMap<String, String>>,
|
env: Option<&HashMap<String, String>>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let exit_status = get_command_inner(input, cwd, env)
|
let exit_status = exec_command(input, cwd, env)?;
|
||||||
.spawn()
|
|
||||||
.map_err(|e| command_error(input, &cwd, e))?
|
|
||||||
.wait()
|
|
||||||
.map_err(|e| command_error(input, &cwd, e))?;
|
|
||||||
check_exit_status(input, cwd, exit_status, None, true)?;
|
check_exit_status(input, cwd, exit_status, None, true)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -117,11 +141,7 @@ pub fn run_command_with_output_and_env_no_err(
|
|||||||
cwd: Option<&Path>,
|
cwd: Option<&Path>,
|
||||||
env: Option<&HashMap<String, String>>,
|
env: Option<&HashMap<String, String>>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let exit_status = get_command_inner(input, cwd, env)
|
let exit_status = exec_command(input, cwd, env)?;
|
||||||
.spawn()
|
|
||||||
.map_err(|e| command_error(input, &cwd, e))?
|
|
||||||
.wait()
|
|
||||||
.map_err(|e| command_error(input, &cwd, e))?;
|
|
||||||
check_exit_status(input, cwd, exit_status, None, false)?;
|
check_exit_status(input, cwd, exit_status, None, false)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user