From fbdb6e8ea02c88e5ed1a39edb14a514d78f72a89 Mon Sep 17 00:00:00 2001 From: WindSoilder Date: Mon, 1 Aug 2022 18:51:20 +0800 Subject: [PATCH] add comment, make var more readable --- crates/nu-system/src/foreground.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/nu-system/src/foreground.rs b/crates/nu-system/src/foreground.rs index cec793fe76..88a50b1ac7 100644 --- a/crates/nu-system/src/foreground.rs +++ b/crates/nu-system/src/foreground.rs @@ -11,17 +11,18 @@ pub mod external_process_setup { libc::signal(libc::SIGTTIN, libc::SIG_IGN); external_command.pre_exec(|| { + // 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. libc::setpgid(0, 0); Ok(()) }); } } - pub fn set_foreground(process: &std::process::Child) -> i32 { + pub fn set_foreground(process: &std::process::Child) { unsafe { - let my_id = libc::getpid(); - libc::tcsetpgrp(0, process.id() as i32); - my_id + libc::tcsetpgrp(libc::STDIN_FILENO, process.id() as i32); } }