From 56fc0aef450e199bc93ea75b15dff778713de81f Mon Sep 17 00:00:00 2001 From: Matthew Leach Date: Sat, 26 Mar 2016 20:43:26 +0000 Subject: [PATCH 4/4] When Emacs is passed a socket descriptor, make the server listen on it. * lisp/server.el (server-start): Set :use-external-socket to `t' when calling `make-network-process'. * etc/NEWS: Document new socket-passing functionality and the configure option to disable systemd interaction. * doc/emacs/misc.texi (Emacs Server): Document systemd socket passing functionality and provide systemd unit examples. --- doc/emacs/misc.texi | 38 ++++++++++++++++++++++++++++++++++++++ etc/NEWS | 7 +++++++ lisp/server.el | 1 + 3 files changed, 46 insertions(+) diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index b5a2150..775cda9 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -1580,6 +1580,44 @@ option. @xref{Initial Options}. When Emacs is started this way, it calls @code{server-start} after initialization, and returns control to the calling terminal instead of opening an initial frame; it then waits in the background, listening for edit requests. + +@cindex socket activation, systemd, Emacs +@item +An external process can invoke the Emacs server when a connection +event occurs upon a specified socket and pass the socket to the new +Emacs server process. An instance of this is @command{systemd}'s +socket functionaly: the @command{systemd} service creates a socket and +listens for connections on it; when @command{emacsclient} connects to +it for the first time, @command{systemd} can launch the Emacs server +and hand over the socket to it for servicing @command{emacsclient} +connections. A setup to use this functionality could be: + +@file{~/.config/systemd/user/emacs.service}: +@example +[Unit] +Description=Emacs + +[Service] +Type=forking +ExecStart=/path/to/emacs --daemon +ExecStop=/path/to/emacsclient --eval "(kill-emacs)" +Restart=always + +[Install] +WantedBy=default.target +@end example + +@file{~/.config/systemd/user/emacs.socket}: +@example +[Socket] +ListenStream=/path/to/.emacs.socket + +[Install] +WantedBy=sockets.target +@end example + +The @code{ListenStream} path will be the path that Emacs listens for +connections from @command{emacsclient}; this is a file of your choice. @end itemize @cindex @env{TEXEDIT} environment variable diff --git a/etc/NEWS b/etc/NEWS index 66777e9..f395d45 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -26,6 +26,13 @@ otherwise leave it unmarked. * Installation Changes in Emacs 25.2 +++ +** Emacs server now has socket-launching support. This allows socket +based activation, where an external process can invoke the Emacs +server process upon a socket connection event and hand over the socket +to Emacs. Emacs will use this socket for servicing emacsclient +commands. systemd can make use of this new functionally but can be +disabled with the configure option '--disable-libsystemd'. + ** New configure option '--disable-build-details' attempts to build an Emacs that is more likely to be reproducible; that is, if you build and install Emacs twice, the second Emacs is a copy of the first. diff --git a/lisp/server.el b/lisp/server.el index 5243820..2a9729e 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -655,6 +655,7 @@ server or call `\\[server-force-delete]' to forcibly disconnect it.")) :noquery t :sentinel #'server-sentinel :filter #'server-process-filter + :use-external-socket t ;; We must receive file names without being decoded. ;; Those are decoded by server-process-filter according ;; to file-name-coding-system. Also don't get -- 2.8.0