Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to unix domain socket #36

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
5 changes: 0 additions & 5 deletions src/cmd/interactive/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use hyper::server::conn::Http;
use hyper::service::Service;
use hyper::Body;
use tokio::net::UnixListener;
// use tokio::runtime::Runtime;
use tokio::task::JoinHandle;
use tracing::instrument;

Expand All @@ -36,9 +35,6 @@ impl TodaServer {
pub fn serve_interactive(&mut self, interactive_path: PathBuf) {
let toda_rpc = self.toda_rpc.clone();
self.task = Some(tokio::task::spawn(async move {
// Runtime::new()
// .expect("Failed to create Tokio runtime")
// .block_on(async {
tracing::info!("TodaServer listener try binding {:?}", interactive_path);
let unix_listener = UnixListener::bind(interactive_path).unwrap();

Expand All @@ -64,7 +60,6 @@ impl TodaServer {
}
}
}
// })
}));
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/hookfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,13 @@ impl HookFs {
self.enable_injection.store(true, Ordering::SeqCst);
}

pub fn disable_injection(&self) {
pub async fn disable_injection(&self) {
self.enable_injection.store(false, Ordering::SeqCst);

// TODO: create a standalone runtime only for interrupt is too ugly.
RandyLambert marked this conversation as resolved.
Show resolved Hide resolved
// this RWLock is actually redundant, and the injector is rarely written.
let mut rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let injector = self.injector.read().await;
injector.interrupt();
});
}

pub fn rebuild_path<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf> {
Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,26 @@ async fn main() -> anyhow::Result<()> {
};

let (tx, _) = mpsc::channel();
if option.interactive_path.is_some() {
if let Some(path) = option.interactive_path.clone() {
let hookfs = match &mount_injector {
Ok(e) => Some(e.hookfs.clone()),
Err(_) => None,
};
let mut toda_server =
TodaServer::new(TodaRpc::new(Mutex::new(status), Mutex::new(tx), hookfs));
toda_server.serve_interactive(option.interactive_path.clone().unwrap());
toda_server.serve_interactive(path.clone());

info!("waiting for signal to exit");
let mut signals = Signals::from_kinds(&[SignalKind::interrupt(), SignalKind::terminate()])?;
signals.wait().await;

// delete the unix socket file
std::fs::remove_file(option.interactive_path.clone().unwrap())?;

info!("start to recover and exit");
if let Ok(v) = mount_injector {
resume(option, v)?;
}

// delete the unix socket file
std::fs::remove_file(path.clone())?;
exit(0);
}
Ok(())
Expand Down