GNU bug report logs - #14491
emacs -nw doesn't always restore the terminal screen

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: "Andries E. Brouwer" <Andries.Brouwer@HIDDEN>; merged with #10959, #15013; dated Tue, 28 May 2013 18:37:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Merged 10959 14491 15013. Request was from Glenn Morris <rgm@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 14491 <at> debbugs.gnu.org:


Received: (at 14491) by debbugs.gnu.org; 2 Aug 2013 16:56:22 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Aug 02 12:56:22 2013
Received: from localhost ([127.0.0.1]:36683 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1V5IeL-0003u3-OI
	for submit <at> debbugs.gnu.org; Fri, 02 Aug 2013 12:56:22 -0400
Received: from fester.cwi.nl ([192.16.191.27]:48978)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <Andries.Brouwer@HIDDEN>) id 1V5IeI-0003tb-FY
 for 14491 <at> debbugs.gnu.org; Fri, 02 Aug 2013 12:56:19 -0400
Received: from fester.cwi.nl (fester.cwi.nl [192.16.191.27]) by fester.cwi.nl
 with ESMTP id r72GuCbb011175 for ; Fri, 2 Aug 2013 18:56:12 +0200
Received: from localhost (a80-101-109-117.adsl.xs4all.nl [80.101.109.117])
 (authenticated bits=0)
 by fester.cwi.nl (8.14.4/8.12.3) with ESMTP id r72GuBEr011173
 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO);
 Fri, 2 Aug 2013 18:56:11 +0200
Date: Fri, 2 Aug 2013 18:56:05 +0200
From: "Andries E. Brouwer" <Andries.Brouwer@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: Re: emacs -nw doesn't always restore the terminal screen
Message-ID: <20130802165603.GA13204@jp>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.5.21 (2010-09-15)
X-Spam-Score: -1.4 (-)
X-Debbugs-Envelope-To: 14491
Cc: 14491 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.4 (-)

Two months ago I wrote

> Sometimes after exiting "emacs -nw" the cursor is left
> in the middle of a former terminal buffer.
> It feels like a timing issue.

Yesterday I had a different emacs problem (utf-8 pasted
into an emacs -nw buffer was corrupted when preceded by an
ESC-q command, for any q), and debugging showed that the problem
was not with emacs but with luit, a layer that sits between
xterm and emacs -nw. Since luit parses its input and recognizes
escape sequences, it is in a state where it truncates UTF-8
when it thinks it is reading an ISO 2022 escape sequence.

OK - so emacs -nw under luit has some strange corruption issues.

Returning to this old problem, I now conjecture that also that was
caused by luit. It is somewhat difficult to reproduce, but a moment ago
I did reproduce it once with emacs -nw under luit, and saw no problems
without luit.

Perhaps the problem has been solved and no emacs fixes are required.

Andries





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#14491; Package emacs. Full text available.
Merged 10959 14491. Request was from Glenn Morris <rgm@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 28 May 2013 18:36:51 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue May 28 14:36:51 2013
Received: from localhost ([127.0.0.1]:37857 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.72)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1UhOlP-0002kH-9d
	for submit <at> debbugs.gnu.org; Tue, 28 May 2013 14:36:51 -0400
Received: from eggs.gnu.org ([208.118.235.92]:52167)
	by debbugs.gnu.org with esmtp (Exim 4.72)
	(envelope-from <Andries.Brouwer@HIDDEN>) id 1UhOYk-0002LD-2L
	for submit <at> debbugs.gnu.org; Tue, 28 May 2013 14:23:47 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Andries.Brouwer@HIDDEN>) id 1UhOXH-0008Ua-Hf
	for submit <at> debbugs.gnu.org; Tue, 28 May 2013 14:22:21 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_50,RP_MATCHES_RCVD
	autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([208.118.235.17]:36268)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Andries.Brouwer@HIDDEN>) id 1UhOXH-0008UW-EN
	for submit <at> debbugs.gnu.org; Tue, 28 May 2013 14:22:15 -0400
Received: from eggs.gnu.org ([208.118.235.92]:35279)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Andries.Brouwer@HIDDEN>) id 1UhOXE-0000hw-FT
	for bug-gnu-emacs@HIDDEN; Tue, 28 May 2013 14:22:15 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Andries.Brouwer@HIDDEN>) id 1UhOX9-0008TY-LE
	for bug-gnu-emacs@HIDDEN; Tue, 28 May 2013 14:22:12 -0400
Received: from fester.cwi.nl ([192.16.191.27]:60193)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Andries.Brouwer@HIDDEN>) id 1UhOX9-0008TH-Cj
	for bug-gnu-emacs@HIDDEN; Tue, 28 May 2013 14:22:07 -0400
Received: from fester.cwi.nl (fester.cwi.nl [192.16.191.27]) by fester.cwi.nl
	with ESMTP id r4SIM4Qo025526 for ; Tue, 28 May 2013 20:22:04 +0200
Received: from localhost (a80-101-109-117.adsl.xs4all.nl [80.101.109.117])
	(authenticated bits=0)
	by fester.cwi.nl (8.14.4/8.12.3) with ESMTP id r4SIM4tV025524
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO);
	Tue, 28 May 2013 20:22:04 +0200
Date: Tue, 28 May 2013 20:22:01 +0200
From: "Andries E. Brouwer" <Andries.Brouwer@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: emacs -nw doesn't always restore the terminal screen
Message-ID: <20130528182159.GA22032@jp>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.5.21 (2010-09-15)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.17
X-Spam-Score: -4.2 (----)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Tue, 28 May 2013 14:36:50 -0400
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.13
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Sender: debbugs-submit-bounces <at> debbugs.gnu.org
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
X-Spam-Score: -6.9 (------)

Sometimes after exiting "emacs -nw" the cursor is left
in the middle of a former terminal buffer, so that one
has to search for the bash prompt among former buffer text.
Sometimes the cursor position is OK, but the screen is not restored.

On my old computer I saw this sporadically, now I see it regularly.
It feels like a timing issue.

Probably the same issue was reported by Vincent Lefevre
in bug#10959 for emacs 23.3. That was also my working emacs,
but I verified that emacs 24.3 has the same issue.

Running the session under script shows what emacs sends to the
xterm pseudoterminal.

When all works as expected one sees something like
^[[?12l^[[?25h^[[?12;25h^[[>4m^[[48d^[[?1l^[>^[[?12l^[[?25h^[[?1049l^[[39;49m^M
upon exit. In the cases that fail it is something like
^[[?12l^[[?25h^[[?12;25h^[[>4m^[[48d^[[K

The essential difference for the purposes of this bug is ^[[?1049l,
the "te" capability ("rmcup" in terminfo terms), that restores
terminal state.

First solution:

Replace the invocation "emacs -nw --no-splash file" by
"emacs -nw --no-splash file; tput rmcup".
Now all is fine.

Second solution:

The "^[[>4m" here is from xterm-remove-modify-other-keys
which is attached to kill-emacs-hook. If I remove it,
I no longer see the problem. (Maybe only the timing is changed,
maybe this really helps. One could imagine that the same terminal
is approached via several buffered output streams, and that a
second simultaneous invocation of a terminal write kills the first.)

The ^[[?1l^[>^[[?12l^[[?25h^[[?1049l^[[39;49m^M" comes from
tty_reset_terminal_modes();
It contains a fflush (tty->output); Adding an fsync() there
does not help. An additional sleep for a few seconds does not
help either.

Third solution:

If I add another
OUTPUT_IF (tty, tty->TS_end_termcap_modes); fflush (tty->output);
at the end of tty_reset_terminal_modes();
I no longer see the problem.

Proper solution: no idea.
What sources of concurrency are there? Does emacs use threads?
Does emacs write to several file descriptors that ultimately
refer to the same pty?

Since this is tested via script, the properties of xterm do not seem
to play a role.

Andries




Acknowledgement sent to "Andries E. Brouwer" <Andries.Brouwer@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#14491; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 25 Nov 2019 12:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.