Skip to content
Snippets Groups Projects
Commit a188a8ec authored by AdminXVII's avatar AdminXVII
Browse files

:bug: The set_unique_pid was removed, but it was necessary

When Ion is started as a login shell, the `login` command expects the
shell to take ownership of the terminal. Else, the read command fails,
putting liner in an infinite loop. Bring back the set_unique_pid
function
parent b6382f3e
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ use atty::Stream;
use ion_shell::{BuiltinMap, IonError, PipelineError, Shell, Value};
use liner::KeyBindings;
use std::{
io::{stdin, BufReader},
io::{self, stdin, BufReader},
process,
};
......@@ -125,6 +125,16 @@ fn parse_args() -> CommandLineArgs {
}
}
fn set_unique_pid() -> io::Result<()> {
unsafe {
let pgid = libc::getpid();
libc::setpgid(0, pgid);
libc::signal(libc::SIGTTOU, libc::SIG_IGN);
libc::tcsetpgrp(libc::STDIN_FILENO, pgid);
}
Ok(())
}
fn main() {
let command_line_args = parse_args();
......@@ -143,6 +153,12 @@ fn main() {
let stdin_is_a_tty = atty::is(Stream::Stdin);
let mut shell = Shell::with_builtins(builtins);
if stdin_is_a_tty {
if let Err(err) = set_unique_pid() {
println!("ion: could not bring shell to foreground: {}", err);
}
}
shell.opts_mut().print_comms = command_line_args.print_commands;
shell.opts_mut().no_exec = command_line_args.no_execute;
shell.opts_mut().is_background_shell = !stdin_is_a_tty;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment