Skip to content

Commit

Permalink
fix unexpected pane closing issue with nushell
Browse files Browse the repository at this point in the history
nushell doesn't create a new process group when spawnning a process,
so all processes including the ones spwanned by us are in the same
foreground group. So if kernel will send signal to every member of this
group.

This patch fixes this issue by creating a new foreground process group
when spawnning a new terminal pane.

Fix zellij-org#615

Signed-off-by: Tw <tw19881113@gmail.com>
  • Loading branch information
tw4452852 committed Aug 15, 2021
1 parent da3f20c commit 64e0d00
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions zellij-server/src/os_input_output.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;
use std::os::unix::io::RawFd;
use std::os::unix::process::CommandExt;
use std::path::PathBuf;
use std::process::{Child, Command};
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -102,10 +103,19 @@ fn handle_terminal(cmd: RunCommand, orig_termios: termios::Termios) -> (RawFd, P
let pid_secondary = match fork_pty_res.fork_result {
ForkResult::Parent { child } => child,
ForkResult::Child => {
let child = Command::new(cmd.command)
.args(&cmd.args)
.spawn()
.expect("failed to spawn");
let child = unsafe {
Command::new(cmd.command)
.args(&cmd.args)
.pre_exec(|| -> std::io::Result<()> {
unistd::setpgid(Pid::from_raw(0), Pid::from_raw(0))
.expect("failed to create a new process group");
Ok(())
})
.spawn()
.expect("failed to spawn")
};
unistd::tcsetpgrp(0, Pid::from_raw(child.id() as i32))
.expect("faled to set child's forceground process group");
handle_command_exit(child);
::std::process::exit(0);
}
Expand Down

0 comments on commit 64e0d00

Please sign in to comment.