From a09250b5c53c8da1157135f1ace2ecd4748d6510 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-systemd-socket to `t' when calling `make-network-process'. * etc/NEWS: Document new systemd functionality and build option to disable it. * doc/emacs/misc.texi (Emacs Server): Document systemd socket passing functionality and provide systemd unit examples. --- doc/emacs/misc.texi | 37 +++++++++++++++++++++++++++++++++++++ etc/NEWS | 7 +++++++ lisp/server.el | 1 + 3 files changed, 45 insertions(+) diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index b5a2150..2622592 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -1580,6 +1580,43 @@ 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 +If Emacs has been built with @command{systemd} support, the Emacs +server can be started by socket activation. 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 hands 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..9afed5b 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -26,6 +26,13 @@ otherwise leave it unmarked. * Installation Changes in Emacs 25.2 +++ +** Emacs now has systemd support. This allows socket based +activation, where systemd can invoke the Emacs process upon a +socket connection and hand over the socket to Emacs. Emacs will +use this socket for communicating with the emacsclient program. +This can be disabled with the new configure option +'--disable-systemd'. + ** 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..2c9113c 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-systemd-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.7.4