Skip to content

Commit

Permalink
Fix Windows build
Browse files Browse the repository at this point in the history
This fixes building on Windows by putting the unix specific signal
handling behind a cfg attribute and adding Windows specific handling
too.

Adresses #86
  • Loading branch information
hannesdejager committed Feb 21, 2023
1 parent 1a29759 commit 85b56f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
1 change: 0 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ jobs:
with:
name: Windows
path: target/x86_64-pc-windows-msvc/release/unftp.exe
continue-on-error: true # Until we fix the Windows issue. See https://github.com/bolcom/unFTP/issues/86

build-macos-intel:
runs-on: macos-latest
Expand Down
47 changes: 29 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ use std::{
sync::Arc,
time::Duration,
};
use tokio::{
runtime::Runtime,
signal::unix::{signal, SignalKind},
};
use tokio::runtime::Runtime;
#[cfg(feature = "pam_auth")]
use unftp_auth_pam as pam;
use unftp_sbe_gcs::options::AuthMethod;
Expand Down Expand Up @@ -679,20 +676,34 @@ where
struct ExitSignal(pub &'static str);

async fn listen_for_signals() -> Result<ExitSignal, String> {
let mut term_sig = signal(SignalKind::terminate())
.map_err(|e| format!("could not listen for TERM signals: {}", e))?;
let mut int_sig = signal(SignalKind::interrupt())
.map_err(|e| format!("Could not listen for INT signal: {}", e))?;

let sig_name = tokio::select! {
Some(_signal) = term_sig.recv() => {
"SIG_TERM"
},
Some(_signal) = int_sig.recv() => {
"SIG_INT"
},
};
Ok(ExitSignal(sig_name))
#[cfg(unix)]
{
use tokio::signal::unix::{signal, SignalKind};

let mut term_sig = signal(SignalKind::terminate())
.map_err(|e| format!("could not listen for TERM signals: {}", e))?;
let mut int_sig = signal(SignalKind::interrupt())
.map_err(|e| format!("Could not listen for INT signal: {}", e))?;

let sig_name = tokio::select! {
Some(_signal) = term_sig.recv() => {
"SIG_TERM"
},
Some(_signal) = int_sig.recv() => {
"SIG_INT"
},
};
Ok(ExitSignal(sig_name))
}

#[cfg(windows)]
{
use tokio::signal;
signal::ctrl_c()
.await
.map_err(|e| format!("could not listen for ctrl-c: {}", e))?;
Ok(ExitSignal("CTRL-C"))
}
}

async fn main_task(
Expand Down

0 comments on commit 85b56f8

Please sign in to comment.