From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel,gmane.emacs.pretest.bugs Subject: after-delete-terminal-functions (was: 23.0.60; Emacs should survive a lost X connection) Date: Tue, 12 Feb 2008 22:09:06 -0500 Message-ID: References: <20080205.155847.56398348.hanche@math.ntnu.no> <200802051957.m15Jv8r1019258@sallyv1.ics.uci.edu> <200802052349.m15NnxSu013983@sallyv1.ics.uci.edu> <200802062007.m16K7r78005498@sallyv1.ics.uci.edu> <200802080726.m187Q5gL002961@sallyv1.ics.uci.edu> <200802090504.m1954WTM028192@sallyv1.ics.uci.edu> <200802100803.m1A83Eq5026472@sallyv1.ics.uci.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1202872174 6946 80.91.229.12 (13 Feb 2008 03:09:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 13 Feb 2008 03:09:34 +0000 (UTC) Cc: emacs-pretest-bug@gnu.org, hanche@math.ntnu.no, rms@gnu.org To: Dan Nicolaescu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Feb 13 04:09:56 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JP80O-0004AW-CK for ged-emacs-devel@m.gmane.org; Wed, 13 Feb 2008 04:09:52 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JP7zu-0004Sq-Mh for ged-emacs-devel@m.gmane.org; Tue, 12 Feb 2008 22:09:22 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JP7zq-0004Se-LH for emacs-devel@gnu.org; Tue, 12 Feb 2008 22:09:18 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JP7zp-0004SL-Km for emacs-devel@gnu.org; Tue, 12 Feb 2008 22:09:17 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JP7zp-0004SI-FK for emacs-devel@gnu.org; Tue, 12 Feb 2008 22:09:17 -0500 Original-Received: from fencepost.gnu.org ([140.186.70.10]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JP7zp-00058y-7U for emacs-devel@gnu.org; Tue, 12 Feb 2008 22:09:17 -0500 Original-Received: from mx10.gnu.org ([199.232.76.166]) by fencepost.gnu.org with esmtp (Exim 4.67) (envelope-from ) id 1JP7zo-0007Bk-R3 for emacs-pretest-bug@gnu.org; Tue, 12 Feb 2008 22:09:16 -0500 Original-Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1JP7zl-00058L-Or for emacs-pretest-bug@gnu.org; Tue, 12 Feb 2008 22:09:16 -0500 Original-Received: from 76-10-146-187.dsl.teksavvy.com ([76.10.146.187] helo=ceviche.home) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JP7zk-000587-L7; Tue, 12 Feb 2008 22:09:13 -0500 Original-Received: by ceviche.home (Postfix, from userid 20848) id 42F4AB44AD; Tue, 12 Feb 2008 22:09:06 -0500 (EST) In-Reply-To: <200802100803.m1A83Eq5026472@sallyv1.ics.uci.edu> (Dan Nicolaescu's message of "Sun, 10 Feb 2008 00:03:11 -0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:88928 gmane.emacs.pretest.bugs:21056 Archived-At: > emacs -Q -nw -f server-start > emacsclient -c -d $DISPLAY& > xkill > the emacsclient X11 frame > then C-x C-c in the emacs -nw frame will warn about clients still being > connected. > Same thing when instead of using xkill, kill X11. So I looked at the issue of letting know server.el when an X11 connection is abruptly closed as above. I created a new event DELETE_TERMINAL_EVENT; changed Fdelete_terminal to generate such an event; changed x_connection_closed to call Fdelete_terminal and ... it didn't work. The problem is that x_connection_closed ends up signalling an error, which flushes the input queue and hence throws away the DELETE_TERMINAL_EVENT we just created. So, I removed the `error' call, but this makes things worse, apparently: Emacs then exits abruptly. It seems that it's important to abort execution at the end of x_connection_closed. So I re[placed the `error' call by a call to Fthrow. This finally worked. But now I wonder: is DELETE_TERMINAL_EVENT the right thing to do, or should we use run-at-time instead? Find attach my current attempt, Stefan ? src/.depend cvs diff: Diffing src Index: src/keyboard.c =================================================================== RCS file: /sources/emacs/emacs/src/keyboard.c,v retrieving revision 1.946 diff -u -r1.946 keyboard.c --- src/keyboard.c 12 Feb 2008 04:05:29 -0000 1.946 +++ src/keyboard.c 13 Feb 2008 03:06:48 -0000 @@ -466,6 +466,7 @@ Lisp_Object Qscroll_bar_movement; Lisp_Object Qswitch_frame; Lisp_Object Qdelete_frame; +Lisp_Object Qdelete_terminal; Lisp_Object Qiconify_frame; Lisp_Object Qmake_frame_visible; Lisp_Object Qselect_window; @@ -4195,6 +4196,11 @@ kbd_fetch_ptr = event + 1; } #endif + else if (event->kind == DELETE_TERMINAL_EVENT) + { + obj = Fcons (Qdelete_terminal, Fcons (event->frame_or_window, Qnil)); + kbd_fetch_ptr = event + 1; + } #if defined (HAVE_X11) || defined (HAVE_NTGUI) || defined (MAC_OS) else if (event->kind == ICONIFY_EVENT) { @@ -11718,6 +11724,7 @@ {&Qscroll_bar_movement, "scroll-bar-movement", &Qmouse_movement}, {&Qswitch_frame, "switch-frame", &Qswitch_frame}, {&Qdelete_frame, "delete-frame", &Qdelete_frame}, + {&Qdelete_terminal, "delete-terminal", &Qdelete_terminal}, {&Qiconify_frame, "iconify-frame", &Qiconify_frame}, {&Qmake_frame_visible, "make-frame-visible", &Qmake_frame_visible}, /* `select-window' should be handled just like `switch-frame' Index: src/lisp.h =================================================================== RCS file: /sources/emacs/emacs/src/lisp.h,v retrieving revision 1.611 diff -u -r1.611 lisp.h --- src/lisp.h 12 Feb 2008 21:35:14 -0000 1.611 +++ src/lisp.h 13 Feb 2008 03:06:49 -0000 @@ -3261,6 +3261,7 @@ extern void fatal P_ ((const char *msgid, ...)) NO_RETURN; /* Defined in terminal.c */ +EXFUN (Fdelete_terminal, 2); extern void syms_of_terminal P_ ((void)); #ifdef HAVE_WINDOW_SYSTEM Index: src/puresize.h =================================================================== RCS file: /sources/emacs/emacs/src/puresize.h,v retrieving revision 1.104 diff -u -r1.104 puresize.h --- src/puresize.h 1 Feb 2008 23:29:14 -0000 1.104 +++ src/puresize.h 13 Feb 2008 03:06:49 -0000 @@ -35,7 +35,7 @@ amount of storage. This is a lot more update-robust that defining BASE_PURESIZE or even PURESIZE directly. */ #ifndef SYSTEM_PURESIZE_EXTRA -#define SYSTEM_PURESIZE_EXTRA 0 +#define SYSTEM_PURESIZE_EXTRA 1000000 #endif #ifndef SITELOAD_PURESIZE_EXTRA Index: src/termhooks.h =================================================================== RCS file: /sources/emacs/emacs/src/termhooks.h,v retrieving revision 1.91 diff -u -r1.91 termhooks.h --- src/termhooks.h 8 Jan 2008 20:44:20 -0000 1.91 +++ src/termhooks.h 13 Feb 2008 03:06:49 -0000 @@ -137,6 +137,7 @@ SELECTION_CLEAR_EVENT, /* Another X client cleared our selection. */ BUFFER_SWITCH_EVENT, /* A process filter has switched buffers. */ DELETE_WINDOW_EVENT, /* An X client said "delete this window". */ + DELETE_TERMINAL_EVENT, /* A terminal was deleted. */ MENU_BAR_EVENT, /* An event generated by the menu bar. The frame_or_window field's cdr holds the Lisp-level event value. Index: src/terminal.c =================================================================== RCS file: /sources/emacs/emacs/src/terminal.c,v retrieving revision 1.9 diff -u -r1.9 terminal.c --- src/terminal.c 11 Feb 2008 03:51:39 -0000 1.9 +++ src/terminal.c 13 Feb 2008 03:06:49 -0000 @@ -320,6 +320,15 @@ error ("Attempt to delete the sole active display terminal"); } + if (!NILP (Vrun_hooks)) + { + struct input_event ie; + ie.kind = DELETE_TERMINAL_EVENT; + ie.arg = Qnil; + XSETTERMINAL (ie.frame_or_window, t); + kbd_buffer_store_event (&ie); + } + if (t->delete_terminal_hook) (*t->delete_terminal_hook) (t); else Index: src/xterm.c =================================================================== RCS file: /sources/emacs/emacs/src/xterm.c,v retrieving revision 1.975 diff -u -r1.975 xterm.c --- src/xterm.c 10 Feb 2008 21:56:37 -0000 1.975 +++ src/xterm.c 13 Feb 2008 03:06:50 -0000 @@ -8093,10 +8093,11 @@ OpenWindows in certain situations. I suspect that is a bug in OpenWindows. I don't know how to circumvent it here. */ + if (dpyinfo) + { #ifdef USE_X_TOOLKIT /* If DPYINFO is null, this means we didn't open the display in the first place, so don't try to close it. */ - if (dpyinfo) { extern void (*fatal_error_signal_hook) P_ ((void)); fatal_error_signal_hook = x_fatal_error_signal; @@ -8106,12 +8107,9 @@ #endif #ifdef USE_GTK - if (dpyinfo) xg_display_close (dpyinfo->display); #endif - if (dpyinfo) - { /* Indicate that this display is dead. */ dpyinfo->display = 0; @@ -8121,7 +8119,14 @@ /* We have just closed all frames on this display. */ abort (); - x_delete_display (dpyinfo); + { + struct terminal *t = terminal_list; + Lisp_Object tmp; + while (t && t->display_info.x != dpyinfo) + t = t->next_terminal; + XSETTERMINAL (tmp, t); + Fdelete_terminal (tmp, Qnoelisp); + } } x_uncatch_errors (); @@ -8146,7 +8151,10 @@ error might not be the best thing to do. I'd vote for creating an elisp event and stuffing it in the queue so people can bind to it via the global map. --Stef */ - error ("%s", error_msg); + /* We used to throw an error, but this flushes the input_event queue, + on which we just put a DELETE_TERMINAL_EVENT :-( + error ("%s", error_msg) */ + Fthrow (Qtop_level, Qnil); } /* We specifically use it before defining it, so that gcc doesn't inline it, @@ -11812,6 +11812,10 @@ return; BLOCK_INPUT; + /* When called from x_connection_closed, the display is already closed + and dpyinfo->display was set to 0 to indicate that. */ + if (dpyinfo->display) + { #ifdef USE_FONT_BACKEND if (! enable_font_backend) #endif @@ -11834,6 +11838,7 @@ XCloseDisplay (dpyinfo->display); #endif #endif /* ! USE_GTK */ + } x_delete_display (dpyinfo); UNBLOCK_INPUT; cvs diff: Diffing src/bitmaps cvs diff: Diffing src/m cvs diff: Diffing src/s