Skip to content

Commit

Permalink
add win interruption using tokio::windows
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Llerena <philippe.llerena@gmail.com>
  • Loading branch information
doubleailes committed Sep 11, 2024
1 parent 19ff372 commit 97489fe
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions crates/spfs-cli/cmd-monitor/src/cmd_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use spfs::Error;
use spfs_cli_common as cli;
use spfs_cli_common::CommandName;
use tokio::io::AsyncReadExt;
#[cfg(unix)]
use tokio::signal::unix::{signal, SignalKind};
#[cfg(windows)]
use tokio::signal::windows::ctrl_c;
use tokio::time::timeout;

fn main() -> Result<()> {
Expand Down Expand Up @@ -86,11 +89,10 @@ impl CmdMonitor {
rt.block_on(self.wait_for_ready());
// clean up this runtime and all other threads before detaching
drop(rt);

#[cfg(unix)]
nix::unistd::daemon(self.no_chdir, self.no_close)
.into_diagnostic()
.wrap_err("Failed to daemonize the monitor process")?;

#[cfg(feature = "sentry")]
{
// Initialize sentry after the call to `daemon` so it is safe for
Expand Down Expand Up @@ -142,12 +144,23 @@ impl CmdMonitor {
}

pub async fn run_async(&mut self, config: &spfs::Config) -> Result<i32> {
#[cfg(unix)]
let mut interrupt = signal(SignalKind::interrupt())
.map_err(|err| Error::process_spawn_error("signal()", err, None))?;
#[cfg(windows)]
let mut interrupt =
ctrl_c().map_err(|err| Error::process_spawn_error("ctrl_c()", err, None))?;
#[cfg(unix)]
let mut quit = signal(SignalKind::quit())
.map_err(|err| Error::process_spawn_error("signal()", err, None))?;
#[cfg(windows)]
let mut quit = ctrl_c().map_err(|err| Error::process_spawn_error("ctrl_c()", err, None))?;
#[cfg(unix)]
let mut terminate = signal(SignalKind::terminate())
.map_err(|err| Error::process_spawn_error("signal()", err, None))?;
#[cfg(windows)]
let mut terminate =
ctrl_c().map_err(|err| Error::process_spawn_error("ctrl_c()", err, None))?;

let repo = spfs::open_repository(&self.runtime_storage).await?;
let storage = spfs::runtime::Storage::new(repo)?;
Expand Down

0 comments on commit 97489fe

Please sign in to comment.