Skip to content

Commit 5c858a6

Browse files
committed
nix 0.30
1 parent be7f1ab commit 5c858a6

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ which = ["dep:which"]
117117

118118
[dependencies]
119119
comma = "1.0"
120-
nix = { version = "0.29", features = ["fs", "process", "signal", "term"] }
120+
nix = { version = "0.30", features = ["fs", "process", "signal", "term"] }
121121
regex = "1"
122122
tempfile = "3"
123123
thiserror = "2.0.0"

src/process.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
use crate::error::Error;
44
use nix;
55
use nix::fcntl::{open, OFlag};
6-
use nix::libc::{STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};
6+
use nix::libc::STDERR_FILENO;
77
use nix::pty::{grantpt, posix_openpt, unlockpt, PtyMaster};
88
pub use nix::sys::{signal, wait};
99
use nix::sys::{stat, termios};
10-
use nix::unistd::{close, dup, dup2, fork, setsid, ForkResult, Pid};
10+
use nix::unistd::{
11+
close, dup, dup2_stderr, dup2_stdin, dup2_stdout, fork, setsid, ForkResult, Pid,
12+
};
1113
use std;
1214
use std::fs::File;
1315
use std::io;
14-
use std::os::unix::io::{AsRawFd, FromRawFd};
16+
use std::os::unix::io::AsRawFd;
1517
use std::os::unix::process::CommandExt;
1618
use std::process::Command;
1719
use std::{thread, time};
@@ -109,12 +111,12 @@ impl PtyProcess {
109111
)?;
110112

111113
// assign stdin, stdout, stderr to the tty, just like a terminal does
112-
dup2(slave_fd, STDIN_FILENO)?;
113-
dup2(slave_fd, STDOUT_FILENO)?;
114-
dup2(slave_fd, STDERR_FILENO)?;
114+
dup2_stdin(&slave_fd)?;
115+
dup2_stdout(&slave_fd)?;
116+
dup2_stderr(&slave_fd)?;
115117

116118
// Avoid leaking slave fd
117-
if slave_fd > STDERR_FILENO {
119+
if slave_fd.as_raw_fd() > STDERR_FILENO {
118120
close(slave_fd)?;
119121
}
120122

@@ -138,8 +140,8 @@ impl PtyProcess {
138140
/// Get handle to pty fork for reading/writing
139141
pub fn get_file_handle(&self) -> Result<File, Error> {
140142
// needed because otherwise fd is closed both by dropping process and reader/writer
141-
let fd = dup(self.pty.as_raw_fd())?;
142-
unsafe { Ok(File::from_raw_fd(fd)) }
143+
let fd = dup(&self.pty)?;
144+
Ok(fd.into())
143145
}
144146

145147
/// At the drop of `PtyProcess` the running process is killed. This is blocking forever if

0 commit comments

Comments
 (0)