]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
fix for optimizing forks away if bash -ic command is executed
authorChet Ramey <chet.ramey@case.edu>
Mon, 12 Jun 2023 21:46:30 +0000 (17:46 -0400)
committerChet Ramey <chet.ramey@case.edu>
Mon, 12 Jun 2023 21:46:30 +0000 (17:46 -0400)
CWRU/CWRU.chlog
builtins/evalstring.c
jobs.c
jobs.h
lib/readline/util.c
nojobs.c
shell.c
shell.h

index e3dc20d9c5e472b103bdf73e50a336b3904940bd..a667dbe986d4ed17c899964c3ebdace5d5377255 100644 (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.
index 1b00da2e01a77a41896e9f7d8375983e6cc9f392..11785de1c1d2abfd4db7f40f7872bfa479d0660a 100644 (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));
 }
 
diff --git a/jobs.c b/jobs.c
index d392851856f02aa0183f65d929df1379a97b1131..1af63f9c6a76d246eea4444a41c80fde94b7cd9a 100644 (file)
--- a/jobs.c
+++ b/jobs.c
@@ -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
diff --git a/jobs.h b/jobs.h
index 5f9c9fc3086ef440d1fb1129d995a4ca2deb4487..c6430216b829ff1f122f5d8ab6ee08044afc2fcf 100644 (file)
--- a/jobs.h
+++ b/jobs.h
@@ -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);
 
index f909daafc206b17fd5257aff0348b1ee4730ff13..2a247034b809747c35bc3f4dfb42096f4ea85619 100644 (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>
index c480e8601b5819ececf7bf372ab820346706a029..6073d75a7991c131515fc4781a93651170d68dce 100644 (file)
--- a/nojobs.c
+++ b/nojobs.c
@@ -1038,3 +1038,9 @@ count_all_jobs (void)
 {
   return 0;
 }
+
+int
+job_control_active_p (void)
+{
+  return 0;
+}
diff --git a/shell.c b/shell.c
index b1359eaff409669976648b83e63b873b0052bc35..9f1934d23a89389bcc5f3885fdd026b03b99e22c 100644 (file)
--- a/shell.c
+++ b/shell.c
@@ -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;
        }
     }
diff --git a/shell.h b/shell.h
index bf96786aa067118ac55d787f8a36b465753ffd2c..7b43813ba9cf4a08c2a07161d108e772afe42860 100644 (file)
--- a/shell.h
+++ b/shell.h
@@ -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;