mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
main: Enable the api-socket to be passed as an fd
To avoid race issues where the api-socket may not be created by the time a cloud-hypervisor caller is ready to look for it, enable the caller to pass the api-socket fd directly. Avoid breaking current callers by allowing the --api-socket path to be passed as it is now in addition to through the path argument. Signed-off-by: William Douglas <william.r.douglas@gmail.com>
This commit is contained in:
@@ -11,6 +11,7 @@ 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::path::PathBuf;
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::sync::Arc;
|
||||
@@ -253,16 +254,12 @@ fn handle_http_request(
|
||||
response
|
||||
}
|
||||
|
||||
pub fn start_http_thread(
|
||||
path: &str,
|
||||
fn start_http_thread(
|
||||
mut server: HttpServer,
|
||||
api_notifier: EventFd,
|
||||
api_sender: Sender<ApiRequest>,
|
||||
seccomp_action: &SeccompAction,
|
||||
) -> Result<thread::JoinHandle<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::CreateApiServer)?;
|
||||
|
||||
// Retrieve seccomp filter for API thread
|
||||
let api_seccomp_filter =
|
||||
get_seccomp_filter(seccomp_action, Thread::Api).map_err(Error::CreateSeccompFilter)?;
|
||||
@@ -299,3 +296,25 @@ pub fn start_http_thread(
|
||||
})
|
||||
.map_err(Error::HttpThreadSpawn)
|
||||
}
|
||||
|
||||
pub fn start_http_path_thread(
|
||||
path: &str,
|
||||
api_notifier: EventFd,
|
||||
api_sender: Sender<ApiRequest>,
|
||||
seccomp_action: &SeccompAction,
|
||||
) -> 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)?;
|
||||
start_http_thread(server, api_notifier, api_sender, seccomp_action)
|
||||
}
|
||||
|
||||
pub fn start_http_fd_thread(
|
||||
fd: RawFd,
|
||||
api_notifier: EventFd,
|
||||
api_sender: Sender<ApiRequest>,
|
||||
seccomp_action: &SeccompAction,
|
||||
) -> Result<thread::JoinHandle<Result<()>>> {
|
||||
let server = HttpServer::new_from_fd(fd).map_err(Error::CreateApiServer)?;
|
||||
start_http_thread(server, api_notifier, api_sender, seccomp_action)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
extern crate vm_device;
|
||||
extern crate vmm_sys_util;
|
||||
|
||||
pub use self::http::start_http_thread;
|
||||
pub use self::http::start_http_fd_thread;
|
||||
pub use self::http::start_http_path_thread;
|
||||
|
||||
pub mod http;
|
||||
pub mod http_endpoint;
|
||||
|
||||
Reference in New Issue
Block a user