From d784bf0c75254ecefa003d2b4f6d566a349b8ff7 Mon Sep 17 00:00:00 2001 From: Praveen K Paladugu Date: Tue, 30 Apr 2024 19:36:57 +0000 Subject: [PATCH] vmm: move listen_for_sigwinch_on_tty method Move listen_for_sigwinch_on_tty to sigwinch_listener.rs module. Signed-off-by: Praveen K Paladugu --- vmm/src/device_manager.rs | 35 ++++++++++++++++------------------- vmm/src/sigwinch_listener.rs | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index df69adc16..eb525c602 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -20,9 +20,8 @@ use crate::interrupt::LegacyUserspaceInterruptManager; use crate::interrupt::MsiInterruptManager; use crate::memory_manager::{Error as MemoryManagerError, MemoryManager, MEMORY_MANAGER_ACPI_SIZE}; use crate::pci_segment::PciSegment; -use crate::seccomp_filters::{get_seccomp_filter, Thread}; use crate::serial_manager::{Error as SerialManagerError, SerialManager}; -use crate::sigwinch_listener::start_sigwinch_listener; +use crate::sigwinch_listener::listen_for_sigwinch_on_tty; use crate::vm_config::DEFAULT_PCI_SEGMENT_APERTURE_WEIGHT; use crate::GuestRegionMmap; use crate::PciDeviceInfo; @@ -494,6 +493,9 @@ pub enum DeviceManagerError { /// Cannot create a RateLimiterGroup RateLimiterGroupCreate(rate_limiter::group::Error), + + /// Cannot start sigwinch listener + StartSigwinchListener(std::io::Error), } pub type DeviceManagerResult = result::Result; @@ -1973,20 +1975,6 @@ impl DeviceManager { Ok(serial) } - fn listen_for_sigwinch_on_tty(&mut self, pty_sub: File) -> std::io::Result<()> { - let seccomp_filter = get_seccomp_filter( - &self.seccomp_action, - Thread::PtyForeground, - self.hypervisor_type, - ) - .unwrap(); - - self.console_resize_pipe = - Some(Arc::new(start_sigwinch_listener(seccomp_filter, pty_sub)?)); - - Ok(()) - } - fn add_virtio_console_device( &mut self, virtio_devices: &mut Vec, @@ -2015,7 +2003,10 @@ impl DeviceManager { self.config.lock().unwrap().console.file = Some(path.clone()); let file = main.try_clone().unwrap(); assert!(resize_pipe.is_none()); - self.listen_for_sigwinch_on_tty(sub).unwrap(); + self.console_resize_pipe = Some(Arc::new( + listen_for_sigwinch_on_tty(sub, &self.seccomp_action, self.hypervisor_type) + .map_err(DeviceManagerError::StartSigwinchListener)?, + )); self.console_pty = Some(Arc::new(Mutex::new(PtyPair { main, path }))); Endpoint::PtyPair(file.try_clone().unwrap(), file) } @@ -2037,8 +2028,14 @@ impl DeviceManager { // SAFETY: FFI call. Trivially safe. if unsafe { libc::isatty(libc::STDOUT_FILENO) } == 1 { - self.listen_for_sigwinch_on_tty(stdout.try_clone().unwrap()) - .unwrap(); + self.console_resize_pipe = Some(Arc::new( + listen_for_sigwinch_on_tty( + stdout.try_clone().unwrap(), + &self.seccomp_action, + self.hypervisor_type, + ) + .map_err(DeviceManagerError::StartSigwinchListener)?, + )); } // If an interactive TTY then we can accept input diff --git a/vmm/src/sigwinch_listener.rs b/vmm/src/sigwinch_listener.rs index 716bf2c61..08137aa53 100644 --- a/vmm/src/sigwinch_listener.rs +++ b/vmm/src/sigwinch_listener.rs @@ -2,13 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 use crate::clone3::{clone3, clone_args, CLONE_CLEAR_SIGHAND}; +use crate::seccomp_filters::{get_seccomp_filter, Thread}; use arch::_NSIG; +use hypervisor::HypervisorType; use libc::{ c_int, c_void, close, fork, getpgrp, ioctl, pipe2, poll, pollfd, setsid, sigemptyset, siginfo_t, signal, sigprocmask, syscall, tcgetpgrp, tcsetpgrp, SYS_close_range, EINVAL, ENOSYS, ENOTTY, O_CLOEXEC, POLLERR, SIGCHLD, SIGWINCH, SIG_DFL, SIG_SETMASK, STDERR_FILENO, TIOCSCTTY, }; -use seccompiler::{apply_filter, BpfProgram}; +use seccompiler::{apply_filter, BpfProgram, SeccompAction}; use std::cell::RefCell; use std::collections::BTreeSet; use std::fs::{read_dir, File}; @@ -256,3 +258,16 @@ pub fn start_sigwinch_listener(seccomp_filter: BpfProgram, tty_sub: File) -> io: Ok(rx) } + +pub fn listen_for_sigwinch_on_tty( + pty_sub: File, + seccomp_action: &SeccompAction, + hypervisor_type: HypervisorType, +) -> std::io::Result { + let seccomp_filter = + get_seccomp_filter(seccomp_action, Thread::PtyForeground, hypervisor_type).unwrap(); + + let console_resize_pipe = start_sigwinch_listener(seccomp_filter, pty_sub)?; + + Ok(console_resize_pipe) +}