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 <william.douglas@intel.com>
This commit is contained in:
William Douglas 2021-04-28 11:22:14 -07:00 committed by Rob Bradford
parent 51a93bc635
commit b8779ddc9e
2 changed files with 9 additions and 2 deletions

View File

@ -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<thread::JoinHandle<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)
}

View File

@ -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<T> = result::Result<T, Error>;