mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 11:48:13 +01:00
Use OwnedFd with NullTty
This commit is contained in:
@@ -3,7 +3,6 @@ use crate::tty::Tty;
|
|||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use nix::errno::Errno;
|
use nix::errno::Errno;
|
||||||
use nix::sys::select::{select, FdSet};
|
use nix::sys::select::{select, FdSet};
|
||||||
use nix::unistd::pipe;
|
|
||||||
use nix::{libc, pty, sys::signal, sys::wait, unistd, unistd::ForkResult};
|
use nix::{libc, pty, sys::signal, sys::wait, unistd, unistd::ForkResult};
|
||||||
use signal_hook::consts::{SIGHUP, SIGINT, SIGQUIT, SIGTERM, SIGWINCH};
|
use signal_hook::consts::{SIGHUP, SIGINT, SIGQUIT, SIGTERM, SIGWINCH};
|
||||||
use signal_hook::SigId;
|
use signal_hook::SigId;
|
||||||
@@ -316,7 +315,7 @@ struct SignalFd {
|
|||||||
|
|
||||||
impl SignalFd {
|
impl SignalFd {
|
||||||
fn open(signal: libc::c_int) -> Result<Self> {
|
fn open(signal: libc::c_int) -> Result<Self> {
|
||||||
let (rx, tx) = pipe()?;
|
let (rx, tx) = unistd::pipe()?;
|
||||||
set_non_blocking(&rx)?;
|
set_non_blocking(&rx)?;
|
||||||
set_non_blocking(&tx)?;
|
set_non_blocking(&tx)?;
|
||||||
let rx = unsafe { OwnedFd::from_raw_fd(rx) };
|
let rx = unsafe { OwnedFd::from_raw_fd(rx) };
|
||||||
|
|||||||
10
src/tty.rs
10
src/tty.rs
@@ -2,7 +2,7 @@ use anyhow::Result;
|
|||||||
use nix::{libc, pty, unistd};
|
use nix::{libc, pty, unistd};
|
||||||
use std::{
|
use std::{
|
||||||
fs, io,
|
fs, io,
|
||||||
os::fd::{AsFd, AsRawFd, BorrowedFd},
|
os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd},
|
||||||
};
|
};
|
||||||
use termion::raw::{IntoRawMode, RawTerminal};
|
use termion::raw::{IntoRawMode, RawTerminal};
|
||||||
|
|
||||||
@@ -66,13 +66,15 @@ impl AsFd for DevTty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct NullTty {
|
pub struct NullTty {
|
||||||
tx: i32,
|
tx: OwnedFd,
|
||||||
_rx: i32,
|
_rx: OwnedFd,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NullTty {
|
impl NullTty {
|
||||||
pub fn open() -> Result<Self> {
|
pub fn open() -> Result<Self> {
|
||||||
let (rx, tx) = unistd::pipe()?;
|
let (rx, tx) = unistd::pipe()?;
|
||||||
|
let rx = unsafe { OwnedFd::from_raw_fd(rx) };
|
||||||
|
let tx = unsafe { OwnedFd::from_raw_fd(tx) };
|
||||||
|
|
||||||
Ok(Self { tx, _rx: rx })
|
Ok(Self { tx, _rx: rx })
|
||||||
}
|
}
|
||||||
@@ -107,6 +109,6 @@ impl io::Write for NullTty {
|
|||||||
|
|
||||||
impl AsFd for NullTty {
|
impl AsFd for NullTty {
|
||||||
fn as_fd(&self) -> BorrowedFd<'_> {
|
fn as_fd(&self) -> BorrowedFd<'_> {
|
||||||
unsafe { BorrowedFd::borrow_raw(self.tx.as_raw_fd()) }
|
self.tx.as_fd()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user