aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKarl Heuer1994-02-02 06:20:58 +0000
committerKarl Heuer1994-02-02 06:20:58 +0000
commit67004ffb7a9afa613b753655848a11424bda1734 (patch)
treec9d31e1b78dc4246ce24a3091619e9262baf398e /src
parentb1fa544fda46cbf18b599ba3ede88b1ec797aa7e (diff)
downloademacs-67004ffb7a9afa613b753655848a11424bda1734.tar.gz
emacs-67004ffb7a9afa613b753655848a11424bda1734.zip
(get_system_name): Remove restriction on hostname size.
Diffstat (limited to 'src')
-rw-r--r--src/sysdep.c162
1 files changed, 88 insertions, 74 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index 42b6ce14d65..267016f2757 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1901,7 +1901,7 @@ end_of_data ()
1901 1901
1902#endif /* not CANNOT_DUMP */ 1902#endif /* not CANNOT_DUMP */
1903 1903
1904/* Get_system_name returns as its value 1904/* get_system_name returns as its value
1905 a string for the Lisp function system-name to return. */ 1905 a string for the Lisp function system-name to return. */
1906 1906
1907#ifdef BSD4_1 1907#ifdef BSD4_1
@@ -1910,13 +1910,8 @@ end_of_data ()
1910 1910
1911/* Can't have this within the function since `static' is #defined to 1911/* Can't have this within the function since `static' is #defined to
1912 nothing for some USG systems. */ 1912 nothing for some USG systems. */
1913#ifdef USG 1913static char *get_system_name_cache;
1914#ifdef HAVE_GETHOSTNAME 1914static int get_system_name_predump_p;
1915static char get_system_name_name[256];
1916#else /* not HAVE_GETHOSTNAME */
1917static struct utsname get_system_name_name;
1918#endif /* not HAVE_GETHOSTNAME */
1919#endif /* USG */
1920 1915
1921#ifndef BSD4_1 1916#ifndef BSD4_1
1922#ifndef USG 1917#ifndef USG
@@ -1932,81 +1927,100 @@ static struct utsname get_system_name_name;
1932char * 1927char *
1933get_system_name () 1928get_system_name ()
1934{ 1929{
1935#ifdef USG
1936#ifdef HAVE_GETHOSTNAME
1937 gethostname (get_system_name_name, sizeof (get_system_name_name));
1938 return get_system_name_name;
1939#else /* not HAVE_GETHOSTNAME */
1940 uname (&get_system_name_name);
1941 return (get_system_name_name.nodename);
1942#endif /* not HAVE_GETHOSTNAME */
1943#else /* Not USG */
1944#ifdef BSD4_1 1930#ifdef BSD4_1
1945 return sysname; 1931 return sysname;
1946#else /* not USG, not 4.1 */ 1932#else
1947 static char system_name_saved[32]; 1933#ifndef CANNOT_DUMP
1948#ifdef VMS 1934 /* If the cached value is from before the dump, and we've dumped
1949 char *sp; 1935 since then, then the cached value is no good. */
1950 if ((sp = egetenv ("SYS$NODE")) == 0) 1936 if (get_system_name_predump_p && initialized && get_system_name_cache)
1951 sp = "vax-vms";
1952 else
1953 { 1937 {
1954 char *end; 1938 xfree (get_system_name_cache);
1955 1939 get_system_name_cache = 0;
1956 if ((end = index (sp, ':')) != 0)
1957 *end = '\0';
1958 } 1940 }
1959 strcpy (system_name_saved, sp); 1941#endif
1960#else /* not VMS */ 1942 if (!get_system_name_cache)
1961 gethostname (system_name_saved, sizeof (system_name_saved));
1962#ifdef HAVE_SOCKETS
1963 /* Turn the hostname into the official, fully-qualified hostname.
1964 Don't do this if we're going to dump; this can confuse system
1965 libraries on some machines and make the dumped emacs core dump. */
1966#ifndef CANNOT_DUMP
1967 if (initialized)
1968#endif /* not CANNOT_DUMP */
1969 { 1943 {
1970 struct hostent *hp; 1944 /* No cached value, so get the name from the system. */
1971 hp = gethostbyname (system_name_saved); 1945#ifdef VMS
1972 if (hp && strlen (hp->h_name) < sizeof(system_name_saved)) 1946 char *sp;
1973 strcpy (system_name_saved, hp->h_name); 1947 if ((sp = egetenv ("SYS$NODE")) == 0)
1974 if (hp && !index (system_name_saved, '.')) 1948 sp = "vax-vms";
1949 else
1975 { 1950 {
1976 /* We still don't have a fully qualified domain name. 1951 char *end;
1977 Try to find one in the list of alternate names */
1978 char **alias = hp->h_aliases;
1979 while (*alias && !index (*alias, '.'))
1980 alias++;
1981 if (*alias && strlen (*alias) < sizeof (system_name_saved))
1982 strcpy (system_name_saved, *alias);
1983 }
1984 }
1985#endif /* HAVE_SOCKETS */
1986#endif /* not VMS */
1987 return system_name_saved;
1988#endif /* not USG, not 4.1 */
1989#endif /* not USG */
1990}
1991 1952
1992#ifdef VMS 1953 if ((end = index (sp, ':')) != 0)
1954 *end = '\0';
1955 }
1956 get_system_name_cache = (char *) xmalloc (strlen (sp) + 1);
1957 strcpy (get_system_name_cache, sp);
1958#else
1993#ifndef HAVE_GETHOSTNAME 1959#ifndef HAVE_GETHOSTNAME
1994void gethostname(buf, len) 1960 struct utsname uts;
1995 char *buf; 1961 uname (&uts);
1996 int len; 1962 get_system_name_cache = (char *) xmalloc (strlen (uts.nodename) + 1);
1997{ 1963 strcpy (get_system_name_cache, uts.nodename);
1998 char *s; 1964#else /* HAVE_GETHOSTNAME */
1999 s = getenv ("SYS$NODE"); 1965 {
2000 if (s == NULL) 1966 int hostname_size = 256;
2001 buf[0] = '\0'; 1967 char *hostname = (char *) xmalloc (hostname_size);
2002 else { 1968
2003 strncpy (buf, s, len - 2); 1969 /* Try to get the host name; if the buffer is too short, try
2004 buf[len - 1] = '\0'; 1970 again. Apparently, the only indication gethostname gives of
2005 } /* else */ 1971 whether the buffer was large enough is the presence or absence
2006} /* static void gethostname */ 1972 of a '\0' in the string. Eech. */
2007#endif /* ! HAVE_GETHOSTNAME */ 1973 for (;;)
2008#endif /* VMS */ 1974 {
1975 gethostname (hostname, hostname_size - 1);
1976 hostname[hostname_size - 1] = '\0';
2009 1977
1978 /* Was the buffer large enough for the '\0'? */
1979 if (strlen (hostname) < hostname_size - 1)
1980 break;
1981
1982 hostname_size <<= 1;
1983 hostname = (char *) xrealloc (hostname, hostname_size);
1984 }
1985 get_system_name_cache = hostname;
1986#ifdef HAVE_SOCKETS
1987 /* Turn the hostname into the official, fully-qualified hostname.
1988 Don't do this if we're going to dump; this can confuse system
1989 libraries on some machines and make the dumped emacs core dump. */
1990#ifndef CANNOT_DUMP
1991 if (initialized)
1992#endif /* not CANNOT_DUMP */
1993 {
1994 struct hostent *hp = gethostbyname (hostname);
1995 if (hp)
1996 {
1997 char *fqdn = hp->h_name;
1998 if (!index (fqdn, '.'))
1999 {
2000 /* We still don't have a fully qualified domain name.
2001 Try to find one in the list of alternate names */
2002 char **alias = hp->h_aliases;
2003 while (*alias && !index (*alias, '.'))
2004 alias++;
2005 if (*alias)
2006 fqdn = *alias;
2007 }
2008 hostname = (char *) xrealloc (hostname, strlen (fqdn) + 1);
2009 strcpy (hostname, fqdn);
2010 }
2011 }
2012#endif /* HAVE_SOCKETS */
2013 get_system_name_cache = hostname;
2014 }
2015#endif /* HAVE_GETHOSTNAME */
2016#endif /* VMS */
2017#ifndef CANNOT_DUMP
2018 get_system_name_predump_p = !initialized;
2019#endif
2020 }
2021 return (get_system_name_cache);
2022#endif /* BSD4_1 */
2023}
2010 2024
2011#ifndef VMS 2025#ifndef VMS
2012#ifndef HAVE_SELECT 2026#ifndef HAVE_SELECT