Issue 406: Keep FileDesc alive long enough for ioctl to work (#413)

This commit is contained in:
m-lima 2020-04-09 19:34:45 +02:00 committed by GitHub
parent e61320ef32
commit 1dd20f3ada
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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