From 94403041837ea010073459b1aa2d710c31910b4e Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 17 Mar 2021 09:19:30 +0000 Subject: [PATCH] vmm: http: Error out earlier if we can't create API server This removes a panic inside the API thread. Fixes: #2395 Signed-off-by: Rob Bradford --- vmm/src/api/http.rs | 2 +- vmm/src/lib.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/vmm/src/api/http.rs b/vmm/src/api/http.rs index 915e5a572..ded356ea9 100644 --- a/vmm/src/api/http.rs +++ b/vmm/src/api/http.rs @@ -261,6 +261,7 @@ pub fn start_http_thread( ) -> Result>> { std::fs::remove_file(path).unwrap_or_default(); let socket_path = PathBuf::from(path); + let mut server = HttpServer::new(socket_path).map_err(Error::CreatingAPIServer)?; // Retrieve seccomp filter for API thread let api_seccomp_filter = @@ -272,7 +273,6 @@ pub fn start_http_thread( // Apply seccomp filter for API thread. SeccompFilter::apply(api_seccomp_filter).map_err(Error::ApplySeccompFilter)?; - let mut server = HttpServer::new(socket_path).unwrap(); server.start_server().unwrap(); loop { match server.requests() { diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index d3bfb9196..94205a241 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -140,6 +140,10 @@ pub enum Error { /// Error activating virtio devices #[error("Error activating virtio devices: {0:?}")] ActivateVirtioDevices(VmError), + + /// Error creating API server + #[error("Error creating API server {0:?}")] + CreatingAPIServer(micro_http::ServerError), } pub type Result = result::Result;