netutils/ping: add sigint handler
This commit is contained in:
Generated
+1
@@ -1693,6 +1693,7 @@ dependencies = [
|
|||||||
"bytemuck",
|
"bytemuck",
|
||||||
"clap",
|
"clap",
|
||||||
"clap-num",
|
"clap-num",
|
||||||
|
"cross",
|
||||||
"hclient",
|
"hclient",
|
||||||
"http",
|
"http",
|
||||||
"log",
|
"log",
|
||||||
|
|||||||
@@ -11,10 +11,18 @@ pub mod term;
|
|||||||
pub mod time;
|
pub mod time;
|
||||||
pub mod timer;
|
pub mod timer;
|
||||||
|
|
||||||
|
use runtime::rt::process::Signal;
|
||||||
use std::{
|
use std::{
|
||||||
io,
|
io,
|
||||||
os::{fd::RawFd, yggdrasil::process::CommandExt},
|
os::{
|
||||||
|
fd::RawFd,
|
||||||
|
yggdrasil::{
|
||||||
|
process::CommandExt,
|
||||||
|
signal::{set_signal_handler, SignalHandler},
|
||||||
|
},
|
||||||
|
},
|
||||||
process::Command,
|
process::Command,
|
||||||
|
sync::atomic::{AtomicUsize, Ordering},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use mem::{FileMappingImpl, SharedMemoryImpl};
|
pub use mem::{FileMappingImpl, SharedMemoryImpl};
|
||||||
@@ -29,7 +37,22 @@ pub use timer::TimerFdImpl;
|
|||||||
|
|
||||||
use crate::process::CommandSpawnExt;
|
use crate::process::CommandSpawnExt;
|
||||||
|
|
||||||
pub fn set_sigint_handler(_handler: fn()) {}
|
pub fn set_sigint_handler(handler: fn()) {
|
||||||
|
static HANDLER: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
|
||||||
|
fn handler_stub(_signal: Signal) {
|
||||||
|
let handler = HANDLER.load(Ordering::Acquire);
|
||||||
|
|
||||||
|
if handler != 0 {
|
||||||
|
let handler: fn() = unsafe { core::mem::transmute(handler) };
|
||||||
|
handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HANDLER.store(handler as usize, Ordering::Release);
|
||||||
|
|
||||||
|
let _ = set_signal_handler(Signal::Interrupted, SignalHandler::Function(handler_stub));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn send_kill(pid: u32) -> io::Result<()> {
|
pub fn send_kill(pid: u32) -> io::Result<()> {
|
||||||
use runtime::rt::{
|
use runtime::rt::{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ yggdrasil-abi.workspace = true
|
|||||||
runtime.workspace = true
|
runtime.workspace = true
|
||||||
logsink.workspace = true
|
logsink.workspace = true
|
||||||
hclient.workspace = true
|
hclient.workspace = true
|
||||||
|
cross.workspace = true
|
||||||
|
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
bytemuck.workspace = true
|
bytemuck.workspace = true
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use std::{
|
|||||||
|
|
||||||
use bytemuck::Zeroable;
|
use bytemuck::Zeroable;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use cross::signal::set_sigint_handler;
|
||||||
use netutils::{netconfig::NetConfig, Error};
|
use netutils::{netconfig::NetConfig, Error};
|
||||||
use runtime::abi::net::MacAddress;
|
use runtime::abi::net::MacAddress;
|
||||||
use yggdrasil_abi::net::{
|
use yggdrasil_abi::net::{
|
||||||
@@ -339,7 +340,13 @@ fn ping(
|
|||||||
|
|
||||||
static INTERRUPTED: AtomicBool = AtomicBool::new(false);
|
static INTERRUPTED: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
|
fn sigint_handler() {
|
||||||
|
eprintln!("Sigint received, aborting");
|
||||||
|
INTERRUPTED.store(true, Ordering::Release);
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> ExitCode {
|
||||||
|
set_sigint_handler(sigint_handler);
|
||||||
// set_signal_handler(Signal::Interrupted, SignalHandler::Function(interrupt));
|
// set_signal_handler(Signal::Interrupted, SignalHandler::Function(interrupt));
|
||||||
|
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|||||||
Reference in New Issue
Block a user