Fix leaking fd's

Signed-off-by: Igor Raits <ignatenkobrain@fedoraproject.org>
epel9
Igor Raits 5 years ago
parent e8c833b58c
commit b6ea1a2b09
No known key found for this signature in database
GPG Key ID: 695714BD1BBC5F4C

@ -0,0 +1,60 @@
From 007063896e8b310a6711d7ab780962a9f8ed7283 Mon Sep 17 00:00:00 2001
From: Jonathan Turner <jonathandturner@users.noreply.github.com>
Date: Sat, 22 Feb 2020 19:59:40 +1300
Subject: [PATCH] Automatically close raw fd (#383)
---
src/event.rs | 2 +-
src/terminal/sys/unix.rs | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/event.rs b/src/event.rs
index 71eb3f3..ee2a2eb 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -91,7 +91,7 @@ mod read;
mod source;
#[cfg(feature = "event-stream")]
mod stream;
-mod sys;
+pub(crate) mod sys;
mod timeout;
lazy_static! {
diff --git a/src/terminal/sys/unix.rs b/src/terminal/sys/unix.rs
index b5bd6e4..90fceea 100644
--- a/src/terminal/sys/unix.rs
+++ b/src/terminal/sys/unix.rs
@@ -1,13 +1,13 @@
//! UNIX related logic for terminal manipulation.
use std::{io, mem, process, sync::Mutex};
+use crate::event::sys::unix::file_descriptor::FileDesc;
+use lazy_static::lazy_static;
use libc::{
cfmakeraw, ioctl, tcgetattr, tcsetattr, termios as Termios, winsize, STDIN_FILENO, TCSANOW,
TIOCGWINSZ,
};
-use lazy_static::lazy_static;
-
use crate::error::{ErrorKind, Result};
use std::fs::File;
use std::os::unix::io::IntoRawFd;
@@ -32,10 +32,10 @@ pub(crate) fn size() -> Result<(u16, u16)> {
ws_ypixel: 0,
};
- let file = File::open("/dev/tty").unwrap();
+ let file = File::open("/dev/tty")?;
- if let Ok(true) =
- wrap_with_result(unsafe { ioctl(file.into_raw_fd(), TIOCGWINSZ.into(), &mut size) })
+ let fd = FileDesc::new(file.into_raw_fd(), true);
+ if let Ok(true) = wrap_with_result(unsafe { ioctl(fd.raw_fd(), TIOCGWINSZ.into(), &mut size) })
{
Ok((size.ws_col, size.ws_row))
} else {
--
2.25.1

@ -7,7 +7,7 @@
Name: rust-%{crate} Name: rust-%{crate}
Version: 0.16.0 Version: 0.16.0
Release: 1%{?dist} Release: 2%{?dist}
Summary: Crossplatform terminal library for manipulating terminals Summary: Crossplatform terminal library for manipulating terminals
# Upstream license specification: MIT # Upstream license specification: MIT
@ -17,6 +17,8 @@ Source: %{crates_source}
# Initial patched metadata # Initial patched metadata
# * No windows # * No windows
Patch0: crossterm-fix-metadata.diff Patch0: crossterm-fix-metadata.diff
# https://github.com/crossterm-rs/crossterm/commit/007063896e8b310a6711d7ab780962a9f8ed7283
Patch0001: 0001-Automatically-close-raw-fd-383.patch
ExclusiveArch: %{rust_arches} ExclusiveArch: %{rust_arches}
%if %{__cargo_skip_build} %if %{__cargo_skip_build}
@ -112,6 +114,9 @@ find -type f -exec chmod -x '{}' '+'
%endif %endif
%changelog %changelog
* Thu Mar 19 2020 Igor Raits <ignatenkobrain@fedoraproject.org> - 0.16.0-2
- Fix leaking fd's
* Thu Mar 19 2020 Josh Stone <jistone@redhat.com> - 0.16.0-1 * Thu Mar 19 2020 Josh Stone <jistone@redhat.com> - 0.16.0-1
- Update to 0.16.0 - Update to 0.16.0

Loading…
Cancel
Save