Skip to content

Commit

Permalink
apple patch by @AppleSheeple
Browse files Browse the repository at this point in the history
  • Loading branch information
squell committed Jun 21, 2024
1 parent 90e2385 commit 4a7d298
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/exec/use_pty/pipe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
};

use crate::exec::event::{EventHandle, EventRegistry, PollEvent, Process};
use crate::log::dev_warn;

use self::ring_buffer::RingBuffer;

Expand Down Expand Up @@ -58,6 +59,19 @@ impl<L: Read + Write + AsRawFd, R: Read + Write + AsRawFd> Pipe<L, R> {
&self.right
}

pub(super) fn tty_gone<T: Process>(&mut self, registry: &mut EventRegistry<T>) -> bool {
let gone = unsafe {
// Check if tty which existed is now gone.
// NOTE: errno set is EIO which is not a documented possibility.
libc::tcgetsid(self.left.as_raw_fd()) == -1
};
if gone {
dev_warn!("tty gone (closed/detached), ignoring future events");
self.ignore_events(registry);
}
gone
}

Check warning on line 73 in src/exec/use_pty/pipe/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/exec/use_pty/pipe/mod.rs#L62-L73

Added lines #L62 - L73 were not covered by tests

/// Stop the poll events of this pipe.
pub(super) fn ignore_events<T: Process>(&mut self, registry: &mut EventRegistry<T>) {
self.buffer_lr.read_handle.ignore(registry);
Expand All @@ -80,6 +94,9 @@ impl<L: Read + Write + AsRawFd, R: Read + Write + AsRawFd> Pipe<L, R> {
poll_event: PollEvent,
registry: &mut EventRegistry<T>,
) -> io::Result<()> {
if self.tty_gone(registry) {
return Ok(());
}

Check warning on line 99 in src/exec/use_pty/pipe/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/exec/use_pty/pipe/mod.rs#L97-L99

Added lines #L97 - L99 were not covered by tests
match poll_event {
PollEvent::Readable => self.buffer_lr.read(&mut self.left, registry),
PollEvent::Writable => self.buffer_rl.write(&mut self.left, registry),
Expand Down

0 comments on commit 4a7d298

Please sign in to comment.