mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
virtio-devices: get tty size from the right tty
Previously, we were always getting the size from stdin, even when the console was hooked up to a pty. Signed-off-by: Alyssa Ross <hi@alyssa.is>
This commit is contained in:
parent
28382a1491
commit
98bfd1e988
@ -293,21 +293,24 @@ impl EpollHelperHandler for ConsoleEpollHandler {
|
|||||||
/// Resize handler
|
/// Resize handler
|
||||||
pub struct ConsoleResizer {
|
pub struct ConsoleResizer {
|
||||||
config_evt: EventFd,
|
config_evt: EventFd,
|
||||||
|
tty: Option<File>,
|
||||||
config: Arc<Mutex<VirtioConsoleConfig>>,
|
config: Arc<Mutex<VirtioConsoleConfig>>,
|
||||||
acked_features: AtomicU64,
|
acked_features: AtomicU64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConsoleResizer {
|
impl ConsoleResizer {
|
||||||
pub fn update_console_size(&self) {
|
pub fn update_console_size(&self) {
|
||||||
if self
|
if let Some(tty) = self.tty.as_ref() {
|
||||||
.acked_features
|
let (cols, rows) = get_win_size(tty);
|
||||||
.fetch_and(1u64 << VIRTIO_CONSOLE_F_SIZE, Ordering::AcqRel)
|
|
||||||
!= 0
|
|
||||||
{
|
|
||||||
let (cols, rows) = get_win_size();
|
|
||||||
self.config.lock().unwrap().update_console_size(cols, rows);
|
self.config.lock().unwrap().update_console_size(cols, rows);
|
||||||
//Send the interrupt to the driver
|
if self
|
||||||
let _ = self.config_evt.write(1);
|
.acked_features
|
||||||
|
.fetch_and(1u64 << VIRTIO_CONSOLE_F_SIZE, Ordering::AcqRel)
|
||||||
|
!= 0
|
||||||
|
{
|
||||||
|
// Send the interrupt to the driver
|
||||||
|
let _ = self.config_evt.write(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -339,7 +342,7 @@ pub struct ConsoleState {
|
|||||||
in_buffer: Vec<u8>,
|
in_buffer: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_win_size() -> (u16, u16) {
|
fn get_win_size(tty: &dyn AsRawFd) -> (u16, u16) {
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct WindowSize {
|
struct WindowSize {
|
||||||
@ -351,7 +354,7 @@ fn get_win_size() -> (u16, u16) {
|
|||||||
let ws: WindowSize = WindowSize::default();
|
let ws: WindowSize = WindowSize::default();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
libc::ioctl(0, TIOCGWINSZ, &ws);
|
libc::ioctl(tty.as_raw_fd(), TIOCGWINSZ, &ws);
|
||||||
}
|
}
|
||||||
|
|
||||||
(ws.cols, ws.rows)
|
(ws.cols, ws.rows)
|
||||||
@ -379,6 +382,7 @@ impl Console {
|
|||||||
let resizer = Arc::new(ConsoleResizer {
|
let resizer = Arc::new(ConsoleResizer {
|
||||||
config_evt,
|
config_evt,
|
||||||
config: console_config.clone(),
|
config: console_config.clone(),
|
||||||
|
tty: endpoint.out_file().as_ref().map(|t| t.try_clone().unwrap()),
|
||||||
acked_features: AtomicU64::new(0),
|
acked_features: AtomicU64::new(0),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user