Skip to content

Commit

Permalink
fix: only handle unix signals on unix
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanccn committed Nov 25, 2023
1 parent ce8e4fb commit efa2e97
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ on:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
runner:
- ubuntu-latest
- macos-latest
- windows-latest

runs-on: ${{ matrix.runner }}

steps:
- name: Checkout repository
Expand Down
7 changes: 7 additions & 0 deletions src/run_script.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(unix)]
use nix::{
sys::signal::{kill, Signal},
unistd::Pid,
Expand Down Expand Up @@ -148,9 +149,12 @@ pub async fn run_script(
}

let mut child = subproc.spawn()?;

#[allow(clippy::cast_possible_wrap)]
#[cfg(unix)]
let pid = child.id().map(|v| Pid::from_raw(v as i32));

#[cfg(unix)]
let task = tokio::task::spawn(async move {
if ctrl_c().await.is_ok() {
if let Some(pid) = pid {
Expand All @@ -160,7 +164,10 @@ pub async fn run_script(
});

let status = child.wait().await?;

#[cfg(unix)]
task.abort();

if !status.success() {
std::process::exit(status.code().unwrap_or(1));
}
Expand Down

0 comments on commit efa2e97

Please sign in to comment.