bug-bash
[Top][All Lists]
Advanced

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

bash: ^D exits immediately while jobs are stopped


From: Tom Levy
Subject: bash: ^D exits immediately while jobs are stopped
Date: Fri, 8 Mar 2019 09:52:03 +1300
User-agent: NeoMutt/20170113 (1.7.2)

Description:

When jobs are stopped it normally takes two attempts to exit with no
intervening commands. However, if there is exactly one intervening
command, ^D exits immediately instead of printing a warning. (The
"exit" builtin works correctly on the other hand.)

Repeat-By:

$ cat
^Z
[1]+  Stopped                 cat
$ ^D
exit
There are stopped jobs.
$ echo intervening command
intervening command
$ ^D
exit
<terminates>
# expected behaviour: print "There are stopped jobs" instead of exiting

Cause:

The exit_or_logout function in builtins/exit.def uses
last_shell_builtin to check if the last command was also an exit
attempt. However, ^D bypasses the command parser so last_shell_builtin
will actually be the second to last command.

In the example above, when the second ^D is typed, this_shell_builtin
is the "echo" command and last_shell_builtin is "exit" from the first
^D. So exit_or_logout thinks this is the second exit in a row when it
isn't.

Fix:

Patch attached. It makes exit_or_logout check that this_shell_builtin
is also an exit attempt.

(The code already sets both this_shell_builtin and last_shell_builtin
to "exit" on the first exit attempt, so typing ^D twice in a row will
exit immediately like it should.)

Configuration Information:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -Wno-parentheses -Wno-format-security
uname output: Linux debian 4.9.0-8-amd64 #1 SMP Debian 4.9.144-3.1 (2019-02-19) 
x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.0
Patch Level: 2
Release Status: release

Regards,
Tom Levy

Attachment: 0001-fix-D-don-t-exit-while-jobs-are-stopped-after-interv.patch
Description: Text Data


reply via email to

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