From 1dd20f3ada72076a7d4b874b85d061c5958b5ac8 Mon Sep 17 00:00:00 2001 From: m-lima Date: Thu, 9 Apr 2020 19:34:45 +0200 Subject: [PATCH] Issue 406: Keep FileDesc alive long enough for ioctl to work (#413) --- src/terminal/sys/unix.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/terminal/sys/unix.rs b/src/terminal/sys/unix.rs index 9e50e53..13b56bd 100644 --- a/src/terminal/sys/unix.rs +++ b/src/terminal/sys/unix.rs @@ -32,8 +32,9 @@ pub(crate) fn size() -> Result<(u16, u16)> { ws_ypixel: 0, }; - let fd = if let Ok(file) = File::open("/dev/tty") { - FileDesc::new(file.into_raw_fd(), true).raw_fd() + let file = File::open("/dev/tty").map(|file| (FileDesc::new(file.into_raw_fd(), true))); + let fd = if let Ok(file) = &file { + file.raw_fd() } else { // Fallback to libc::STDOUT_FILENO if /dev/tty is missing STDOUT_FILENO