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

Method signal_handler

vmm/src/lib.rs:699–731  ·  view source on GitHub ↗
(
        mut signals: Signals,
        original_termios_opt: &Mutex<Option<termios>>,
        exit_evt: &EventFd,
    )

Source from the content-addressed store, hash-verified

697 pub const HANDLED_SIGNALS: [i32; 2] = [SIGTERM, SIGINT];
698
699 fn signal_handler(
700 mut signals: Signals,
701 original_termios_opt: &Mutex<Option<termios>>,
702 exit_evt: &EventFd,
703 ) {
704 for sig in &Self::HANDLED_SIGNALS {
705 unblock_signal(*sig).unwrap();
706 }
707
708 for signal in signals.forever() {
709 match signal {
710 #[allow(clippy::collapsible_match)]
711 SIGTERM | SIGINT => {
712 if exit_evt.write(1).is_err() {
713 // Resetting the terminal is usually done as the VMM exits
714 if let Ok(lock) = original_termios_opt.lock() {
715 if let Some(termios) = *lock {
716 // SAFETY: FFI call
717 let _ = unsafe {
718 tcsetattr(stdout().lock().as_raw_fd(), TCSANOW, &termios)
719 };
720 }
721 } else {
722 warn!("Failed to lock original termios");
723 }
724
725 std::process::exit(1);
726 }
727 }
728 _ => (),
729 }
730 }
731 }
732
733 fn setup_signal_handler(&mut self, landlock_enable: bool) -> Result<()> {
734 let signals = Signals::new(Self::HANDLED_SIGNALS);

Callers

nothing calls this directly

Calls 2

writeMethod · 0.45
as_raw_fdMethod · 0.45

Tested by

no test coverage detected