emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/5] Read the number of sockets passed by systemd.


From: Matthew Leach
Subject: [PATCH 2/5] Read the number of sockets passed by systemd.
Date: Sat, 26 Mar 2016 21:16:39 +0000

* src/emacs.c (systemd_socket): New variable for storing the number
  of sockets passed by systemd.
  (main): Call sd_listen_fds to read the number of sockets passed.
  (Fsystemd_socket): New lisp function that returns `t' when systemd
  did pass Emacs a socket.
---
 src/emacs.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/emacs.c b/src/emacs.c
index 95d1905..5a87bcd 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -56,6 +56,10 @@ along with GNU Emacs.  If not, see 
<http://www.gnu.org/licenses/>.  */
 #include <binary-io.h>
 #endif
 
+#ifdef HAVE_SYSTEMD
+#include <systemd/sd-daemon.h>
+#endif /* HAVE_SYSTEMD */
+
 #ifdef HAVE_WINDOW_SYSTEM
 #include TERM_HEADER
 #endif /* HAVE_WINDOW_SYSTEM */
@@ -195,6 +199,11 @@ int daemon_pipe[2];
 HANDLE w32_daemon_event;
 #endif
 
+#ifdef HAVE_SYSTEMD
+/* The number of sockets passed by systemd. */
+int systemd_socket = 0;
+#endif /* HAVE_SYSTEMD */
+
 /* Save argv and argc.  */
 char **initial_argv;
 int initial_argc;
@@ -997,6 +1006,15 @@ main (int argc, char **argv)
          exit (1);
        }
 
+#ifdef HAVE_SYSTEMD
+      /* Read the number of sockets passed through by systemd. */
+      systemd_socket = sd_listen_fds(0);
+
+      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");
+#endif
+
 #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\
@@ -2335,6 +2353,21 @@ If the daemon was given a name argument, return that 
name. */)
     return Qnil;
 }
 
+DEFUN ("systemd-socket", Fsystemd_socket, Ssystemd_socket, 0, 0, 0,
+       doc: /* Returns non-nil if systemd passed a socket through.
+When systemd passes a socket through to emacs, return `t'.*/)
+  (void)
+{
+#ifdef HAVE_SYSTEMD
+    if (systemd_socket)
+        return Qt;
+    else
+        return Qnil;
+#else
+    return Qnil;
+#endif
+}
+
 DEFUN ("daemon-initialized", Fdaemon_initialized, Sdaemon_initialized, 0, 0, 0,
        doc: /* Mark the Emacs daemon as being initialized.
 This finishes the daemonization process by doing the other half of detaching
@@ -2403,6 +2436,7 @@ syms_of_emacs (void)
   defsubr (&Sinvocation_name);
   defsubr (&Sinvocation_directory);
   defsubr (&Sdaemonp);
+  defsubr (&Ssystemd_socket);
   defsubr (&Sdaemon_initialized);
 
   DEFVAR_LISP ("command-line-args", Vcommand_line_args,
-- 
2.7.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]