embedded: prevent double-close of pty fd

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/468/head
Manos Pitsidianakis 2 months ago
parent eda6620cb4
commit 35f12b1551
No known key found for this signature in database
GPG Key ID: 7729C7707F7E09D0

@ -23,6 +23,7 @@
use std::os::fd::OwnedFd;
use std::{
ffi::{CString, OsStr},
mem::ManuallyDrop,
os::unix::{
ffi::OsStrExt,
io::{AsRawFd, FromRawFd, IntoRawFd},
@ -178,7 +179,8 @@ pub fn create_pty(width: usize, height: usize, command: &str) -> Result<Arc<Mute
};
let stdin = unsafe { std::fs::File::from_raw_fd(frontend_fd.as_raw_fd()) };
let mut embedded_pty = Terminal::new(stdin, child_pid);
// We will let the spawned thread close frontend_fd
let mut embedded_pty = Terminal::new(ManuallyDrop::new(stdin), child_pid);
embedded_pty.set_terminal_size((width, height));
let pty = Arc::new(Mutex::new(embedded_pty));
let pty_ = pty.clone();

@ -70,7 +70,7 @@ enum CodepointBuf {
#[derive(Debug)]
pub struct Terminal {
pub grid: EmbeddedGrid,
stdin: std::fs::File,
stdin: std::mem::ManuallyDrop<std::fs::File>,
/// Pid of the embedded process
pub child_pid: nix::unistd::Pid,
}
@ -114,7 +114,7 @@ impl std::io::Write for Terminal {
}
impl Terminal {
pub fn new(stdin: std::fs::File, child_pid: nix::unistd::Pid) -> Self {
pub fn new(stdin: std::mem::ManuallyDrop<std::fs::File>, child_pid: nix::unistd::Pid) -> Self {
Self {
grid: EmbeddedGrid::new(),
stdin,

Loading…
Cancel
Save