mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-20 07:01:40 +03:00
roll intercept_sigs login into terminal
This commit is contained in:
parent
1863c397ec
commit
25ec21cc39
@ -1,29 +0,0 @@
|
|||||||
use tokio::signal::unix::{signal, SignalKind};
|
|
||||||
|
|
||||||
/// trigger cleanup if receive signal to kill process
|
|
||||||
pub async fn intercept_sigs() -> String {
|
|
||||||
let mut sigalrm = signal(SignalKind::alarm()).expect("uqbar: failed to set up SIGALRM handler");
|
|
||||||
let mut sighup = signal(SignalKind::hangup()).expect("uqbar: failed to set up SIGHUP handler");
|
|
||||||
let mut sigint =
|
|
||||||
signal(SignalKind::interrupt()).expect("uqbar: failed to set up SIGINT handler");
|
|
||||||
let mut sigpipe = signal(SignalKind::pipe()).expect("uqbar: failed to set up SIGPIPE handler");
|
|
||||||
let mut sigquit = signal(SignalKind::quit()).expect("uqbar: failed to set up SIGQUIT handler");
|
|
||||||
let mut sigterm =
|
|
||||||
signal(SignalKind::terminate()).expect("uqbar: failed to set up SIGTERM handler");
|
|
||||||
let mut sigusr1 =
|
|
||||||
signal(SignalKind::user_defined1()).expect("uqbar: failed to set up SIGUSR1 handler");
|
|
||||||
let mut sigusr2 =
|
|
||||||
signal(SignalKind::user_defined2()).expect("uqbar: failed to set up SIGUSR2 handler");
|
|
||||||
|
|
||||||
tokio::select! {
|
|
||||||
_ = sigalrm.recv() => "exiting due to SIGALRM",
|
|
||||||
_ = sighup.recv() => "exiting due to SIGHUP",
|
|
||||||
_ = sigint.recv() => "exiting due to SIGINT",
|
|
||||||
_ = sigpipe.recv() => "exiting due to SIGPIPE",
|
|
||||||
_ = sigquit.recv() => "exiting due to SIGQUIT",
|
|
||||||
_ = sigterm.recv() => "exiting due to SIGTERM",
|
|
||||||
_ = sigusr1.recv() => "exiting due to SIGUSR1",
|
|
||||||
_ = sigusr2.recv() => "exiting due to SIGUSR2",
|
|
||||||
}
|
|
||||||
.into()
|
|
||||||
}
|
|
@ -13,7 +13,6 @@ use ring::{rand::SystemRandom, signature, signature::KeyPair};
|
|||||||
|
|
||||||
mod eth_rpc;
|
mod eth_rpc;
|
||||||
mod http;
|
mod http;
|
||||||
mod intercept_sigs;
|
|
||||||
mod kernel;
|
mod kernel;
|
||||||
mod keygen;
|
mod keygen;
|
||||||
mod kv;
|
mod kv;
|
||||||
@ -495,9 +494,6 @@ async fn main() {
|
|||||||
Err(e) => e.to_string(),
|
Err(e) => e.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s = intercept_sigs::intercept_sigs() => {
|
|
||||||
s.into()
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// gracefully abort all running processes in kernel
|
// gracefully abort all running processes in kernel
|
||||||
|
@ -14,6 +14,7 @@ use crossterm::{
|
|||||||
use futures::{future::FutureExt, StreamExt};
|
use futures::{future::FutureExt, StreamExt};
|
||||||
use std::fs::{read_to_string, OpenOptions};
|
use std::fs::{read_to_string, OpenOptions};
|
||||||
use std::io::{stdout, BufWriter, Write};
|
use std::io::{stdout, BufWriter, Write};
|
||||||
|
use tokio::signal::unix::{signal, SignalKind};
|
||||||
|
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
@ -129,6 +130,24 @@ pub async fn terminal(
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let mut log_writer = BufWriter::new(log_handle);
|
let mut log_writer = BufWriter::new(log_handle);
|
||||||
|
|
||||||
|
// use to trigger cleanup if receive signal to kill process
|
||||||
|
let mut sigalrm = signal(SignalKind::alarm())
|
||||||
|
.expect("uqbar: failed to set up SIGALRM handler");
|
||||||
|
let mut sighup = signal(SignalKind::hangup())
|
||||||
|
.expect("uqbar: failed to set up SIGHUP handler");
|
||||||
|
let mut sigint = signal(SignalKind::interrupt())
|
||||||
|
.expect("uqbar: failed to set up SIGINT handler");
|
||||||
|
let mut sigpipe = signal(SignalKind::pipe())
|
||||||
|
.expect("uqbar: failed to set up SIGPIPE handler");
|
||||||
|
let mut sigquit = signal(SignalKind::quit())
|
||||||
|
.expect("uqbar: failed to set up SIGQUIT handler");
|
||||||
|
let mut sigterm = signal(SignalKind::terminate())
|
||||||
|
.expect("uqbar: failed to set up SIGTERM handler");
|
||||||
|
let mut sigusr1 = signal(SignalKind::user_defined1())
|
||||||
|
.expect("uqbar: failed to set up SIGUSR1 handler");
|
||||||
|
let mut sigusr2 = signal(SignalKind::user_defined2())
|
||||||
|
.expect("uqbar: failed to set up SIGUSR2 handler");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let event = reader.next().fuse();
|
let event = reader.next().fuse();
|
||||||
|
|
||||||
@ -172,7 +191,7 @@ pub async fn terminal(
|
|||||||
Print(utils::truncate_in_place(¤t_line, prompt_len, win_cols, (line_col, cursor_col))),
|
Print(utils::truncate_in_place(¤t_line, prompt_len, win_cols, (line_col, cursor_col))),
|
||||||
cursor::MoveTo(cursor_col, win_rows),
|
cursor::MoveTo(cursor_col, win_rows),
|
||||||
)?;
|
)?;
|
||||||
},
|
}
|
||||||
Some(Ok(event)) = event => {
|
Some(Ok(event)) = event => {
|
||||||
let mut stdout = stdout.lock();
|
let mut stdout = stdout.lock();
|
||||||
match event {
|
match event {
|
||||||
@ -599,7 +618,15 @@ pub async fn terminal(
|
|||||||
},
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_ = sigalrm.recv() => return Err(anyhow::anyhow!("exiting due to SIGALRM")),
|
||||||
|
_ = sighup.recv() => return Err(anyhow::anyhow!("exiting due to SIGHUP")),
|
||||||
|
_ = sigint.recv() => return Err(anyhow::anyhow!("exiting due to SIGINT")),
|
||||||
|
_ = sigpipe.recv() => return Err(anyhow::anyhow!("exiting due to SIGPIPE")),
|
||||||
|
_ = sigquit.recv() => return Err(anyhow::anyhow!("exiting due to SIGQUIT")),
|
||||||
|
_ = sigterm.recv() => return Err(anyhow::anyhow!("exiting due to SIGTERM")),
|
||||||
|
_ = sigusr1.recv() => return Err(anyhow::anyhow!("exiting due to SIGUSR1")),
|
||||||
|
_ = sigusr2.recv() => return Err(anyhow::anyhow!("exiting due to SIGUSR2")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
execute!(stdout.lock(), DisableBracketedPaste, terminal::SetTitle(""))?;
|
execute!(stdout.lock(), DisableBracketedPaste, terminal::SetTitle(""))?;
|
||||||
|
Loading…
Reference in New Issue
Block a user