On Sat, Mar 31, 2018 at 09:36:23PM +0000, Thorsten Glaser wrote:
> Hi,
> 
> I sometimes have weird tty state even after a process finished;
> this is mostly mpg123 running in foreground, so no backgrounding
> involved. When I then press Enter, the tty is back to normal
> state; is that true for your scenario too?

Typing ENTER does not change anything in my case.  But the tty is not in
an unforeseen state: it is just that after the command finishes
(successfully) if it has changed the tty state, this state is recorded
(and not reset to the value before it started) only if the job has not
been stopped, which I found susrprising.

I wondered if mksh records the stopping explicitely or if it is just a
side-effect of the code that does not keep the tty state after a failed
command (ends with non zero status or killed by SIGQUIT etc.).

> I didnbt find the underlying issue yet. If anyone can jump in
> with more debugging, or perhaps patches, Ibd be glad.

First one should know what is the correct behaviour.  The feature of
discarding tty changes after a failed command is related to job control
but it is not documented and not standard as neither bash nor ksh do
the same.  What makes sense is to discard the tty state after a
killed command as bash and ksh do.  After a failed command I don't think
it is necessary but it can be considered a safe choice.

Before a patch fixing the strange case of a "successful but temporarily
stopped job has failed" it would be good to document the feature (and
the bug, if it is one).

PS. bash has the same "bug", which can be tested with the following
command to circumvent the lack of tty state restoration when restarting
a job:
```
$ sh -c 'stty; sleep 2; stty; stty intr ^G; stty'
$ stty intr ^C; stty; sh -c 'stty intr ^G; sleep 2; stty; stty intr ^G; stty'
speed 38400 baud; line = 0;
-brkint -imaxbel iutf8
^Z
[1]+  Stopped                 sh -c 'stty intr ^G; sleep 2; stty; stty intr ^G; 
stty'
$ fg; stty
sh -c 'stty intr ^G; sleep 2; stty; stty intr ^G; stty'
speed 38400 baud; line = 0;
-brkint -imaxbel iutf8
speed 38400 baud; line = 0;
intr = ^G;
-brkint -imaxbel iutf8
speed 38400 baud; line = 0;
-brkint -imaxbel iutf8
```

Reply via email to