unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Functions in kill-emacs-hook aren't run if emacs gets killed with SIGTERM
@ 2009-01-21  8:06 Tassilo Horn
  2009-01-21 18:42 ` Eli Zaretskii
  0 siblings, 1 reply; 53+ messages in thread
From: Tassilo Horn @ 2009-01-21  8:06 UTC (permalink / raw)
  To: emacs-devel

Hi,

I use emacs --daemon as system service and it's started and stopped by
the start-stop-daemon utility.  Now I found out that all the functions
in `kill-emacs-hook' aren't run when start-stop-daemon stops the emacs
process.  I'm not sure how it stops it, but I think it's by sending a
SIGTERM to the process, waiting some seconds and then firing an SIGKILL
if the process didn't finish.

How does emacs handle SIGTERM?  Doesn't it simply run `kill-emacs'?  At
least that's what I would expect.

A related question: What does emacs --daemon do when it receives a
SIGTERM and there are unsaved buffers?

Bye,
Tassilo




^ permalink raw reply	[flat|nested] 53+ messages in thread
* Re: Functions in kill-emacs-hook aren't run if emacs gets killed with SIGTERM
@ 2009-01-23 19:01 grischka
  2009-01-23 22:52 ` Eli Zaretskii
  0 siblings, 1 reply; 53+ messages in thread
From: grischka @ 2009-01-23 19:01 UTC (permalink / raw)
  To: eliz; +Cc: emacs-devel

> On balance, I would leave things as they are, i.e. don't run
> kill-emacs-hook when we get SIGTERM.  After all, we are being killed,
> so only the minimum necessary cleanup should be in order.

That seems to me like a quite twisted argumentation to say that
	"kill-emacs-hook"
should NOT be run because
	"After all, we are being killed ...".

Btw, with SIGINT emacs (GTK) quits like this
	Fatal Error (6)Abort
Is this a bug?

--- grischka





^ permalink raw reply	[flat|nested] 53+ messages in thread
* Re: Functions in kill-emacs-hook aren't run if emacs gets killed with SIGTERM
@ 2009-01-24 20:32 Stefan Monnier
  2009-02-02 20:23 ` Eli Zaretskii
  0 siblings, 1 reply; 53+ messages in thread
From: Stefan Monnier @ 2009-01-24 20:32 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: tassilo, emacs-devel

> We may also delay it indefinitely if we run Lisp, because that could
> infloop, especially if our internal data structures are unstable.

What makes you think our data structures might be unstable when we
get SIGTERM?  AFAIK this signal is only received when some external
process decides that Emacs should stop, so data structures should be
just as stable as when we receive SIGUSRn.

> If SIGTERM is used to programmatically shut down Emacs, I think it's
> rather a conceptual bug in whatever uses SIGTERM for that purpose.

Huh?  SIGTERM is *the canonical way* to programmatically shut down an
application via a signal.


        Stefan




^ permalink raw reply	[flat|nested] 53+ messages in thread
* Re: Functions in kill-emacs-hook aren't run if emacs gets killed with SIGTERM
@ 2009-01-24 20:39 Stefan Monnier
  0 siblings, 0 replies; 53+ messages in thread
From: Stefan Monnier @ 2009-01-24 20:39 UTC (permalink / raw)
  To: Jason Rumney; +Cc: Eli Zaretskii, tassilo, emacs-devel

>> On balance, I would leave things as they are, i.e. don't run
>> kill-emacs-hook when we get SIGTERM.  After all, we are being killed,
>> so only the minimum necessary cleanup should be in order.
> Another case for not running kill-emacs-hook for SIGTERM is that some elisp
> packages seem to get themselves into inconsistent states (semantic is
> terrible for this) where they throw errors from kill-emacs-hook, so the user
> is forced to kill emacs using SIGTERM. Changing SIGTERM to also run
> kill-emacs-hook would mean only SIGKILL can kill emacs in
> these circumstances.

I'd think that throwing errors from kill-emacs-hook should not prevent
Emacs from exiting.  Can someone look into this and fix the problem?


        Stefan




^ permalink raw reply	[flat|nested] 53+ messages in thread
* Re: Functions in kill-emacs-hook aren't run if emacs gets killed with SIGTERM
@ 2009-02-03 17:28 grischka
  2009-02-05  3:37 ` Stefan Monnier
  0 siblings, 1 reply; 53+ messages in thread
From: grischka @ 2009-02-03 17:28 UTC (permalink / raw)
  To: tassilo; +Cc: emacs-devel

From:     Tassilo Horn
 > I don't get what could be so dangerous running a user-defined hook after
 > all buffers have been saved, as Stefan suggested.  The worst case I can
 > imagine is that one of the functions accesses a file but is too slow,
 > and a subsequent SIGKILL causes some data loss.

Actually it requires only three lines to get something that seems to
work quite nicely, at least for demonstration purposes.

Replace one line in emacs.c:~1315:

-  signal (SIGTERM, fatal_error_signal);
+  add_user_signal (SIGTERM, "sigterm");

and add some lisp to catch the signal (can be put into .emacs, to begin with)

(define-key special-event-map [sigterm] 'sigterm-handler)
(defun sigterm-handler () (interactive) (kill-emacs))

Where kill-emacs will also run the kill-emacs-hooks in a safe way, as intended.





^ permalink raw reply	[flat|nested] 53+ messages in thread

end of thread, other threads:[~2009-02-05 19:40 UTC | newest]

Thread overview: 53+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-21  8:06 Functions in kill-emacs-hook aren't run if emacs gets killed with SIGTERM Tassilo Horn
2009-01-21 18:42 ` Eli Zaretskii
2009-01-21 19:49   ` Tassilo Horn
2009-01-21 20:35     ` Chong Yidong
2009-01-22  9:03       ` Tassilo Horn
2009-01-21 20:36   ` Stefan Monnier
2009-01-22  4:09     ` Eli Zaretskii
2009-01-22  9:00       ` Tassilo Horn
2009-01-22 18:23         ` Eli Zaretskii
2009-01-23  2:15           ` mail
2009-01-23 12:05             ` Eli Zaretskii
2009-01-22 10:08       ` Andreas Schwab
2009-01-22 18:25         ` Eli Zaretskii
2009-01-23  1:52         ` Richard M Stallman
2009-01-22 14:41       ` Stefan Monnier
2009-01-22 18:32         ` Eli Zaretskii
2009-01-22 21:16           ` Stefan Monnier
2009-01-23 15:25             ` Eli Zaretskii
2009-01-23 15:58               ` Tassilo Horn
2009-01-23 19:06                 ` Eli Zaretskii
2009-01-23 19:56                   ` David De La Harpe Golden
2009-01-23 22:39                     ` Eli Zaretskii
2009-01-23 23:00                       ` Tassilo Horn
2009-01-23 23:13                         ` Lennart Borgman
2009-01-24  9:04                           ` Tassilo Horn
2009-01-24  9:59                             ` Eli Zaretskii
2009-01-24 12:34                               ` Miles Bader
2009-01-24 10:00                             ` Eli Zaretskii
2009-01-23 20:33                   ` Dan Nicolaescu
2009-01-23 22:37                     ` Eli Zaretskii
2009-01-24  4:40               ` Jason Rumney
2009-01-24  6:11                 ` Miles Bader
2009-01-23  1:52         ` Richard M Stallman
  -- strict thread matches above, loose matches on Subject: below --
2009-01-23 19:01 grischka
2009-01-23 22:52 ` Eli Zaretskii
2009-01-24 14:16   ` grischka
2009-01-24 16:14     ` Eli Zaretskii
2009-01-24 17:56       ` grischka
2009-01-24 18:20         ` Eli Zaretskii
2009-01-24 19:11           ` grischka
2009-01-24 20:08             ` Eli Zaretskii
2009-01-24 20:28               ` grischka
2009-01-24 20:32 Stefan Monnier
2009-02-02 20:23 ` Eli Zaretskii
2009-02-02 20:52   ` Tassilo Horn
2009-02-02 21:09     ` Eli Zaretskii
2009-02-03 10:43       ` Tassilo Horn
2009-02-05  3:34   ` Stefan Monnier
2009-01-24 20:39 Stefan Monnier
2009-02-03 17:28 grischka
2009-02-05  3:37 ` Stefan Monnier
2009-02-05 13:31   ` grischka
2009-02-05 19:40     ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).