The fix [1] for the issue reported in [2]:

+ give the terminal to pipeline_pgrp. We don't give the terminal
+ back to shell_pgrp if an async job exits because we never gave it
+ to that job in the first place. */
       if ((flags & JWAIT_NOTERM) == 0 && running_in_background == 0 &&
+  (job == NO_JOB || IS_ASYNC (job) == 0) &&
   (subshell_environment & (SUBSHELL_ASYNC|SUBSHELL_PIPE)) == 0)
  give_terminal_to (shell_pgrp, 0);

makes bash not take the terminal back when an async job is brought to the
foreground with `fg' and then subsequently TSTP-ed.

This is not immediately noticeable because if readline is in use,
yy_readline_get will shortly do it. However, with --noediting mode the
interactive shell will get EOF when reading the next command and exit.  And
even with readline, any attempt to read from the terminal prior to readline
doing it (e.g. from PROMPT_COMMAND) will result in EIO (which is how I
first noticed this).

[1]: https://git.savannah.gnu.org/cgit/bash.git/commit/?h=devel&id=a37b2af9
[2]: https://lists.gnu.org/archive/html/bug-bash/2023-01/msg00057.html


$ bash --norc --noediting
bash-5.3$ sleep 60 &
[1] 30163
bash-5.3$ fg
sleep 60
^Z                     # shell exits after this
[1]+ Stopped sleep 60
bash-5.3$ exit
There are stopped jobs.
bash-5.3$ exit

$ bash --norc
bash-5.3$ r() { read -r -s -dR -t1 -p$'\e[6n'; }
bash-5.3$ PROMPT_COMMAND=r
bash-5.3$ sleep 60 &
[1] 31088
bash-5.3$ fg
sleep 60
^Z
[1]+ Stopped sleep 60
bash: read: read error: 0: I/O error
bash-5.3$

Reply via email to