1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-25 14:05:41 -05:00

Fix IO safety violation from consequent dropping OwnedFd

This was not a _real_ violation and was _expected_, though for rust
to not complain clone FD properly...
This commit is contained in:
Jakob Hellermann 2024-05-23 16:03:28 +02:00 committed by GitHub
parent f04b16161b
commit e9d4ac2a6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,10 +5,10 @@ use std::fs::File;
use std::io::{Error, ErrorKind, Read, Result}; use std::io::{Error, ErrorKind, Read, Result};
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
use std::os::fd::OwnedFd; use std::os::fd::OwnedFd;
use std::os::unix::io::{AsRawFd, FromRawFd}; use std::os::unix::io::AsRawFd;
use std::os::unix::net::UnixStream; use std::os::unix::net::UnixStream;
use std::os::unix::process::CommandExt; use std::os::unix::process::CommandExt;
use std::process::{Child, Command, Stdio}; use std::process::{Child, Command};
use std::sync::Arc; use std::sync::Arc;
use std::{env, ptr}; use std::{env, ptr};
@ -212,12 +212,9 @@ pub fn from_fd(config: &Options, window_id: u64, master: OwnedFd, slave: OwnedFd
}; };
// Setup child stdin/stdout/stderr as slave fd of PTY. // Setup child stdin/stdout/stderr as slave fd of PTY.
// Ownership of fd is transferred to the Stdio structs and will be closed by them at the end of builder.stdin(slave.try_clone()?);
// this scope. (It is not an issue that the fd is closed three times since File::drop ignores builder.stderr(slave.try_clone()?);
// error on libc::close.). builder.stdout(slave);
builder.stdin(unsafe { Stdio::from_raw_fd(slave_fd) });
builder.stderr(unsafe { Stdio::from_raw_fd(slave_fd) });
builder.stdout(unsafe { Stdio::from_raw_fd(slave_fd) });
// Setup shell environment. // Setup shell environment.
let window_id = window_id.to_string(); let window_id = window_id.to_string();