*** empty log message ***
[bpt/emacs.git] / lib-src / emacsserver.c
index ba3fa08..fd532ce 100644 (file)
@@ -1,5 +1,5 @@
 /* Communication subprocess for GNU Emacs acting as server.
-   Copyright (C) 1986, 1987, 1992, 1994 Free Software Foundation, Inc.
+   Copyright (C) 1986, 1987, 1992, 1994, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -26,12 +26,8 @@ Boston, MA 02111-1307, USA.  */
    up to the Emacs which then executes them.  */
 
 #define NO_SHORTNAMES
-#include <signal.h>
 #include <../src/config.h>
-#undef read
-#undef write
-#undef open
-#undef close
+#include <signal.h>
 #undef signal
 
 #if !defined (HAVE_SOCKETS) && !defined (HAVE_SYSVIPC)
@@ -65,7 +61,9 @@ void fatal_error ();
 #include <unistd.h>
 #endif
 
+#ifndef errno
 extern int errno;
+#endif
 
 /* Copied from src/process.c */
 #ifdef FD_SET
@@ -213,7 +211,8 @@ main (argc, argv)
      int argc;
      char **argv;
 {
-  char system_name[32];
+  char *system_name;
+  int system_name_length;
   int s, infd;
 #ifdef SOCKLEN_TYPE
   SOCKLEN_TYPE fromlen;
@@ -249,10 +248,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));
-    /* system_name must be null-terminated string */
-    system_name[sizeof (system_name) - 1] = '\0';
   sprintf (server.sun_path, "/tmp/esrv%d-%s", geteuid (), system_name);
 
   if (unlink (server.sun_path) == -1 && errno != ENOENT)
@@ -266,7 +278,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);
@@ -555,7 +566,6 @@ main ()
 
 #endif /* HAVE_SYSVIPC */
 
-#endif /* HAVE_SOCKETS or HAVE_SYSVIPC */
 \f
 /* This is like perror but puts `Error: ' at the beginning.  */
 
@@ -580,3 +590,4 @@ fatal_error (string)
   fprintf (stderr, string);
   exit (1);
 }
+#endif /* HAVE_SOCKETS or HAVE_SYSVIPC */