all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Matthew Leach <matthew@mattleach.net>
To: emacs-devel <emacs-devel@gnu.org>
Cc: Matthew Leach <matthew@mattleach.net>
Subject: [PATCH v2 2/4] Read the number of sockets passed by systemd.
Date: Sun, 27 Mar 2016 21:39:41 +0100	[thread overview]
Message-ID: <1459111183-27018-3-git-send-email-matthew@mattleach.net> (raw)
In-Reply-To: <1459111183-27018-1-git-send-email-matthew@mattleach.net>

* src/emacs.c (systemd_socket): New variable for storing the socket
  descriptor passed in by systemd.
  (main): Call sd_listen_fds to read the number of sockets passed.
---
 src/emacs.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/src/emacs.c b/src/emacs.c
index 95d1905..df5fade 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_SYSTEMD
+#include <systemd/sd-daemon.h>
+#include <sys/socket.h>
+#endif /* HAVE_SYSTEMD */
+
 #ifdef HAVE_WINDOW_SYSTEM
 #include TERM_HEADER
 #endif /* HAVE_WINDOW_SYSTEM */
@@ -195,6 +200,12 @@ int daemon_pipe[2];
 HANDLE w32_daemon_event;
 #endif
 
+#ifdef HAVE_SYSTEMD
+/* The socket descriptor passed by systemd.  If nothing has been
+   passed, this will be 0. */
+int systemd_socket = 0;
+#endif /* HAVE_SYSTEMD */
+
 /* Save argv and argc.  */
 char **initial_argv;
 int initial_argc;
@@ -997,6 +1008,24 @@ main (int argc, char **argv)
 	  exit (1);
 	}
 
+#ifdef HAVE_SYSTEMD
+      /* 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");
+          systemd_socket = 0;
+        }
+      else if (systemd_socket == 1 &&
+               sd_is_socket (SD_LISTEN_FDS_START,
+                             AF_UNSPEC, SOCK_STREAM, 1) >= 0)
+        systemd_socket = SD_LISTEN_FDS_START;
+      else
+        systemd_socket = 0;
+#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\
-- 
2.7.4




  parent reply	other threads:[~2016-03-27 20:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-27 20:39 [PATCH v2 0/4] Add systemd socket launching support Matthew Leach
2016-03-27 20:39 ` [PATCH v2 1/4] Check for libsystemd when building Emacs Matthew Leach
2016-03-27 20:39 ` Matthew Leach [this message]
2016-03-27 20:39 ` [PATCH v2 3/4] Allow network processes to be made with a pre-allocated fd Matthew Leach
2016-03-27 21:18   ` Andreas Schwab
2016-03-28 15:24   ` Eli Zaretskii
2016-03-28 15:45     ` Matthew Leach
2016-03-30 16:29   ` John Wiegley
2016-03-27 20:39 ` [PATCH v2 4/4] When Emacs is passed a socket descriptor, make the server listen on it Matthew Leach

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1459111183-27018-3-git-send-email-matthew@mattleach.net \
    --to=matthew@mattleach.net \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.