Skip to content

Commit

Permalink
Merge pull request #845 from memorysafety/cpu
Browse files Browse the repository at this point in the history
Fix high CPU usage
  • Loading branch information
pvdrz committed Jun 25, 2024
2 parents 3b09b4c + 4e6e916 commit 13527c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/exec/use_pty/parent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,13 @@ impl Process for ParentClosure {
match event {
ParentEvent::Signal => self.on_signal(registry),
ParentEvent::Tty(poll_event) => {
self.tty_pipe.on_left_event(poll_event, registry).ok();
// Check if tty which existed is now gone.
if self.tty_pipe.left().tcgetsid().is_err() {
dev_warn!("tty gone (closed/detached), ignoring future events");
self.tty_pipe.ignore_events(registry);
} else {
self.tty_pipe.on_left_event(poll_event, registry).ok();
}
}
ParentEvent::Pty(poll_event) => {
self.tty_pipe.on_right_event(poll_event, registry).ok();
Expand Down
5 changes: 5 additions & 0 deletions src/system/term/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ pub(crate) trait Terminal: sealed::Sealed {
fn make_controlling_terminal(&self) -> io::Result<()>;
fn ttyname(&self) -> io::Result<OsString>;
fn is_terminal(&self) -> bool;
fn tcgetsid(&self) -> io::Result<ProcessId>;
}

impl<F: AsRawFd> Terminal for F {
Expand Down Expand Up @@ -179,6 +180,10 @@ impl<F: AsRawFd> Terminal for F {
fn is_terminal(&self) -> bool {
safe_isatty(self.as_raw_fd())
}

fn tcgetsid(&self) -> io::Result<ProcessId> {
cerr(unsafe { libc::tcgetsid(self.as_raw_fd()) })
}
}

/// Try to get the path of the current TTY
Expand Down

0 comments on commit 13527c1

Please sign in to comment.