bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Remove maybe_give_terminal_to() race


From: Earl Chew
Subject: [PATCH] Remove maybe_give_terminal_to() race
Date: Sun, 10 Sep 2023 17:12:40 -0700

Following the discussion, here is a patch proposed against
the devel branch.

--------

When creating a foreground job, only configure the controlling
terminal from the child. This addresses a scenario where
the new foreground job reconfiguring the foreground
process group would race with the parent.

Signed-off-by: Earl Chew <earl_chew@yahoo.com>
---
 jobs.c | 44 +-------------------------------------------
 1 file changed, 1 insertion(+), 43 deletions(-)

diff --git a/jobs.c b/jobs.c
index da47cf71..79006e14 100644
--- a/jobs.c
+++ b/jobs.c
@@ -283,7 +283,6 @@ static void set_current_job (int);
 static void reset_current (void);
 static void set_job_running (int);
 static void setjstatus (int);
-static int maybe_give_terminal_to (pid_t, pid_t, int);
 static void mark_all_jobs_as_dead (void);
 static void mark_dead_jobs_as_notified (int);
 static void restore_sigint_handler (void);
@@ -702,24 +701,7 @@ stop_pipeline (int async, COMMAND *deferred)
   else
     {
       if (newjob)
-       {
-         newjob->flags |= J_FOREGROUND;
-         /*
-          *            !!!!! NOTE !!!!!  (chet@po.cwru.edu)
-          *
-          * The currently-accepted job control wisdom says to set the
-          * terminal's process group n+1 times in an n-step pipeline:
-          * once in the parent and once in each child.  This is where
-          * the parent gives it away.
-          *
-          * Don't give the terminal away if this shell is an asynchronous
-          * subshell or if we're a (presumably non-interactive) shell running
-          * in the background.
-          *
-          */
-         if (job_control && newjob->pgrp && 
(subshell_environment&SUBSHELL_ASYNC) == 0 && running_in_background == 0)
-           maybe_give_terminal_to (shell_pgrp, newjob->pgrp, 0);
-       }
+       newjob->flags |= J_FOREGROUND;
     }
 
   stop_making_children ();
@@ -4637,30 +4619,6 @@ give_terminal_to (pid_t pgrp, int force)
   return r;
 }
 
-/* Give terminal to NPGRP iff it's currently owned by OPGRP.  FLAGS are the
-   flags to pass to give_terminal_to(). */
-static int
-maybe_give_terminal_to (pid_t opgrp, pid_t npgrp, int flags)
-{
-  int tpgrp;
-
-  tpgrp = tcgetpgrp (shell_tty);
-  if (tpgrp < 0 && errno == ENOTTY)
-    return -1;
-  if (tpgrp == npgrp)
-    {
-      terminal_pgrp = npgrp;
-      return 0;
-    }
-  else if (tpgrp != opgrp)
-    {
-      internal_debug ("%d: maybe_give_terminal_to: terminal pgrp == %d shell 
pgrp = %d new pgrp = %d in_background = %d", (int)getpid(), tpgrp, opgrp, 
npgrp, running_in_background);
-      return -1;
-    }
-  else
-    return (give_terminal_to (npgrp, flags));     
-}
-
 /* Clear out any jobs in the job array.  This is intended to be used by
    children of the shell, who should not have any job structures as baggage
    when they start executing (forking subshells for parenthesized execution
-- 
2.39.1



reply via email to

[Prev in Thread] Current Thread [Next in Thread]