From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David De La Harpe Golden Newsgroups: gmane.emacs.devel Subject: Re: Functions in kill-emacs-hook aren't run if emacs gets killed with SIGTERM Date: Fri, 23 Jan 2009 19:56:06 +0000 Message-ID: <497A20D6.4050208@harpegolden.net> References: <87prihxeu5.fsf@thinkpad.tsdh.de> <87ab9iggl0.fsf@thinkpad.tsdh.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1232740600 31854 80.91.229.12 (23 Jan 2009 19:56:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 23 Jan 2009 19:56:40 +0000 (UTC) To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jan 23 20:57:51 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 1LQS9t-0003ww-V1 for ged-emacs-devel@m.gmane.org; Fri, 23 Jan 2009 20:57:42 +0100 Original-Received: from localhost ([127.0.0.1]:55801 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LQS8c-00053Z-1g for ged-emacs-devel@m.gmane.org; Fri, 23 Jan 2009 14:56:22 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LQS8X-00053K-KQ for emacs-devel@gnu.org; Fri, 23 Jan 2009 14:56:17 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LQS8V-000538-6D for emacs-devel@gnu.org; Fri, 23 Jan 2009 14:56:16 -0500 Original-Received: from [199.232.76.173] (port=44248 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LQS8U-000535-WC for emacs-devel@gnu.org; Fri, 23 Jan 2009 14:56:15 -0500 Original-Received: from harpegolden.net ([65.99.215.13]:57532) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LQS8U-00014v-GD for emacs-devel@gnu.org; Fri, 23 Jan 2009 14:56:14 -0500 Original-Received: from [87.198.47.26] (87-198-47-26.ptr.magnet.ie [87.198.47.26]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "David De La Harpe Golden", Issuer "David De La Harpe Golden Personal CA rev 3" (verified OK)) by harpegolden.net (Postfix) with ESMTP id 56CBF8154 for ; Fri, 23 Jan 2009 19:56:12 +0000 (GMT) User-Agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103) In-Reply-To: X-detected-operating-system: by monty-python.gnu.org: GNU/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:108163 Archived-At: Eli Zaretskii wrote: >> From: Tassilo Horn >> Cc: Stefan Monnier , emacs-devel@gnu.org >> Date: Fri, 23 Jan 2009 16:58:03 +0100 >> >> Init or start-stop-daemon do that. >> >>> Why can't they use SIGUSRn? >> Because SIGUSRn has different meanings across applications, so the only >> reliable way to terminate a program is "kill " which send a >> SIGTERM. > > You can run your own script when the machine is shut down, can't you? > Then have that script deliver a SIGUSRn signal to Emacs and wait a few > moments for it to shut down peacefully. > Uh, but SIGTERM IS "please shutdown". Sorry, but _conventionally_ automated systems* will issue a SIGTERM to allow graceful shutdown, then a SIGKILL a few seconds later if the process hasn't promptly terminated like a good little process should. This is mere convention on unix and gnu, but is a very long standing one at this stage? Certainly USRn shouldn't be used where TERM would do and is conventional... SIGKILL, of course, is not a normal signal, it's a signal to the kernel to kill and eat the process whether the process likes it or not. But SIGTERM is a normal signal and it's IMO fine for emacs to do lots of cleanup actions before exit upon its receipt. So long as the emergency save happens ASAP, I'd consider dropping back to the main loop having queued an event that runs kill emacs hooks then exits upon SIGTERM (avoiding issues with running lisp code directly from a signal handler)- if there's a bug in one of the hooks, well, that just means emacs will then be kill -9'd, but that's life. SIGUSR1 should maybe close and reopen the emacsclient socket (see init, where USR1 closes and reopens the socket). * initscripts/daemon managers, batch systems like PBS... e.g. "When init is requested to change the runlevel, it sends the warning signal SIGTERM to all processes that are undefined in the new runlevel. It then waits 5 seconds before forcibly terminating these processes via the SIGKILL signal." - init "All processes are first notified that the system is going down by the signal SIGTERM. This gives programs like vi(1) the time to save the file being edited, mail and news processing programs a chance to exit cleanly, etc" - shutdown "A batch job being deleted by a server will be sent a SIGTERM signal following by a SIGKILL signal. The time delay between the two signals is an attribute of the execution queue... " - qdel (from PBS.)