[PATCH 2/3] ash: stopped jobs should only prevent exit from interactive shell

Harald van Dijk harald at gigawatt.nl
Sun Sep 12 11:31:01 UTC 2021


On 12/09/2021 11:21, Ron Yorston wrote:
> When the user tries to exit an interactive shell with stopped jobs
> present the shell issues a warning and only exits if the user
> insists by trying to exit again.
> 
> This shouldn't apply to non-interactive shells.

Agreed, but even in interactive shells, the implementation is not what 
it should be. Other shells (bash, ksh, yash, though not zsh) still use 
the exit status that exit would have resulted in to update $?, ash does not.

That is, ash results in:

   ~ $ cat &
   ~ $
   [1]+  Stopped (tty input)        cat
   ~ $ exit 1
   You have stopped jobs.
   ~ $ echo $?
   0

In bash, ksh and yash the last command prints 1.

Additionally, the check for stopped jobs happens before the job status 
is updated. I pressed Enter twice after 'cat &' to work around that. If 
I don't, I get:

   ~ $ cat &
   ~ $ exit 1

That is, even though by the time 'exit 1' is run the 'cat' command has 
stopped, the shell does not detect this. bash, ksh, yash do pick up on 
it and prevent the shell from exiting. (zsh is special and notifies that 
cat was suspended as it happens.)

Cheers,
Harald van Dijk


More information about the busybox mailing list