summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2014-12-29 12:37:53 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2014-12-29 12:38:58 -0800
commitf9acac751d4cd22480e62cc63936b1208ca9fe48 (patch)
tree49f37d577e63a00042dc990ec92651d19be8870a /src
parentce1ebdf1ba8acc75e8f959f414652cdc87e76401 (diff)
downloademacs-f9acac751d4cd22480e62cc63936b1208ca9fe48.tar.gz
system-name's returned value can vary
Also, the system-name variable is now obsolete. Fixes Bug#19438. * doc/lispref/os.texi (System Environment): * etc/NEWS: Document this. * doc/misc/efaq.texi: (Displaying the current file name in the titlebar): * lisp/desktop.el (desktop-save-frameset): * lisp/dnd.el (dnd-get-local-file-uri): * lisp/gnus/message.el (message-make-fqdn): * lisp/gnus/nnvirtual.el (nnvirtual-retrieve-headers) (nnvirtual-update-xref-header): * lisp/nxml/rng-uri.el (rng-uri-file-name-1): * lisp/org/org-clock.el (org-clock-save): * src/filelock.c (current_lock_owner): * src/xrdb.c (get_environ_db): * src/xterm.c (same_x_server): * src/xterm.c (x_term_init): Prefer (system-name) to system-name, and avoid naming locals 'system-name'. * doc/misc/smtpmail.texi (Server workarounds): Fix grammar. * lisp/startup.el (system-name): Now an obsolete variable. * src/editfns.c (cached_system_name): New static var. (init_and_cache_system_name): New function. (init_editfns, Fsystem_name): Use it. (syms_of_editfns): Initialize it and Vsystem_name to the same value. * src/sysdep.c [HAVE_SOCKETS]: Don't include <sys/socket.h>, <netdb.h>. (h_errno) [TRY_AGAIN && !HAVE_H_ERRNO]: Remove decl. (init_system_name) [HAVE_SOCKETS]: Don't canonicalize the name. Don't create a new string if the current value is already correct.
Diffstat (limited to 'src')
-rw-r--r--src/editfns.c16
-rw-r--r--src/filelock.c7
-rw-r--r--src/sysdep.c23
-rw-r--r--src/xrdb.c5
-rw-r--r--src/xterm.c12
5 files changed, 41 insertions, 22 deletions
diff --git a/src/editfns.c b/src/editfns.c
index 430c4c91fb3..2a7dd9209ae 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -93,6 +93,17 @@ static char const *initial_tz;
It is OK (though a bit slower) if the user chooses this value. */
static char dump_tz_string[] = "TZ=UtC0";
+/* The cached value of Vsystem_name. This is used only to compare it
+ to Vsystem_name, so it need not be visible to the GC. */
+static Lisp_Object cached_system_name;
+
+static void
+init_and_cache_system_name (void)
+{
+ init_system_name ();
+ cached_system_name = Vsystem_name;
+}
+
void
init_editfns (void)
{
@@ -102,7 +113,7 @@ init_editfns (void)
Lisp_Object tem;
/* Set up system_name even when dumping. */
- init_system_name ();
+ init_and_cache_system_name ();
#ifndef CANNOT_DUMP
/* When just dumping out, set the time zone to a known unlikely value
@@ -1365,6 +1376,8 @@ DEFUN ("system-name", Fsystem_name, Ssystem_name, 0, 0, 0,
doc: /* Return the host name of the machine you are running on, as a string. */)
(void)
{
+ if (EQ (Vsystem_name, cached_system_name))
+ init_and_cache_system_name ();
return Vsystem_name;
}
@@ -4965,6 +4978,7 @@ functions if all the text being accessed has this property. */);
DEFVAR_LISP ("system-name", Vsystem_name,
doc: /* The host name of the machine Emacs is running on. */);
+ Vsystem_name = cached_system_name = Qnil;
DEFVAR_LISP ("user-full-name", Vuser_full_name,
doc: /* The full name of the user logged in. */);
diff --git a/src/filelock.c b/src/filelock.c
index f857c488143..99215f215e7 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -592,9 +592,10 @@ current_lock_owner (lock_info_type *owner, char *lfname)
return -1;
/* On current host? */
- if (STRINGP (Vsystem_name)
- && dot - (at + 1) == SBYTES (Vsystem_name)
- && memcmp (at + 1, SSDATA (Vsystem_name), SBYTES (Vsystem_name)) == 0)
+ Lisp_Object system_name = Fsystem_name ();
+ if (STRINGP (system_name)
+ && dot - (at + 1) == SBYTES (system_name)
+ && memcmp (at + 1, SSDATA (system_name), SBYTES (system_name)) == 0)
{
if (pid == getpid ())
ret = 2; /* We own it. */
diff --git a/src/sysdep.c b/src/sysdep.c
index 24cc5cb0b40..b4a9be1eb1a 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1420,15 +1420,16 @@ extern int h_errno;
void
init_system_name (void)
{
+ char *hostname_alloc = NULL;
+ char *hostname;
#ifndef HAVE_GETHOSTNAME
struct utsname uts;
uname (&uts);
- Vsystem_name = build_string (uts.nodename);
+ hostname = uts.nodename;
#else /* HAVE_GETHOSTNAME */
- char *hostname_alloc = NULL;
char hostname_buf[256];
ptrdiff_t hostname_size = sizeof hostname_buf;
- char *hostname = hostname_buf;
+ hostname = hostname_buf;
/* Try to get the host name; if the buffer is too short, try
again. Apparently, the only indication gethostname gives of
@@ -1541,15 +1542,15 @@ init_system_name (void)
#endif /* !HAVE_GETADDRINFO */
}
#endif /* HAVE_SOCKETS */
- Vsystem_name = build_string (hostname);
- xfree (hostname_alloc);
#endif /* HAVE_GETHOSTNAME */
- {
- char *p;
- for (p = SSDATA (Vsystem_name); *p; p++)
- if (*p == ' ' || *p == '\t')
- *p = '-';
- }
+ char *p;
+ for (p = hostname; *p; p++)
+ if (*p == ' ' || *p == '\t')
+ *p = '-';
+ if (! (STRINGP (Vsystem_name) && SBYTES (Vsystem_name) == p - hostname
+ && strcmp (SSDATA (Vsystem_name), hostname) == 0))
+ Vsystem_name = build_string (hostname);
+ xfree (hostname_alloc);
}
sigset_t empty_mask;
diff --git a/src/xrdb.c b/src/xrdb.c
index e21206d0800..8500fb1095b 100644
--- a/src/xrdb.c
+++ b/src/xrdb.c
@@ -385,10 +385,11 @@ get_environ_db (void)
{
char *home = gethomedir ();
ptrdiff_t homelen = strlen (home);
+ Lisp_Object system_name = Fsystem_name ();
ptrdiff_t filenamesize = (homelen + sizeof xdefaults
- + SBYTES (Vsystem_name));
+ + SBYTES (system_name));
p = filename = xrealloc (home, filenamesize);
- lispstpcpy (stpcpy (filename + homelen, xdefaults), Vsystem_name);
+ lispstpcpy (stpcpy (filename + homelen, xdefaults), system_name);
}
db = XrmGetFileDatabase (p);
diff --git a/src/xterm.c b/src/xterm.c
index 130174dff19..892562bd612 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -10497,8 +10497,9 @@ static bool
same_x_server (const char *name1, const char *name2)
{
bool seen_colon = false;
- const char *system_name = SSDATA (Vsystem_name);
- ptrdiff_t system_name_length = SBYTES (Vsystem_name);
+ Lisp_Object sysname = Fsystem_name ();
+ const char *system_name = SSDATA (sysname);
+ ptrdiff_t system_name_length = SBYTES (sysname);
ptrdiff_t length_until_period = 0;
while (system_name[length_until_period] != 0
@@ -10890,14 +10891,15 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
#endif
lim = min (PTRDIFF_MAX, SIZE_MAX) - sizeof "@";
- if (lim - SBYTES (Vinvocation_name) < SBYTES (Vsystem_name))
+ Lisp_Object system_name = Fsystem_name ();
+ if (lim - SBYTES (Vinvocation_name) < SBYTES (system_name))
memory_full (SIZE_MAX);
dpyinfo->x_id = ++x_display_id;
dpyinfo->x_id_name = xmalloc (SBYTES (Vinvocation_name)
- + SBYTES (Vsystem_name) + 2);
+ + SBYTES (system_name) + 2);
char *nametail = lispstpcpy (dpyinfo->x_id_name, Vinvocation_name);
*nametail++ = '@';
- lispstpcpy (nametail, Vsystem_name);
+ lispstpcpy (nametail, system_name);
/* Figure out which modifier bits mean what. */
x_find_modifier_meanings (dpyinfo);