Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 337829 - app-emacs/emacs-daemon-0.17 call kill-emacs upon stopping
Summary: app-emacs/emacs-daemon-0.17 call kill-emacs upon stopping
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Emacs project
URL: http://lists.gnu.org/archive/html/ema...
Whiteboard:
Keywords: InVCS
Depends on:
Blocks:
 
Reported: 2010-09-18 10:01 UTC by MageSlayer
Modified: 2010-09-20 18:25 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
init.d script patch (emacs.ebuild.patch,1.23 KB, patch)
2010-09-18 10:02 UTC, MageSlayer
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description MageSlayer 2010-09-18 10:01:48 UTC
I'd like to propose a change to emacs-vcs ebuild.
Primary aim of this patch is allow emacs to shutdown gracefully.
Current shutdown method does not trigger kill-emacs-query-functions, kill-emacs-hook, server-done-hook hooks.

Reproducible: Always
Comment 1 MageSlayer 2010-09-18 10:02:22 UTC
Created attachment 247762 [details, diff]
init.d script patch
Comment 2 Ulrich Müller gentoo-dev 2010-09-18 11:35:56 UTC
Have you tested this with both baselayout-1 and openrc?
Comment 3 MageSlayer 2010-09-18 11:44:25 UTC
(In reply to comment #2)
> Have you tested this with both baselayout-1 and openrc?
> 

Tested only under baselayout-1.                                                                                                                                                                           
                                                                                                                                                                                                          
But I doubt openrc differs somehow.                                                                                                                                                                       
                                                                                                                                                                                                          
The problem actually in emacs itself. See http://stackoverflow.com/questions/3737207/emacsclient-hook-on-kill for details.
Comment 4 Ulrich Müller gentoo-dev 2010-09-18 12:10:27 UTC
(In reply to comment #3)
> The problem actually in emacs itself. See
> http://stackoverflow.com/questions/3737207/emacsclient-hook-on-kill for
> details.

Right, and the discussion that is linked there was a previous request from Tassilo Horn (see URL), with bug 246462 being the corresponding Gentoo bug.
And now I remember that we have already implemented something to provide for such additional functionality when stopping.

Basically, you should set EMACS_STOP to point to a script that will call emacsclient.

However, I'm reluctant to add any sort of interactive behaviour to the default shutdown sequence. Reception of SIGTERM in Emacs will call shut_down_emacs which at least autosaves all buffers, so there should be no data loss. Beyond that, users' preferences for shutdown behaviour may be very different, and I think that the EMACS_STOP solution is general enough to account for the different needs.


*** This bug has been marked as a duplicate of bug 246462 ***
Comment 5 MageSlayer 2010-09-18 12:40:40 UTC
(In reply to comment #4)
Ok, I see now.

But why not add this or similar script to /usr/share/emacs... and provide it as a standard solution to stop reinventing the wheel each time?
Comment 6 MageSlayer 2010-09-18 13:06:48 UTC
The problem with external stop script now is that it cannot get environment variables from /etc/init.d runscript. To shutdown emacs properly at least USER, EMACS, PIDFILE should be exported. SVCNAME preferably too.
Comment 7 Ulrich Müller gentoo-dev 2010-09-18 15:27:37 UTC
(In reply to comment #5)
> But why not add this or similar script to /usr/share/emacs... and provide it
> as a standard solution to stop reinventing the wheel each time?

Yes, I'll consider this. It should go to /usr/libexec/emacs/ or /usr/share/doc/emacs-daemon-*/ though. And I won't assign EMACS_STOP by default.

(In reply to comment #6)
> The problem with external stop script now is that it cannot get environment
> variables from /etc/init.d runscript. To shutdown emacs properly at least
> USER, EMACS, PIDFILE should be exported.

EMACS_DEBUG and EMACS_TIMEOUT, too. I wonder why nobody has complained yet that those variables are not exported. Seems that at least USER would be needed, unless one has a separate stop script for each user.

> SVCNAME preferably too.

This is an internal runscript variable, so it normally shouldn't be exported (also it was renamed to RC_SVCNAME in openrc, where SVCNAME is only kept for backwards compatibility).
Comment 8 Ulrich Müller gentoo-dev 2010-09-18 20:27:06 UTC
Could you test if this change would suit your needs:
http://sources.gentoo.org/cgi-bin/viewvc.cgi/emacs?view=revision&revision=1564

The emacs-stop.sh script is only meant as an example, therefore I've kept it as simple as possible. Especially, emacsclient calls (kill-emacs) only.
Comment 9 MageSlayer 2010-09-19 06:46:48 UTC
(In reply to comment #8)
> Could you test if this change would suit your needs:
> http://sources.gentoo.org/cgi-bin/viewvc.cgi/emacs?view=revision&revision=1564
> 
> The emacs-stop.sh script is only meant as an example, therefore I've kept it as
> simple as possible. Especially, emacsclient calls (kill-emacs) only.
> 

This simple example works ok except the case when some client is connected to emacsserver. In this case, a message asking to disconnect pops in emacs, but kill-emacs is never completed. Thus emacs will be killed after timeout.

But that's not a real problem. The real problem with such simple script is that unsaved buffers are not saved. Thus we have a data loss.

That's why I suggest you to add more logic (e.g. from my patch) to EMACS_LISP_EXPR, cause now it's plain error-prone.
Comment 10 Ulrich Müller gentoo-dev 2010-09-19 10:04:41 UTC
As I said before, users' preferences may be very different. And there's no need to pass everything in emacsclient's argument, since any additional commands can be added to kill-emacs-hook. This has the additional advantage that it can be set individually by each user.

But I've added a comment with a short explanation:
http://sources.gentoo.org/cgi-bin/viewvc.cgi/emacs?view=revision&revision=1565
Comment 11 MageSlayer 2010-09-19 17:50:03 UTC
(In reply to comment #10)
> As I said before, users' preferences may be very different. And there's no need
> to pass everything in emacsclient's argument, since any additional commands can
> be added to kill-emacs-hook. This has the additional advantage that it can be
> set individually by each user.
> 
> But I've added a comment with a short explanation:
> http://sources.gentoo.org/cgi-bin/viewvc.cgi/emacs?view=revision&revision=1565
> 

Ok. You are a maintainer after all :)
Release it!
Comment 12 Ulrich Müller gentoo-dev 2010-09-20 18:25:37 UTC
Included with version 0.18.
Thanks.