From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Andries E. Brouwer" Newsgroups: gmane.emacs.bugs Subject: bug#14491: emacs -nw doesn't always restore the terminal screen Date: Tue, 28 May 2013 20:22:01 +0200 Message-ID: <20130528182159.GA22032@jp> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1369766164 6851 80.91.229.3 (28 May 2013 18:36:04 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 28 May 2013 18:36:04 +0000 (UTC) To: 14491@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue May 28 20:36:03 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UhOkc-0007bj-OW for geb-bug-gnu-emacs@m.gmane.org; Tue, 28 May 2013 20:36:02 +0200 Original-Received: from localhost ([::1]:58687 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhOkc-00049j-CA for geb-bug-gnu-emacs@m.gmane.org; Tue, 28 May 2013 14:36:02 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:38396) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhOkP-000491-RS for bug-gnu-emacs@gnu.org; Tue, 28 May 2013 14:35:56 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UhOkJ-0004eS-8e for bug-gnu-emacs@gnu.org; Tue, 28 May 2013 14:35:49 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:49499) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhOkJ-0004eM-5O for bug-gnu-emacs@gnu.org; Tue, 28 May 2013 14:35:43 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UhOlZ-0002kw-UL for bug-gnu-emacs@gnu.org; Tue, 28 May 2013 14:37:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Andries E. Brouwer" Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 28 May 2013 18:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 14491 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.136976621110560 (code B ref -1); Tue, 28 May 2013 18:37:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 28 May 2013 18:36:51 +0000 Original-Received: from localhost ([127.0.0.1]:37857 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UhOlP-0002kH-9d for submit@debbugs.gnu.org; Tue, 28 May 2013 14:36:51 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:52167) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UhOYk-0002LD-2L for submit@debbugs.gnu.org; Tue, 28 May 2013 14:23:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UhOXH-0008Ua-Hf for submit@debbugs.gnu.org; Tue, 28 May 2013 14:22:21 -0400 Original-Received: from lists.gnu.org ([208.118.235.17]:36268) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhOXH-0008UW-EN for submit@debbugs.gnu.org; Tue, 28 May 2013 14:22:15 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:35279) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhOXE-0000hw-FT for bug-gnu-emacs@gnu.org; Tue, 28 May 2013 14:22:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UhOX9-0008TY-LE for bug-gnu-emacs@gnu.org; Tue, 28 May 2013 14:22:12 -0400 Original-Received: from fester.cwi.nl ([192.16.191.27]:60193) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhOX9-0008TH-Cj for bug-gnu-emacs@gnu.org; Tue, 28 May 2013 14:22:07 -0400 Original-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 Original-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 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-Mailman-Approved-At: Tue, 28 May 2013 14:36:50 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:74619 Archived-At: 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