Always become pgroup leader in interactive mode

Prior to this change, if fish were launched connected to a tty but not as
pgroup leader, it would attempt to become pgroup leader only if
--interactive is explicitly passed. But bash will unconditionally attempt
to become pgroup leader if launched interactively. This can result in
scenarios where fish is running interactively but in another pgroup. The
most obvious impact is that control-C will result in the pgroup leader
(not fish) exiting and make fish orphaned.

Switch to matching the bash behavior here - we will always try to become
pgroup leader if interactive.

Fixes #7060.
This commit is contained in:
ridiculousfish
2020-12-06 13:40:45 -08:00
parent 5f131878a9
commit a2e486966a
9 changed files with 25 additions and 29 deletions

View File

@@ -384,7 +384,7 @@ static int fish_parse_opt(int argc, char **argv, fish_cmd_opts_t *opts) {
// command or file to execute and stdin is a tty. Note that the -i or
// --interactive options also force interactive mode.
if (opts->batch_cmds.empty() && optind == argc && isatty(STDIN_FILENO)) {
set_interactive_session(session_interactivity_t::implied);
set_interactive_session(true);
}
return optind;
@@ -447,12 +447,12 @@ int main(int argc, char **argv) {
// Apply our options.
if (opts.is_login) mark_login();
if (opts.no_exec) mark_no_exec();
if (opts.is_interactive_session) set_interactive_session(session_interactivity_t::explicit_);
if (opts.is_interactive_session) set_interactive_session(true);
if (opts.enable_private_mode) start_private_mode(env_stack_t::globals());
// Only save (and therefore restore) the fg process group if we are interactive. See issues
// #197 and #1002.
if (session_interactivity() != session_interactivity_t::not_interactive) {
if (is_interactive_session()) {
save_term_foreground_process_group();
}