Subject: bug#18375: 24.4.50; Emacs hangs X session manager logout in certain cases

From: Christoph Ruegge <[email-masked]>
Date: Wed, 3 Sep 2014 11:53:28 +0200

>>> If I may add, the current behaviour is rather weird to begin with. The
>>> SM integration's purpose is to cleanly shutdown Emacs on logout, so it
>>> should be tied to the entire process and not to a particular terminal.
>
>
> No. The reason is to have Emacs restarted when the user logs in again.
> Logout is no problem, the X connection will go away.

But that is not necessarily the only function of a session manager
(some SMs aren't even set to restart applications by default). They
also give applications the opportunity to query the user about unsaved
changes and such things. Now Emacs does not do that, but it's fairly
simple to do implement using `emacs-save-session-functions'.
Additionally, the only reason for me to log out is usually to restart
the computer, so Emacs will get killed anyway. Having the opportunity
to query about potential data loss may be useful.

That being said, I realize that my patch is rather intrusive and that
the more minimal solution of the daemon not using the SM at all is
better, especially since the daemon _can_ survive losing the X
connection (maybe in case of an X crash), which would lead to
unexpected behaviour in the next session. So one simply has to rely on
something like auto-save to prevent data loss.

Still, there's a corner case of the same bug occuring in non-daemon
mode, since it's technically possible to close the first terminal
after using e.g. "emacsclient -t", though that is likely a rather rare
situation.