Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Update to nix 0.17. #2

Merged
merged 2 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keywords = ["terminal", "tui"]

[dependencies]
ndarray = "0.8"
nix = "0.8"
nix = "0.17"
raw_tty = "0.1"
smallvec = "0.3"
termion = "1.5"
Expand Down
10 changes: 6 additions & 4 deletions src/base/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use std::io::{StdoutLock, Write};
use std::os::unix::io::AsRawFd;
use termion;

use nix::sys::signal::{kill, pthread_sigmask, SigSet, SigmaskHow, SIGCONT, SIGTSTP};
use nix::sys::signal::{killpg, pthread_sigmask, SigSet, SigmaskHow, SIGCONT, SIGTSTP};
use nix::unistd::getpgrp;

/// A type providing an interface to the underlying physical terminal.
Expand Down Expand Up @@ -84,15 +84,17 @@ impl<'a, T: Write + AsRawFd> Terminal<'a, T> {
stop_and_cont.add(SIGTSTP);

// 1. Unblock SIGTSTP and SIGCONT, so that we actually stop when we receive another SIGTSTP
pthread_sigmask(SigmaskHow::SIG_UNBLOCK, Some(&stop_and_cont), None)?;
pthread_sigmask(SigmaskHow::SIG_UNBLOCK, Some(&stop_and_cont), None)
.map_err(|e| e.as_errno().expect("Only expecting io errors"))?;

// 2. Reissue SIGTSTP (this time to whole the process group!)...
kill(-getpgrp(), SIGTSTP)?;
killpg(getpgrp(), SIGTSTP).map_err(|e| e.as_errno().expect("Only expecting io errors"))?;
// ... and stop!
// Now we are waiting for a SIGCONT.

// 3. Once we receive a SIGCONT we block SIGTSTP and SIGCONT again and resume.
pthread_sigmask(SigmaskHow::SIG_BLOCK, Some(&stop_and_cont), None)?;
pthread_sigmask(SigmaskHow::SIG_BLOCK, Some(&stop_and_cont), None)
.map_err(|e| e.as_errno().expect("Only expecting io errors"))?;

self.enter_tui()
}
Expand Down