From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Stefan Monnier" Newsgroups: gmane.emacs.devel Subject: Re: Functions in kill-emacs-hook aren't run if emacs gets killed with SIGTERM Date: Thu, 22 Jan 2009 16:16:37 -0500 Message-ID: References: <87prihxeu5.fsf@thinkpad.tsdh.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1232659417 19159 80.91.229.12 (22 Jan 2009 21:23:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 22 Jan 2009 21:23:37 +0000 (UTC) Cc: tassilo@member.fsf.org, emacs-devel@gnu.org To: "Eli Zaretskii" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jan 22 22:24:49 2009 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 1LQ72d-0001sA-82 for ged-emacs-devel@m.gmane.org; Thu, 22 Jan 2009 22:24:47 +0100 Original-Received: from localhost ([127.0.0.1]:34851 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LQ71L-0007EY-G3 for ged-emacs-devel@m.gmane.org; Thu, 22 Jan 2009 16:23:27 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LQ6ur-0006yk-Up for emacs-devel@gnu.org; Thu, 22 Jan 2009 16:16:46 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LQ6ur-0006xQ-7Q for emacs-devel@gnu.org; Thu, 22 Jan 2009 16:16:45 -0500 Original-Received: from [199.232.76.173] (port=49489 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LQ6ur-0006x9-4A for emacs-devel@gnu.org; Thu, 22 Jan 2009 16:16:45 -0500 Original-Received: from mail.g-wis.com ([204.250.154.18]:1580) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LQ6un-0008OE-Tz; Thu, 22 Jan 2009 16:16:42 -0500 thread-index: Acl81reuQ1s7BWq6QfSVUvoTf7Nztg== X-Received-From-Address: 69.38.23.210 X-Envelope-From: monnier@iro.umontreal.ca X-Envelope-To: eliz@gnu.org, emacs-devel@gnu.org, tassilo@member.fsf.org, monnier@iro.umontreal.ca Original-Received: from ceviche.home ([69.38.23.210]) by mail.g-wis.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 22 Jan 2009 13:16:39 -0800 Original-Received: by ceviche.home (Postfix, from userid 20848) id EC270B400C; Thu, 22 Jan 2009 16:16:37 -0500 (EST) Content-Class: urn:content-classes:message Importance: normal Priority: normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4325 In-Reply-To: (Eli Zaretskii's message of "Thu, 22 Jan2009 20:32:43 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-OriginalArrivalTime: 22 Jan 2009 21:16:39.0516 (UTC) FILETIME=[B73291C0:01C97CD6] X-detected-operating-system: by monty-python.gnu.org: Windows 2000 SP4, XP SP1+ 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:108114 Archived-At: >> I don't know what you mean by "interrupt code in dangerous state". >> AFAIK, the only difference between SIGTERM and SIGUSRn is that SIGTERM >> has a clear intention "please exit now", whereas the other ones's >> intention is user-specified. > Right, and that's what I meant: SIGTERM usually causes an exit, while > SIGUSR can set a flag and do its thing later. It's common for SIGTERM to delay the exit a little bit. It usually affords to do some cleanup (e.g. we perform autosaves). >> > The fact that SIGTERM in this case is a programmed means to stop Emacs >> > does not mean it's the only use case where SIGTERM is delivered >> > to Emacs. >> >> Definitely, but in all cases I can think of, running kill-emacs-hook is >> a good idea. This assumes that the functions placed on kill-emacs-hook >> follow the recommendation of the docstring: >> >> Since `kill-emacs' may be invoked when the terminal is disconnected >> (or in other similar situations), functions placed on this hook >> should not expect to be able to interact with the user. > I'm more worried by the possibility that they run Lisp code when Emacs > is in unstable state. The only sane way to implement it is via an event, just like SIGUSRn, so I don't see why there would be such a risk. The risk would rather be the opposite: that by delaying execution to a safe time, we may delay it indefinitely. >> Maybe another option is to first perform the autosaves (like >> shut_down_emacs does), and then run a hook. > I'm not sure this is enough. We may need to defer exiting until it is > safe to call Lisp code. I'm sure I understand what you mean by "enough", because I'm not sure what you think is necessary. To me what is necessary is: 1 - don't lose data. 2 - exit reasonably promptly. So doing the autosaves before running the hook should make sure 1 is preserved. But running the hook may indeed make us lose 2. Is that what you meant by "not enough"? To keep number 2, we could schedule a SIGALRM so as to forcefully exit after a timeout, in case running the hook doesn't happen quickly enough. Stefan