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 <prapal@linux.microsoft.com>
This commit is contained in:
Praveen K Paladugu 2024-04-30 19:36:57 +00:00 committed by Rob Bradford
parent cf6115a73c
commit d784bf0c75
2 changed files with 32 additions and 20 deletions

View File

@ -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<T> = result::Result<T, DeviceManagerError>;
@ -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<MetaVirtioDevice>,
@ -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

View File

@ -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<File> {
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)
}