Fix for lost clipboard contents (#5424) (#5426)

* Fix for lost clipboard contents (#5424)

* PR feedback: Call "setsid" for all unix systems

* PR Feedback: Only install libc for unix targets
pull/5543/merge
gavynriebau 2 years ago committed by GitHub
parent b6331394a3
commit cce19713fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
Cargo.lock generated

@ -1274,6 +1274,7 @@ dependencies = [
"helix-lsp", "helix-lsp",
"helix-tui", "helix-tui",
"helix-vcs", "helix-vcs",
"libc",
"log", "log",
"once_cell", "once_cell",
"serde", "serde",

@ -48,5 +48,8 @@ which = "4.2"
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
clipboard-win = { version = "4.5", features = ["std"] } clipboard-win = { version = "4.5", features = ["std"] }
[target.'cfg(unix)'.dependencies]
libc = "0.2"
[dev-dependencies] [dev-dependencies]
helix-tui = { path = "../helix-tui" } helix-tui = { path = "../helix-tui" }

@ -276,12 +276,27 @@ pub mod provider {
let stdin = input.map(|_| Stdio::piped()).unwrap_or_else(Stdio::null); let stdin = input.map(|_| Stdio::piped()).unwrap_or_else(Stdio::null);
let stdout = pipe_output.then(Stdio::piped).unwrap_or_else(Stdio::null); let stdout = pipe_output.then(Stdio::piped).unwrap_or_else(Stdio::null);
let mut child = Command::new(self.prg) let mut command: Command = Command::new(self.prg);
let mut command_mut: &mut Command = command
.args(self.args) .args(self.args)
.stdin(stdin) .stdin(stdin)
.stdout(stdout) .stdout(stdout)
.stderr(Stdio::null()) .stderr(Stdio::null());
.spawn()?;
// Fix for https://github.com/helix-editor/helix/issues/5424
if cfg!(unix) {
use std::os::unix::process::CommandExt;
unsafe {
command_mut = command_mut.pre_exec(|| match libc::setsid() {
-1 => Err(std::io::Error::last_os_error()),
_ => Ok(()),
});
}
}
let mut child = command_mut.spawn()?;
if let Some(input) = input { if let Some(input) = input {
let mut stdin = child.stdin.take().context("stdin is missing")?; let mut stdin = child.stdin.take().context("stdin is missing")?;

Loading…
Cancel
Save