add comment
This commit is contained in:
parent
fbdb6e8ea0
commit
a9f31dd95c
|
@ -13,7 +13,7 @@ use nu_protocol::{Category, Example, ListStream, PipelineData, RawStream, Span,
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use nu_engine::CallExt;
|
use nu_engine::CallExt;
|
||||||
use nu_system::external_process_setup::{reset_foreground_id, set_foreground, setup_fg_external};
|
use nu_system::external_process_setup::{reset_foreground_id, set_foreground, prepare_to_foreground};
|
||||||
use pathdiff::diff_paths;
|
use pathdiff::diff_paths;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ impl ExternalCommand {
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
{
|
{
|
||||||
setup_fg_external(&mut process);
|
prepare_to_foreground(&mut process);
|
||||||
child = process.spawn()
|
child = process.spawn()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
pub mod external_process_setup {
|
pub mod external_process_setup {
|
||||||
use std::os::unix::prelude::CommandExt;
|
use std::os::unix::prelude::CommandExt;
|
||||||
pub fn setup_fg_external(external_command: &mut std::process::Command) {
|
pub fn prepare_to_foreground(external_command: &mut std::process::Command) {
|
||||||
unsafe {
|
unsafe {
|
||||||
libc::signal(libc::SIGTTOU, libc::SIG_IGN);
|
libc::signal(libc::SIGTTOU, libc::SIG_IGN);
|
||||||
libc::signal(libc::SIGTTIN, libc::SIG_IGN);
|
libc::signal(libc::SIGTTIN, libc::SIG_IGN);
|
||||||
|
@ -14,18 +14,24 @@ pub mod external_process_setup {
|
||||||
// make the command startup with new process group.
|
// make the command startup with new process group.
|
||||||
// The process group id must be the same as external commands' pid.
|
// The process group id must be the same as external commands' pid.
|
||||||
// Or else we'll failed to set it as foreground process.
|
// Or else we'll failed to set it as foreground process.
|
||||||
|
// For more information, refer to `fork_child_for_process` function:
|
||||||
|
// https://github.com/fish-shell/fish-shell/blob/023042098396aa450d2c4ea1eb9341312de23126/src/exec.cpp#L398
|
||||||
libc::setpgid(0, 0);
|
libc::setpgid(0, 0);
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Before call this function, `prepare_to_foreground` function must be called. Or else
|
||||||
|
/// it'll failed with silence.
|
||||||
pub fn set_foreground(process: &std::process::Child) {
|
pub fn set_foreground(process: &std::process::Child) {
|
||||||
unsafe {
|
unsafe {
|
||||||
libc::tcsetpgrp(libc::STDIN_FILENO, process.id() as i32);
|
libc::tcsetpgrp(libc::STDIN_FILENO, process.id() as i32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// It can only be called when you have called `set_foreground`, or else
|
||||||
|
/// Something strange will happened.
|
||||||
pub fn reset_foreground_id() {
|
pub fn reset_foreground_id() {
|
||||||
unsafe {
|
unsafe {
|
||||||
libc::tcsetpgrp(libc::STDIN_FILENO, libc::getpgrp());
|
libc::tcsetpgrp(libc::STDIN_FILENO, libc::getpgrp());
|
||||||
|
@ -35,6 +41,7 @@ pub mod external_process_setup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: investigate if we can set foreground process through windows system call.
|
||||||
#[cfg(target_family = "windows")]
|
#[cfg(target_family = "windows")]
|
||||||
mod external_process_setup {
|
mod external_process_setup {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user