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

Function start_vmm

cloud-hypervisor/src/main.rs:505–780  ·  view source on GitHub ↗
(
    cmd_arguments: &ArgMatches,
    api_socket_path: &Option<String>,
    api_socket_fd: Option<RawFd>,
)

Source from the content-addressed store, hash-verified

503}
504
505fn start_vmm(
506 cmd_arguments: &ArgMatches,
507 api_socket_path: &Option<String>,
508 api_socket_fd: Option<RawFd>,
509) -> Result<(), Error> {
510 let log_level = match cmd_arguments.get_count("v") {
511 0 => LevelFilter::Warn,
512 1 => LevelFilter::Info,
513 2 => LevelFilter::Debug,
514 _ => LevelFilter::Trace,
515 };
516
517 let log_file: Box<dyn std::io::Write + Send> = if let Some(ref file) =
518 cmd_arguments.get_one::<String>("log-file")
519 {
520 Box::new(std::fs::File::create(std::path::Path::new(file)).map_err(Error::LogFileCreation)?)
521 } else {
522 Box::new(std::io::stderr())
523 };
524
525 let format = cmd_arguments.get_one::<String>("log-format").unwrap();
526 let logger = Logger::new(log_file, format).map_err(Error::LoggerFormat)?;
527 log::set_boxed_logger(Box::new(logger))
528 .map(|()| log::set_max_level(log_level))
529 .map_err(Error::LoggerSetup)?;
530
531 let (api_request_sender, api_request_receiver) = channel();
532 let api_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::CreateApiEventFd)?;
533
534 let api_request_sender_clone = api_request_sender.clone();
535 let seccomp_action = if let Some(seccomp_value) = cmd_arguments.get_one::<String>("seccomp") {
536 match seccomp_value as &str {
537 "true" => SeccompAction::Trap,
538 "false" => SeccompAction::Allow,
539 "log" => SeccompAction::Log,
540 val => {
541 // The user providing an invalid value will be rejected
542 panic!("Invalid parameter {val} for \"--seccomp\" flag");
543 }
544 }
545 } else {
546 SeccompAction::Trap
547 };
548
549 if seccomp_action == SeccompAction::Trap {
550 // SAFETY: We only using signal_hook for managing signals and only execute signal
551 // handler safe functions (writing to stderr) and manipulating signals.
552 unsafe {
553 signal_hook::low_level::register(signal_hook::consts::SIGSYS, || {
554 eprintln!(
555 "\n==== Possible seccomp violation ====\n\
556 Try running with `strace -ff` to identify the cause and open an issue: \
557 https://github.com/cloud-hypervisor/cloud-hypervisor/issues/new"
558 );
559 signal_hook::low_level::emulate_default_handler(SIGSYS).unwrap();
560 })
561 }
562 .map_err(|e| error!("Error adding SIGSYS signal handler: {e}"))

Callers 1

mainFunction · 0.85

Calls 15

newFunction · 0.85
createFunction · 0.85
registerFunction · 0.85
set_monitorFunction · 0.85
start_vmm_threadFunction · 0.85
okMethod · 0.80
addMethod · 0.80
is_setMethod · 0.80
convertMethod · 0.80

Tested by

no test coverage detected