]> code.delx.au - gnu-emacs/blobdiff - src/emacs.c
Merge from origin/emacs-25
[gnu-emacs] / src / emacs.c
index a51df0903b1dc04ef2ec3cca117b51ad9ca006d0..3e0cf5964028aacae1836544e8d016eb3a55789c 100644 (file)
@@ -54,12 +54,13 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #ifdef MSDOS
 #include <binary-io.h>
+#include "dosfns.h"
 #endif
 
 #ifdef HAVE_LIBSYSTEMD
-#include <systemd/sd-daemon.h>
-#include <sys/socket.h>
-#endif /* HAVE_LIBSYSTEMD */
+# include <systemd/sd-daemon.h>
+# include <sys/socket.h>
+#endif
 
 #ifdef HAVE_WINDOW_SYSTEM
 #include TERM_HEADER
@@ -681,9 +682,6 @@ 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;
@@ -974,6 +972,9 @@ main (int argc, char **argv)
   w32_daemon_event = NULL;
 #endif
 
+
+  int sockfd = -1;
+
   if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)
       || argmatch (argv, argc, "-daemon", "--daemon", 5, &dname_arg, &skip_args))
     {
@@ -1008,17 +1009,18 @@ main (int argc, char **argv)
        }
 
 #ifdef HAVE_LIBSYSTEMD
-      /* Read the number of sockets passed through by systemd. */
-      systemd_socket = sd_listen_fds(1);
+      /* Read the number of sockets passed through by systemd.  */
+      int 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);
+        fprintf (stderr,
+                ("\n"
+                 "Warning: systemd passed more than one socket to Emacs.\n"
+                 "Try 'Accept=false' in the Emacs socket unit file.\n"));
+      else if (systemd_socket == 1
+              && (0 < sd_is_socket (SD_LISTEN_FDS_START,
+                                    AF_UNSPEC, SOCK_STREAM, 1)))
+       sockfd = SD_LISTEN_FDS_START;
 #endif /* HAVE_LIBSYSTEMD */
 
 #ifndef DAEMON_MUST_EXEC
@@ -1577,7 +1579,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
   /* This can create a thread that may call getenv, so it must follow
      all calls to putenv and setenv.  Also, this sets up
      add_keyboard_wait_descriptor, which init_display uses.  */
-  init_process_emacs ();
+  init_process_emacs (sockfd);
 
   init_keyboard ();    /* This too must precede init_sys_modes.  */
   if (!noninteractive)