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

Method setup_signal_handler

vmm/src/lib.rs:733–789  ·  view source on GitHub ↗
(&mut self, landlock_enable: bool)

Source from the content-addressed store, hash-verified

731 }
732
733 fn setup_signal_handler(&mut self, landlock_enable: bool) -> Result<()> {
734 let signals = Signals::new(Self::HANDLED_SIGNALS);
735 match signals {
736 Ok(signals) => {
737 self.signals = Some(signals.handle());
738 let exit_evt = self.exit_evt.try_clone().map_err(Error::EventFdClone)?;
739 let original_termios_opt = Arc::clone(&self.original_termios_opt);
740
741 let signal_handler_seccomp_filter = get_seccomp_filter(
742 &self.seccomp_action,
743 Thread::SignalHandler,
744 self.hypervisor.hypervisor_type(),
745 )
746 .map_err(Error::CreateSeccompFilter)?;
747 self.threads.push(
748 thread::Builder::new()
749 .name("vmm_signal_handler".to_string())
750 .spawn(move || {
751 if !signal_handler_seccomp_filter.is_empty() && let Err(e) = apply_filter(&signal_handler_seccomp_filter)
752 .map_err(Error::ApplySeccompFilter)
753 {
754 error!("Error applying seccomp filter: {e:?}");
755 exit_evt.write(1).ok();
756 return;
757 }
758
759 if landlock_enable{
760 match Landlock::new() {
761 Ok(landlock) => {
762 let _ = landlock.restrict_self().map_err(Error::ApplyLandlock).map_err(|e| {
763 error!("Error applying Landlock to signal handler thread: {e:?}");
764 exit_evt.write(1).ok();
765 });
766 }
767 Err(e) => {
768 error!("Error creating Landlock object: {e:?}");
769 exit_evt.write(1).ok();
770 }
771 }
772 }
773
774 std::panic::catch_unwind(AssertUnwindSafe(|| {
775 Vmm::signal_handler(signals, original_termios_opt.as_ref(), &exit_evt);
776 }))
777 .map_err(|_| {
778 error!("vmm signal_handler thread panicked");
779 exit_evt.write(1).ok()
780 })
781 .ok();
782 })
783 .map_err(Error::SignalHandlerSpawn)?,
784 );
785 }
786 Err(e) => error!("Signal not found {e}"),
787 }
788 Ok(())
789 }
790

Callers 1

start_vmm_threadFunction · 0.80

Calls 10

newFunction · 0.85
spawnMethod · 0.80
okMethod · 0.80
restrict_selfMethod · 0.80
get_seccomp_filterFunction · 0.70
try_cloneMethod · 0.45
hypervisor_typeMethod · 0.45
pushMethod · 0.45
is_emptyMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected