mirror of
https://github.com/nushell/nushell.git
synced 2025-08-17 06:41:18 +02:00
add comment
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
#[cfg(target_family = "unix")]
|
||||
pub mod external_process_setup {
|
||||
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 {
|
||||
libc::signal(libc::SIGTTOU, 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.
|
||||
// The process group id must be the same as external commands' pid.
|
||||
// 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);
|
||||
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) {
|
||||
unsafe {
|
||||
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() {
|
||||
unsafe {
|
||||
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")]
|
||||
mod external_process_setup {
|
||||
|
||||
|
Reference in New Issue
Block a user