MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / start_http_thread

Function start_http_thread

vmm/src/api/http/mod.rs:325–405  ·  view source on GitHub ↗
(
    mut server: HttpServer,
    api_notifier: EventFd,
    api_sender: Sender<ApiRequest>,
    seccomp_action: &SeccompAction,
    exit_evt: EventFd,
    hypervisor_type: HypervisorType,
    landloc

Source from the content-addressed store, hash-verified

323}
324
325fn start_http_thread(
326 mut server: HttpServer,
327 api_notifier: EventFd,
328 api_sender: Sender<ApiRequest>,
329 seccomp_action: &SeccompAction,
330 exit_evt: EventFd,
331 hypervisor_type: HypervisorType,
332 landlock_enable: bool,
333) -> Result<HttpApiHandle> {
334 // Retrieve seccomp filter for API thread
335 let api_seccomp_filter = get_seccomp_filter(seccomp_action, Thread::HttpApi, hypervisor_type)
336 .map_err(VmmError::CreateSeccompFilter)?;
337
338 let api_shutdown_fd = EventFd::new(libc::EFD_NONBLOCK).map_err(VmmError::EventFdCreate)?;
339 let api_shutdown_fd_clone = api_shutdown_fd.try_clone().unwrap();
340
341 server
342 .add_kill_switch(api_shutdown_fd_clone)
343 .map_err(VmmError::CreateApiServer)?;
344
345 let thread = thread::Builder::new()
346 .name("http-server".to_string())
347 .spawn(move || {
348 // Apply seccomp filter for API thread.
349 if !api_seccomp_filter.is_empty() {
350 apply_filter(&api_seccomp_filter)
351 .map_err(VmmError::ApplySeccompFilter)
352 .map_err(|e| {
353 error!("Error applying seccomp filter: {e:?}");
354 exit_evt.write(1).ok();
355 e
356 })?;
357 }
358
359 if landlock_enable {
360 Landlock::new()
361 .map_err(VmmError::CreateLandlock)?
362 .restrict_self()
363 .map_err(VmmError::ApplyLandlock)
364 .map_err(|e| {
365 error!("Error applying landlock to http-server thread: {e:?}");
366 exit_evt.write(1).ok();
367 e
368 })?;
369 }
370
371 std::panic::catch_unwind(AssertUnwindSafe(move || {
372 server.start_server().unwrap();
373 loop {
374 match server.requests() {
375 Ok(request_vec) => {
376 for server_request in request_vec {
377 if let Err(e) = server.respond(server_request.process(|request| {
378 handle_http_request(request, &api_notifier, &api_sender)
379 })) {
380 error!("HTTP server error on response: {e}");
381 }
382 }

Callers 2

start_http_path_threadFunction · 0.85
start_http_fd_threadFunction · 0.85

Calls 10

newFunction · 0.85
handle_http_requestFunction · 0.85
spawnMethod · 0.80
okMethod · 0.80
restrict_selfMethod · 0.80
processMethod · 0.80
get_seccomp_filterFunction · 0.50
try_cloneMethod · 0.45
is_emptyMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected