fix for optimizing forks away if bash -ic command is executed

This commit is contained in:
Chet Ramey
2023-06-12 17:46:30 -04:00
parent a629483b0e
commit d44a45afbc
8 changed files with 41 additions and 1 deletions
+21
View File
@@ -6548,3 +6548,24 @@ subst.c
- expand_string_dollar_quote: if singlequote_translations is set, there
is a chance for a use-after-free of `t'.
From a report by Grisha Levit <grishalevit@gmail.com>
6/7
---
jobs.c,nojobs.c,jobs.h
- job_control_active_p: new function, returns 1 if job control is
currently enabled and we have given away the terminal
builtins/evalstring.c
- should_suppress_fork: don't optimize away the fork if job control is
active because we need to call end_job_control and give the terminal
back to the original process group when this command finishes. Call
job_control_active_p() to check this.
Report from Andrew Hamon <and.ham95@gmail.com>
6/8
---
shell.c
- ssh_run_startup_files: new variable, set by run_startup_files if
the shell decides it's being run by ssh and runs bashrc (only if
SSH_SOURCE_BASHRC is defined). Non-zero while the startup files
are being run. Not used by any other part of the shell yet.
+1
View File
@@ -127,6 +127,7 @@ should_suppress_fork (COMMAND *command)
return (startup_state == 2 && parse_and_execute_level == 1 &&
*bash_input.location.string == '\0' &&
parser_expanding_alias () == 0 &&
job_control_active_p () == 0 &&
should_optimize_fork (command, subshell));
}
+6
View File
@@ -4977,6 +4977,12 @@ end_job_control (void)
shell_pgrp = original_pgrp;
}
int
job_control_active_p (void)
{
return (job_control && original_pgrp != shell_pgrp && shell_pgrp == terminal_pgrp);
}
/* Restart job control by closing shell tty and reinitializing. This is
called after an exec fails in an interactive shell and we do not exit. */
void
+1
View File
@@ -309,6 +309,7 @@ extern void set_sigchld_handler (void);
extern void ignore_tty_job_signals (void);
extern void default_tty_job_signals (void);
extern void get_original_tty_job_signals (void);
extern int job_control_active_p (void);
extern void init_job_stats (void);
+1 -1
View File
@@ -43,8 +43,8 @@
#include <ctype.h>
/* System-specific feature definitions and include files. */
#include "rldefs.h"
#include "rlmbutil.h"
#include "rldefs.h"
#if defined (TIOCSTAT_IN_SYS_IOCTL)
# include <sys/ioctl.h>
+6
View File
@@ -1038,3 +1038,9 @@ count_all_jobs (void)
{
return 0;
}
int
job_control_active_p (void)
{
return 0;
}
+4
View File
@@ -161,6 +161,8 @@ int autocd = 0;
int startup_state = 0;
int reading_shell_script = 0;
int ssh_reading_startup_files = 0;
/* Special debugging helper. */
int debugging_login_shell = 0;
@@ -1128,6 +1130,7 @@ run_startup_files (void)
if (isnetconn (fileno (stdin) && shell_level < 2)
#endif
{
ssh_reading_startup_files = 1;
#ifdef SYS_BASHRC
# if defined (__OPENNT)
maybe_execute_file (_prefixInstallPath(SYS_BASHRC, NULL, 0), 1);
@@ -1136,6 +1139,7 @@ run_startup_files (void)
# endif
#endif
maybe_execute_file (bashrc_file, 1);
ssh_reading_startup_files = 0;
return;
}
}
+1
View File
@@ -100,6 +100,7 @@ extern int executing, login_shell;
extern int interactive, interactive_shell;
extern int startup_state;
extern int reading_shell_script;
extern int ssh_reading_startup_files;
extern int shell_initialized;
extern int bash_argv_initialized;
extern int subshell_environment;