diff options
author | Matthew Leach <matthew@mattleach.net> | 2016-04-16 12:43:01 +0300 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2016-04-16 12:43:01 +0300 |
commit | e390b7b54651d3c5a4c36168e84e96e197631f41 (patch) | |
tree | d4ccdf1d6e243e9a5f58b42e78de349a1ffbc6c2 /src/emacs.c | |
parent | bb8c8fdfbb226ea760e8e5761ecda98c8cd9564f (diff) | |
download | emacs-e390b7b54651d3c5a4c36168e84e96e197631f41.tar.gz emacs-e390b7b54651d3c5a4c36168e84e96e197631f41.tar.bz2 emacs-e390b7b54651d3c5a4c36168e84e96e197631f41.zip |
Add external socket launching support
* src/process.c (connect_network_socket): Allow a pre-allocated socket
descriptor to be used if passed to Emacs, avoiding the call to
'socket' and 'bind'.
(Fmake_network_process): Allow users to pass ':use-external-socket' in
the parameter plist to use any sockets that have been passed to Emacs.
(wait_reading_process_output): Call 'socket' and 'bind' every time.
(syms_of_process): New symbol ':use-external-socket'.
(set_external_socket_descriptor): New function.
(external_sock_fd): New variable.
* src/lisp.h: (set_external_socket_descriptor): New declaration.
* src/emacs.c (main): Call 'sd_listen_fds' to read the number of sockets
passed and call 'set_external_socket_descriptor' to set the external
socket.
* src/Makefile.in: Add libsystemd library and C flags to the Emacs
compilation options.
* configure.ac: Add new default-on option "systemd" and check for
libsystemd at configure time.
* 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/lispref/processes.texi (Network Processes): Document new
'make-network-process' option ':use-external-socket'.
Diffstat (limited to 'src/emacs.c')
-rw-r--r-- | src/emacs.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/emacs.c b/src/emacs.c index c21c9e3971c..a51df0903b1 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -56,6 +56,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <binary-io.h> #endif +#ifdef HAVE_LIBSYSTEMD +#include <systemd/sd-daemon.h> +#include <sys/socket.h> +#endif /* HAVE_LIBSYSTEMD */ + #ifdef HAVE_WINDOW_SYSTEM #include TERM_HEADER #endif /* HAVE_WINDOW_SYSTEM */ @@ -676,6 +681,9 @@ main (int argc, char **argv) char dname_arg2[80]; #endif char *ch_to_dir = 0; +#ifdef HAVE_LIBSYSTEMD + int systemd_socket; +#endif /* If we use --chdir, this records the original directory. */ char *original_pwd = 0; @@ -999,6 +1007,20 @@ main (int argc, char **argv) exit (1); } +#ifdef HAVE_LIBSYSTEMD + /* Read the number of sockets passed through by systemd. */ + systemd_socket = sd_listen_fds(1); + + if (systemd_socket > 1) + fprintf (stderr, "\nWarning: systemd has passed more than one socket to the Emacs process.\n\ +Try adding 'Accept=false' in the Emacs socket unit file.\n"); + + else if (systemd_socket == 1 && + sd_is_socket (SD_LISTEN_FDS_START, + AF_UNSPEC, SOCK_STREAM, 1) >= 0) + set_external_socket_descriptor (SD_LISTEN_FDS_START); +#endif /* HAVE_LIBSYSTEMD */ + #ifndef DAEMON_MUST_EXEC #ifdef USE_GTK fprintf (stderr, "\nWarning: due to a long standing Gtk+ bug\nhttp://bugzilla.gnome.org/show_bug.cgi?id=85715\n\ |