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#16093: 24.3.50; Crash of emacs --daemon on killing X server Date: Mon, 09 Dec 2013 21:57:59 +0400 Message-ID: <52A604A7.6010104@yandex.ru> References: <87siu2uics.fsf@spindle.srvr.nix> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------070706050908070209090207" X-Trace: ger.gmane.org 1386611959 25778 80.91.229.3 (9 Dec 2013 17:59:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 9 Dec 2013 17:59:19 +0000 (UTC) To: 16093@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Dec 09 18:59:24 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 1Vq572-0000nv-NJ for geb-bug-gnu-emacs@m.gmane.org; Mon, 09 Dec 2013 18:59:20 +0100 Original-Received: from localhost ([::1]:45187 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vq572-0003ch-2B for geb-bug-gnu-emacs@m.gmane.org; Mon, 09 Dec 2013 12:59:20 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44402) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vq56t-0003V2-1s for bug-gnu-emacs@gnu.org; Mon, 09 Dec 2013 12:59:18 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vq56l-0002SU-Cm for bug-gnu-emacs@gnu.org; Mon, 09 Dec 2013 12:59:10 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:54700) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vq56l-0002SN-0i for bug-gnu-emacs@gnu.org; Mon, 09 Dec 2013 12:59:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Vq56k-0001cD-At for bug-gnu-emacs@gnu.org; Mon, 09 Dec 2013 12:59:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Antipov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 09 Dec 2013 17:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16093 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 16093-submit@debbugs.gnu.org id=B16093.13866118876125 (code B ref 16093); Mon, 09 Dec 2013 17:59:02 +0000 Original-Received: (at 16093) by debbugs.gnu.org; 9 Dec 2013 17:58:07 +0000 Original-Received: from localhost ([127.0.0.1]:40485 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vq55q-0001ai-By for submit@debbugs.gnu.org; Mon, 09 Dec 2013 12:58:06 -0500 Original-Received: from forward4o.mail.yandex.net ([37.140.190.33]:53247) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vq55m-0001aK-BU for 16093@debbugs.gnu.org; Mon, 09 Dec 2013 12:58:03 -0500 Original-Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [37.140.190.29]) by forward4o.mail.yandex.net (Yandex) with ESMTP id B8DCB564107B; Mon, 9 Dec 2013 21:58:00 +0400 (MSK) Original-Received: from smtp4o.mail.yandex.net (localhost [127.0.0.1]) by smtp4o.mail.yandex.net (Yandex) with ESMTP id 5EE52232014F; Mon, 9 Dec 2013 21:58:00 +0400 (MSK) Original-Received: from unknown (unknown [37.139.80.10]) by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id igdowVDgS9-vxheFCKn; Mon, 9 Dec 2013 21:57:59 +0400 (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1386611879; bh=B2lLBeHjPVcL7XaFfnpMFrVnc8e9p2aO4Qt4Cbl3EXs=; h=Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: References:In-Reply-To:Content-Type; b=vSMvSsfYIpzzCPjOcad5wFpV9DOjixJzEQYDEH1eUbsCuA16qME9sbeoHCpkj+qzn mrkMOburxe/dVHc2QqKty126o+5W6bdM0XVIpy/YbTphG0VOB76TmcHTeK/w/CyJuN lG32tIox+F2z/8HfrnYW8okBxLYTokop3AJ0NTxU= Authentication-Results: smtp4o.mail.yandex.net; dkim=pass header.i=@yandex.ru User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 In-Reply-To: <87siu2uics.fsf@spindle.srvr.nix> 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:81653 Archived-At: This is a multi-part message in MIME format. --------------070706050908070209090207 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/09/2013 07:58 PM, Nix wrote: > > Start emacs --daemon (using the lucid toolkit), under X. Shut X down. > Emacs crashes shortly afterwards. > > > The lack of symbol table info is concerning (obviously my gdb has > forgotten how to look up separated debug info *yet again*), but I don't > think that important, since the death site is after a (garbage-collect) > thus not in Lisp-land anyway. Obviously no xbacktrace is possible: the > process is dead. > > It is fairly clear that we should not be calling xftfont_close() if the > X server is not there! Why has this started happening? Hm... IIUC there is no convenient way to check whether X display connection is alive. But we can do some tricks, for example, try to select() or poll() ConnectionNumber() - if there is no EBADF, X server is hopefully present... Dmitry --------------070706050908070209090207 Content-Type: text/x-patch; name="bug16093.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="bug16093.patch" === modified file 'src/xfns.c' --- src/xfns.c 2013-12-03 17:22:05 +0000 +++ src/xfns.c 2013-12-09 17:50:35 +0000 @@ -136,6 +136,20 @@ static struct x_display_info *x_display_info_for_name (Lisp_Object); +bool +x_display_valid (Display *d) +{ + fd_set fdset; + struct timespec timeout; + int fd = ConnectionNumber (d); + + FD_ZERO (&fdset); + FD_SET (fd, &fdset); + timeout.tv_sec = 0; + timeout.tv_nsec = 1000; + return pselect (fd + 1, &fdset, NULL, NULL, &timeout, NULL) != -1; +} + /* Let the user specify an X display with a Lisp object. OBJECT may be nil, a frame or a terminal object. nil stands for the selected frame--or, if that is not an X frame, === modified file 'src/xfont.c' --- src/xfont.c 2013-11-04 06:09:03 +0000 +++ src/xfont.c 2013-12-09 17:47:41 +0000 @@ -897,7 +897,8 @@ if (xfi->xfont) { block_input (); - XFreeFont (xfi->display, xfi->xfont); + if (x_display_valid (xfi->display)) + XFreeFont (xfi->display, xfi->xfont); unblock_input (); xfi->xfont = NULL; } === modified file 'src/xftfont.c' --- src/xftfont.c 2013-10-27 05:30:34 +0000 +++ src/xftfont.c 2013-12-09 17:48:47 +0000 @@ -495,7 +495,8 @@ { block_input (); XftUnlockFace (xftfont_info->xftfont); - XftFontClose (xftfont_info->display, xftfont_info->xftfont); + if (x_display_valid (xftfont_info->display)) + XftFontClose (xftfont_info->display, xftfont_info->xftfont); unblock_input (); xftfont_info->xftfont = NULL; } === modified file 'src/xterm.h' --- src/xterm.h 2013-12-07 23:04:10 +0000 +++ src/xterm.h 2013-12-09 17:46:16 +0000 @@ -989,6 +989,7 @@ /* Defined in xfns.c */ extern Lisp_Object x_get_focus_frame (struct frame *); +extern bool x_display_valid (Display *); #ifdef USE_GTK extern int xg_set_icon (struct frame *, Lisp_Object); --------------070706050908070209090207--