]> code.delx.au - gnu-emacs/blobdiff - lib-src/emacsserver.c
(decode_options): Update version output.
[gnu-emacs] / lib-src / emacsserver.c
index 2cd617c5c9bed6145dc0007bb788819e88528aa2..e58cf231933b30756873ebfb486c3bf17b7c8a1c 100644 (file)
@@ -26,7 +26,7 @@ Boston, MA 02111-1307, USA.  */
    up to the Emacs which then executes them.  */
 
 #define NO_SHORTNAMES
-#include <sys/signal.h>
+#include <signal.h>
 #include <../src/config.h>
 #undef read
 #undef write
@@ -37,6 +37,7 @@ Boston, MA 02111-1307, USA.  */
 #if !defined (HAVE_SOCKETS) && !defined (HAVE_SYSVIPC)
 #include <stdio.h>
 
+int
 main ()
 {
   fprintf (stderr, "Sorry, the Emacs server is supported only on systems\n");
@@ -46,6 +47,9 @@ main ()
 
 #else /* HAVE_SOCKETS or HAVE_SYSVIPC */
 
+void perror_1 ();
+void fatal_error ();
+
 #if defined (HAVE_SOCKETS) && ! defined (NO_SOCKETS_IN_FILE_SYSTEM)
 /* BSD code is very different from SYSV IPC code */
 
@@ -57,6 +61,10 @@ main ()
 #include <errno.h>
 #include <sys/stat.h>
 
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
 extern int errno;
 
 /* Copied from src/process.c */
@@ -104,6 +112,7 @@ delete_socket (sig)
 
 /* Set up to handle all the signals.  */
 
+void
 handle_signals ()
 {
   signal (SIGHUP, delete_socket);
@@ -204,8 +213,14 @@ main (argc, argv)
      int argc;
      char **argv;
 {
-  char system_name[32];
-  int s, infd, fromlen;
+  char *system_name;
+  int system_name_length;
+  int s, infd;
+#ifdef SOCKLEN_TYPE
+  SOCKLEN_TYPE fromlen;
+#else
+  size_t fromlen;
+#endif
   struct sockaddr_un server, fromunix;
   char *homedir;
   char *str, string[BUFSIZ], code[BUFSIZ];
@@ -235,8 +250,23 @@ main (argc, argv)
       exit (1);
     }
   server.sun_family = AF_UNIX;
+
+  system_name_length = 32;
+  while (1)
+    {
+      system_name = (char *) xmalloc (system_name_length + 1);
+
+      /* system_name must be null-terminated string.  */
+      system_name[system_name_length] = '\0';
+
+      if (gethostname (system_name, system_name_length) == 0)
+       break;
+
+      free (system_name);
+      system_name_length *= 2;
+    }
+
 #ifndef SERVER_HOME_DIR
-  gethostname (system_name, sizeof (system_name));
   sprintf (server.sun_path, "/tmp/esrv%d-%s", geteuid (), system_name);
 
   if (unlink (server.sun_path) == -1 && errno != ENOENT)
@@ -250,7 +280,6 @@ main (argc, argv)
 
   strcpy (server.sun_path, homedir);
   strcat (server.sun_path, "/.emacs-server-");
-  gethostname (system_name, sizeof (system_name));
   strcat (server.sun_path, system_name);
   /* Delete anyone else's old server.  */
   unlink (server.sun_path);
@@ -409,6 +438,7 @@ msgcatch ()
    Its stderr always exists--rms.  */
 #include <stdio.h>
 
+int
 main ()
 {
   int s, infd, fromlen, ioproc;
@@ -538,10 +568,10 @@ main ()
 
 #endif /* HAVE_SYSVIPC */
 
-#endif /* HAVE_SOCKETS or HAVE_SYSVIPC */
 \f
 /* This is like perror but puts `Error: ' at the beginning.  */
 
+void
 perror_1 (string)
      char *string;
 {
@@ -554,6 +584,7 @@ perror_1 (string)
   perror (copy);
 }
 
+void
 fatal_error (string)
      char *string;
 {
@@ -561,3 +592,4 @@ fatal_error (string)
   fprintf (stderr, string);
   exit (1);
 }
+#endif /* HAVE_SOCKETS or HAVE_SYSVIPC */