From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Antipov Newsgroups: gmane.emacs.bugs Subject: bug#15025: emacs --daemon stuck in infinite loop Date: Wed, 14 Aug 2013 21:43:15 +0400 Message-ID: <520BC1B3.5080008@yandex.ru> References: <4jpptql6gy.fsf@fencepost.gnu.org> <5201AD43.4040105@yandex.ru> <52045526.8060404@yandex.ru> <5204B28B.2060505@gmx.at> <5205040B.5050404@yandex.ru> <5205526D.7040408@gmx.at> <5208985B.9010106@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------080500090401030500020200" X-Trace: ger.gmane.org 1376502257 6547 80.91.229.3 (14 Aug 2013 17:44:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 14 Aug 2013 17:44:17 +0000 (UTC) Cc: Paul Eggert , 15025@debbugs.gnu.org To: Dan Nicolaescu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Aug 14 19:44:20 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 1V9f7L-00051q-Fa for geb-bug-gnu-emacs@m.gmane.org; Wed, 14 Aug 2013 19:44:19 +0200 Original-Received: from localhost ([::1]:42948 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V9f7L-0000L0-50 for geb-bug-gnu-emacs@m.gmane.org; Wed, 14 Aug 2013 13:44:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54674) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V9f7B-0000JH-AV for bug-gnu-emacs@gnu.org; Wed, 14 Aug 2013 13:44:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V9f74-0001Tv-TY for bug-gnu-emacs@gnu.org; Wed, 14 Aug 2013 13:44:09 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:35967) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V9f74-0001Tj-Oj for bug-gnu-emacs@gnu.org; Wed, 14 Aug 2013 13:44:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1V9f74-0000D5-0m for bug-gnu-emacs@gnu.org; Wed, 14 Aug 2013 13:44:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Antipov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 14 Aug 2013 17:44:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 15025 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 15025-submit@debbugs.gnu.org id=B15025.1376502213739 (code B ref 15025); Wed, 14 Aug 2013 17:44:01 +0000 Original-Received: (at 15025) by debbugs.gnu.org; 14 Aug 2013 17:43:33 +0000 Original-Received: from localhost ([127.0.0.1]:58515 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1V9f6a-0000Bq-Bp for submit@debbugs.gnu.org; Wed, 14 Aug 2013 13:43:32 -0400 Original-Received: from forward1.mail.yandex.net ([77.88.46.6]:51646) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1V9f6W-0000BT-UJ for 15025@debbugs.gnu.org; Wed, 14 Aug 2013 13:43:30 -0400 Original-Received: from smtp1.mail.yandex.net (smtp1.mail.yandex.net [77.88.46.101]) by forward1.mail.yandex.net (Yandex) with ESMTP id 906F41241BAA; Wed, 14 Aug 2013 21:43:22 +0400 (MSK) Original-Received: from smtp1.mail.yandex.net (localhost [127.0.0.1]) by smtp1.mail.yandex.net (Yandex) with ESMTP id 46192AA08FB; Wed, 14 Aug 2013 21:43:22 +0400 (MSK) Original-Received: from 242.gprs.mts.ru (242.gprs.mts.ru [213.87.134.242]) by smtp1.mail.yandex.net (nwsmtp/Yandex) with ESMTP id IhqHK6y66f-hIqGFtgx; Wed, 14 Aug 2013 21:43:21 +0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1376502201; bh=XfWO9hDKZGEiGNJ2dt+BQaJ06vrN0nMWGRd2FUsaCXU=; h=Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: References:In-Reply-To:Content-Type; b=uDBmlmh2AWi4J84OW0w16hCpoHXWzQ22HIxWRd+KYAN7fv4v8QxQg1l5M6ZQdG3RY PoP3mSe4070VZYi3XG+bT7SOeKtfHxHfCr1DDuNm9LoSg3DqFDbY+PfCYckzPyiCXR CIvbpTRmpQwxlX7YCKjFRH0ADzy9e4Ny/Km3F8gc= Authentication-Results: smtp1.mail.yandex.net; dkim=pass header.i=@yandex.ru User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.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:77349 Archived-At: This is a multi-part message in MIME format. --------------080500090401030500020200 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Dan, could you please try this hack? You should see some noise from lisp/server.el code (because server process doesn't know about dead terminals), and warnings about frame deletion. But it shouldn't crash or stuck at least... Dmitry --------------080500090401030500020200 Content-Type: text/plain; charset=UTF-8; name="bug15025_hack.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="bug15025_hack.patch" === modified file 'src/frame.c' --- src/frame.c 2013-08-14 16:36:16 +0000 +++ src/frame.c 2013-08-14 17:28:21 +0000 @@ -1199,8 +1199,14 @@ { Lisp_Object tail, frame1; - /* Look for another visible frame on the same terminal. */ - frame1 = next_frame (frame, Qvisible); + /* Look for another visible frame on the same terminal. + Do not call next_frame here. FIXME this. */ + FOR_EACH_FRAME (tail, frame1) + if (!EQ (frame, frame1) + && (FRAME_TERMINAL (XFRAME (frame)) + == FRAME_TERMINAL (XFRAME (frame1))) + && FRAME_VISIBLE_P (XFRAME (frame1))) + break; /* If there is none, find *some* other frame. */ if (NILP (frame1) || EQ (frame1, frame)) === modified file 'src/keyboard.c' --- src/keyboard.c 2013-08-13 08:39:14 +0000 +++ src/keyboard.c 2013-08-14 17:12:39 +0000 @@ -6847,17 +6847,21 @@ alone in its group. */ terminate_due_to_signal (SIGHUP, 10); - /* XXX Is calling delete_terminal safe here? It calls delete_frame. */ - { - Lisp_Object tmp; - XSETTERMINAL (tmp, t); - Fdelete_terminal (tmp, Qnoelisp); - } + /* This terminal is now dead. */ + t->dead = 1; } if (hold_quit.kind != NO_EVENT) kbd_buffer_store_event (&hold_quit); } + else + { + /* If read_socket_hook is NULL, T is suspended. But T may be + dead, see http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */ + if (t->type == output_termcap + && !check_tty_alive (t->display_info.tty->name)) + t->dead = 1; + } t = next; } @@ -7079,6 +7083,7 @@ { pending_signals = 0; handle_async_input (); + drop_dead_terminals (); do_pending_atimers (); } === modified file 'src/lisp.h' --- src/lisp.h 2013-08-14 16:36:16 +0000 +++ src/lisp.h 2013-08-14 17:14:11 +0000 @@ -4094,6 +4094,7 @@ extern void sys_subshell (void); extern void sys_suspend (void); extern void discard_tty_input (void); +extern bool check_tty_alive (char *); extern void block_tty_out_signal (void); extern void unblock_tty_out_signal (void); extern void init_sys_modes (struct tty_display_info *); === modified file 'src/sysdep.c' --- src/sysdep.c 2013-08-09 12:25:34 +0000 +++ src/sysdep.c 2013-08-14 17:13:48 +0000 @@ -734,6 +734,15 @@ #endif } +/* This works on Linux, but no ideas for others. */ + +bool +check_tty_alive (char *tty) +{ + int fd = emacs_open (tty, O_RDWR | O_NONBLOCK, 0); + return fd > 0 ? (emacs_close (fd), 1) : 0; +} + /* Safely set a controlling terminal FD's process group to PGID. If we are not in the foreground already, POSIX requires tcsetpgrp to deliver a SIGTTOU signal, which would stop us. This is an === modified file 'src/termhooks.h' --- src/termhooks.h 2013-07-16 11:41:06 +0000 +++ src/termhooks.h 2013-08-14 17:04:49 +0000 @@ -362,6 +362,9 @@ /* Chain of all terminal devices. */ struct terminal *next_terminal; + /* Nonzero if this terminal is really dead. */ + unsigned dead : 1; + /* Unique id for this terminal device. */ int id; @@ -648,6 +651,7 @@ extern struct terminal *get_terminal (Lisp_Object terminal, bool); extern struct terminal *create_terminal (void); extern void delete_terminal (struct terminal *); +extern void drop_dead_terminals (void); /* The initial terminal device, created by initial_term_init. */ extern struct terminal *initial_terminal; === modified file 'src/terminal.c' --- src/terminal.c 2013-07-31 06:05:05 +0000 +++ src/terminal.c 2013-08-14 17:36:30 +0000 @@ -537,6 +537,24 @@ } void +drop_dead_terminals (void) +{ + struct terminal *t, *next; + + for (t = terminal_list; t; t = next) + { + next = t->next_terminal; + if (t->dead) + { + if (t->delete_terminal_hook) + (*t->delete_terminal_hook) (t); + else + delete_terminal (t); + } + } +} + +void syms_of_terminal (void) { --------------080500090401030500020200--