Skip to content

Commit 7f7fb3d

Browse files
authored
Try #101:
2 parents 59213cd + 2e292c1 commit 7f7fb3d

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
uses: dtolnay/rust-toolchain@master
2727
with:
2828
toolchain: ${{ matrix.rust }}
29-
- uses: swatinem/rust-cache@v1
29+
- uses: swatinem/rust-cache@v2
3030
- name: cargo-check
3131
uses: actions-rs/cargo@v1
3232
with:
@@ -51,7 +51,7 @@ jobs:
5151
uses: dtolnay/rust-toolchain@master
5252
with:
5353
toolchain: ${{ matrix.rust }}
54-
- uses: swatinem/rust-cache@v1
54+
- uses: swatinem/rust-cache@v2
5555
- name: cargo-test
5656
uses: actions-rs/cargo@v1
5757
with:
@@ -107,7 +107,7 @@ jobs:
107107
with:
108108
toolchain: 1.67.0
109109
components: clippy
110-
- uses: swatinem/rust-cache@v1
110+
- uses: swatinem/rust-cache@v2
111111
- name: cargo-clippy
112112
run: cargo clippy --all --all-targets --all-features
113113

src/process.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use crate::error::Error;
44
use nix;
55
use nix::fcntl::{open, OFlag};
6+
use nix::libc::{ioctl, TIOCSCTTY};
67
use nix::libc::{STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};
78
use nix::pty::{grantpt, posix_openpt, unlockpt, PtyMaster};
89
pub use nix::sys::{signal, wait};
@@ -86,7 +87,7 @@ impl PtyProcess {
8687
/// Start a process in a forked pty
8788
pub fn new(mut command: Command) -> Result<Self, Error> {
8889
// Open a new PTY master
89-
let master_fd = posix_openpt(OFlag::O_RDWR)?;
90+
let master_fd = posix_openpt(OFlag::O_RDWR | OFlag::O_NOCTTY)?;
9091

9192
// Allow a slave to be generated for it
9293
grantpt(&master_fd)?;
@@ -112,16 +113,31 @@ impl PtyProcess {
112113
dup2(slave_fd, STDOUT_FILENO)?;
113114
dup2(slave_fd, STDERR_FILENO)?;
114115

116+
unsafe {
117+
match ioctl(master_fd.as_raw_fd(), TIOCSCTTY) {
118+
0 => Ok(()),
119+
_ => Err(nix::Error::last()),
120+
}?;
121+
}
122+
115123
// Avoid leaking slave fd
116124
if slave_fd > STDERR_FILENO {
117125
close(slave_fd)?;
118126
}
119127

120128
// set echo off
121129
let mut flags = termios::tcgetattr(STDIN_FILENO)?;
122-
flags.local_flags &= !termios::LocalFlags::ECHO;
130+
flags.local_flags.remove(termios::LocalFlags::ECHO);
123131
termios::tcsetattr(STDIN_FILENO, termios::SetArg::TCSANOW, &flags)?;
124132

133+
loop {
134+
flags = termios::tcgetattr(STDIN_FILENO)?;
135+
if !flags.local_flags.contains(termios::LocalFlags::ECHO) {
136+
break;
137+
}
138+
std::thread::sleep(std::time::Duration::from_millis(100));
139+
}
140+
125141
command.exec();
126142
Err(Error::Nix(nix::Error::last()))
127143
}

0 commit comments

Comments
 (0)