mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-11-15 08:15:31 +00:00
Moe exit message
This commit is contained in:
+56
-59
@@ -15,46 +15,43 @@ pub fn monitor_signal(handle: &Handle, plugins: Vec<Plugin>) {
|
||||
use tokio_signal::unix::Signal;
|
||||
|
||||
// Monitor SIGCHLD, triggered if subprocess (plugin) is exited.
|
||||
let fut1 = Signal::new(libc::SIGCHLD, handle)
|
||||
.and_then(|signal| {
|
||||
signal.take(1)
|
||||
.for_each(|_| -> Result<(), io::Error> {
|
||||
error!("Plugin exited unexpectly (SIGCHLD)");
|
||||
Ok(())
|
||||
})
|
||||
.map(|_| libc::SIGCHLD)
|
||||
})
|
||||
.map_err(|err| {
|
||||
error!("Failed to monitor SIGCHLD, err: {:?}", err);
|
||||
});
|
||||
let fut1 = Signal::new(libc::SIGCHLD, handle).and_then(|signal| {
|
||||
signal.take(1)
|
||||
.for_each(|_| -> Result<(), io::Error> {
|
||||
error!("Plugin exited unexpectly (SIGCHLD)");
|
||||
Ok(())
|
||||
})
|
||||
.map(|_| libc::SIGCHLD)
|
||||
})
|
||||
.map_err(|err| {
|
||||
error!("Failed to monitor SIGCHLD, err: {:?}", err);
|
||||
});
|
||||
|
||||
// Monitor SIGTERM, triggered if shadowsocks is exited gracefully. (Kill by user).
|
||||
let fut2 = Signal::new(libc::SIGTERM, handle)
|
||||
.and_then(|sigterm| {
|
||||
sigterm.take(1)
|
||||
.for_each(|_| -> Result<(), io::Error> {
|
||||
info!("Received SIGTERM, exiting.");
|
||||
Ok(())
|
||||
})
|
||||
.map(|_| libc::SIGTERM)
|
||||
})
|
||||
.map_err(|err| {
|
||||
error!("Failed to monitor SIGTERM, err: {:?}", err);
|
||||
});
|
||||
let fut2 = Signal::new(libc::SIGTERM, handle).and_then(|sigterm| {
|
||||
sigterm.take(1)
|
||||
.for_each(|_| -> Result<(), io::Error> {
|
||||
info!("Received SIGTERM, exiting.");
|
||||
Ok(())
|
||||
})
|
||||
.map(|_| libc::SIGTERM)
|
||||
})
|
||||
.map_err(|err| {
|
||||
error!("Failed to monitor SIGTERM, err: {:?}", err);
|
||||
});
|
||||
|
||||
// Monitor SIGINT, triggered by CTRL-C
|
||||
let fut3 = Signal::new(libc::SIGINT, handle)
|
||||
.and_then(|sigint| {
|
||||
sigint.take(1)
|
||||
.for_each(|_| -> Result<(), io::Error> {
|
||||
info!("Received SIGINT, exiting.");
|
||||
Ok(())
|
||||
})
|
||||
.map(|_| libc::SIGINT)
|
||||
})
|
||||
.map_err(|err| {
|
||||
error!("Failed to monitor SIGINT, err: {:?}", err);
|
||||
});
|
||||
let fut3 = Signal::new(libc::SIGINT, handle).and_then(|sigint| {
|
||||
sigint.take(1)
|
||||
.for_each(|_| -> Result<(), io::Error> {
|
||||
info!("Received SIGINT, exiting.");
|
||||
Ok(())
|
||||
})
|
||||
.map(|_| libc::SIGINT)
|
||||
})
|
||||
.map_err(|err| {
|
||||
error!("Failed to monitor SIGINT, err: {:?}", err);
|
||||
});
|
||||
|
||||
// Join them all, if any of them is triggered, kill all subprocesses and exit.
|
||||
let fut = fut1.select(fut2)
|
||||
@@ -65,7 +62,7 @@ pub fn monitor_signal(handle: &Handle, plugins: Vec<Plugin>) {
|
||||
.map_err(|(e, _)| e)
|
||||
.then(|r| {
|
||||
// Something happened ... killing all subprocesses
|
||||
info!("Killing {} plugins and then exit", plugins.len());
|
||||
info!("Killing {} plugin(s) and then ... Bye Bye :)", plugins.len());
|
||||
drop(plugins);
|
||||
|
||||
match r {
|
||||
@@ -85,31 +82,29 @@ pub fn monitor_signal(handle: &Handle, plugins: Vec<Plugin>) {
|
||||
|
||||
use tokio_signal::windows::Event;
|
||||
|
||||
let fut1 = Event::ctrl_c(handle)
|
||||
.and_then(|ev| {
|
||||
ev.take(1).for_each(|_| -> Result<(), io::Error> {
|
||||
error!("Received Ctrl-C event");
|
||||
Ok(())
|
||||
})
|
||||
})
|
||||
.map_err(|err| {
|
||||
error!("Failed to monitor Ctrl-C event: {:?}", err);
|
||||
});
|
||||
let fut1 = Event::ctrl_c(handle).and_then(|ev| {
|
||||
ev.take(1).for_each(|_| -> Result<(), io::Error> {
|
||||
error!("Received Ctrl-C event");
|
||||
Ok(())
|
||||
})
|
||||
})
|
||||
.map_err(|err| {
|
||||
error!("Failed to monitor Ctrl-C event: {:?}", err);
|
||||
});
|
||||
|
||||
let fut2 = Event::ctrl_break(handle)
|
||||
.and_then(|ev| {
|
||||
ev.take(1).for_each(|_| -> Result<(), io::Error> {
|
||||
error!("Received Ctrl-Break event");
|
||||
Ok(())
|
||||
})
|
||||
})
|
||||
.map_err(|err| {
|
||||
error!("Failed to monitor Ctrl-Break event: {:?}", err);
|
||||
});
|
||||
let fut2 = Event::ctrl_break(handle).and_then(|ev| {
|
||||
ev.take(1).for_each(|_| -> Result<(), io::Error> {
|
||||
error!("Received Ctrl-Break event");
|
||||
Ok(())
|
||||
})
|
||||
})
|
||||
.map_err(|err| {
|
||||
error!("Failed to monitor Ctrl-Break event: {:?}", err);
|
||||
});
|
||||
|
||||
let fut = fut1.select(fut2).then(|_| -> Result<(), ()> {
|
||||
// Something happened ... killing all subprocesses
|
||||
info!("Killing {} plugins and then exit", plugins.len());
|
||||
info!("Killing {} plugin(s) and then ... Bye Bye :)", plugins.len());
|
||||
drop(plugins);
|
||||
process::exit(libc::EXIT_FAILURE);
|
||||
});
|
||||
@@ -120,6 +115,8 @@ pub fn monitor_signal(handle: &Handle, plugins: Vec<Plugin>) {
|
||||
pub fn monitor_signal(handle: &Handle, plugins: Vec<Plugin>) {
|
||||
// FIXME: What can I do ...
|
||||
// Blocks forever
|
||||
let fut = futures::empty::<(), ()>().and_then(|_| { drop(plugins); });
|
||||
let fut = futures::empty::<(), ()>().and_then(|_| {
|
||||
drop(plugins);
|
||||
});
|
||||
handle.spawn(fut);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user