On Sun, Apr 01, 2018 at 10:20:43PM +0000, Thorsten Glaser wrote:
> G.raud Meyer dixit:
> 
> >First one should know what is the correct behaviour.  The feature of
> [b&]
> >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).
> 
> I honestly donbt know.

Thinking a bit more about this, I found a valid reason not to keep the
terminal state after a restarted job exits (successfully): the tty
state in which that job was started can be obsolete at the time it is
restarted because the tty state may have been modified while the job was
stopped (or running in the background).

It would be a rare case where mksh is more "advanced" than ksh if the
behaviour is intentional.
 
> It is desirable to be able to change all sorts of terminal state
> with stty, so *some* not-resetting and/or saving is desirable.
> On the other hand, the editor needs a certain state, too.
> 
> Basically, we need to not break the scenarios:
> 
> $ stty something; some other command
> $ b back to the line editor
> 
> (fully)
> 
> $ stty something
> $ some other command b back to the line editor
> 
> (partially? OTOH the line editor can cope with a LOT of states)
> 
> We also want the line editor to work.
> 
> It gets more complicated when backgrounded jobs come
> into play. As I said, I honestly have absolutely no
> ideab&
> 
> Comparing this with, say, the last pdksh release,
> would be a start: did it do the exact same thing,
> and, if not, why the differences.

I join a patch that adds a manage subsection "Terminal state" explaining
how to change the terminal state and describing the exception for
temporarily stopped jobs (and mentioning that the line editing
code saves/restores the terminal state too).  The saving/restoring of
the tty state for stopped/restarted jobs is already documented in the
subsection "Job control".
Index: mksh.1
===================================================================
RCS file: /cvs/src/bin/mksh/mksh.1,v
retrieving revision 1.451
diff -u -p -u -r1.451 mksh.1
--- mksh.1	16 Aug 2017 21:40:14 -0000	1.451
+++ mksh.1	21 Apr 2018 20:31:05 -0000
@@ -5197,6 +5197,15 @@ option differs: the search path is not a
 .Ic whence ,
 but the search is restricted to the path.
 .El
+.Ss Terminal state
+The state of the controlling terminal can be modified by a command executed in
+the shell, whether or not job control is enabled.  The modified state is kept
+only when the command exits successfully (i.e. with an exit status of 0).  As
+an exception, when job control is enabled and the command is momentarily
+stopped then restarted, the modified state is discarded after it finishes, even
+when it exits successfully.  In interactive mode when line editing is enabled,
+as the terminal is reconfigured by the shell, the saved terminal state is
+restored before running a command.
 .Ss Job control
 Job control refers to the shell's ability to monitor and control jobs which
 are processes or groups of processes created for commands or pipelines.

Reply via email to