From b8779ddc9ed50d2b7073c4f8e8eda2874d33a06d Mon Sep 17 00:00:00 2001 From: William Douglas Date: Wed, 28 Apr 2021 11:22:14 -0700 Subject: [PATCH] vmm: Create the api socket fd to pass to the http server Instead of using the http server's method to have it create the fd (causing the http thread to need to support the socket, bind and listen syscalls). Create the socket fd in the vmm thread and use the http server's new method supporting passing in this fd for the api socket. Signed-off-by: William Douglas --- vmm/src/api/http.rs | 7 +++++-- vmm/src/lib.rs | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/vmm/src/api/http.rs b/vmm/src/api/http.rs index f3d637713..b0c73e875 100644 --- a/vmm/src/api/http.rs +++ b/vmm/src/api/http.rs @@ -11,7 +11,8 @@ use micro_http::{Body, HttpServer, MediaType, Method, Request, Response, StatusC use seccomp::{SeccompAction, SeccompFilter}; use serde_json::Error as SerdeError; use std::collections::HashMap; -use std::os::unix::io::RawFd; +use std::os::unix::io::{IntoRawFd, RawFd}; +use std::os::unix::net::UnixListener; use std::path::PathBuf; use std::sync::mpsc::Sender; use std::sync::Arc; @@ -305,7 +306,9 @@ pub fn start_http_path_thread( ) -> Result>> { std::fs::remove_file(path).unwrap_or_default(); let socket_path = PathBuf::from(path); - let server = HttpServer::new(socket_path).map_err(Error::CreateApiServer)?; + let socket_fd = UnixListener::bind(socket_path).map_err(Error::CreateApiServerSocket)?; + let server = + HttpServer::new_from_fd(socket_fd.into_raw_fd()).map_err(Error::CreateApiServer)?; start_http_thread(server, api_notifier, api_sender, seccomp_action) } diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index 8bf46ab72..e24bf6ed8 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -144,6 +144,10 @@ pub enum Error { /// Error creating API server #[error("Error creating API server {0:?}")] CreateApiServer(micro_http::ServerError), + + /// Error binding API server socket + #[error("Error creation API server's socket {0:?}")] + CreateApiServerSocket(#[source] io::Error), } pub type Result = result::Result;