On 6/18/24 4:55 PM, Mark March wrote:
I am working with a large Bash code base where most scripts disable job control 
and the DEBUG trap is used extensively. I noticed that if I tried to run my 
scripts in the background, the interactive shell that started them would 
immediately exit on any keyboard input. A simple repro is to run

bash +m -c "/bin/echo ; trap 'trap DEBUG' DEBUG ; sleep 10" &
in an interactive shell with job control enabled. Hit Enter a few times. The 
shell that launched this background process exits. The background process 
itself appears to be killed by a signal.

Thanks for the report. The attached patch should fix your issue, though
there might be some corner cases. Let me know.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/

*** ../bash-20240609/trap.c     Fri May  3 12:12:38 2024
--- trap.c      Wed Jun 26 10:41:40 2024
***************
*** 1287,1291 ****
        restore_pgrp_pipe (save_pipe);
  #  endif
!       if (pipeline_pgrp > 0 && ((subshell_environment & 
(SUBSHELL_ASYNC|SUBSHELL_PIPE)) == 0))
        give_terminal_to (pipeline_pgrp, 1);
  
--- 1287,1293 ----
        restore_pgrp_pipe (save_pipe);
  #  endif
!       /* If the trap command gave the terminal to another process group,
!        restore it. XXX - check running_in_background? */
!       if (job_control && pipeline_pgrp > 0 && ((subshell_environment & 
(SUBSHELL_ASYNC|SUBSHELL_PIPE)) == 0))
        give_terminal_to (pipeline_pgrp, 1);
  

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to