aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2014-12-29 12:37:53 -0800
committerPaul Eggert2014-12-29 12:38:58 -0800
commitf9acac751d4cd22480e62cc63936b1208ca9fe48 (patch)
tree49f37d577e63a00042dc990ec92651d19be8870a
parentce1ebdf1ba8acc75e8f959f414652cdc87e76401 (diff)
downloademacs-f9acac751d4cd22480e62cc63936b1208ca9fe48.tar.gz
emacs-f9acac751d4cd22480e62cc63936b1208ca9fe48.zip
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.
-rw-r--r--ChangeLog27
-rw-r--r--doc/lispref/os.texi9
-rw-r--r--doc/misc/efaq.texi2
-rw-r--r--doc/misc/smtpmail.texi2
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/desktop.el2
-rw-r--r--lisp/dnd.el21
-rw-r--r--lisp/gnus/nnvirtual.el4
-rw-r--r--lisp/nxml/rng-uri.el2
-rw-r--r--lisp/org/org-clock.el4
-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
15 files changed, 97 insertions, 42 deletions
diff --git a/ChangeLog b/ChangeLog
index 00775edf524..1fc7d66c883 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
12014-12-29 Paul Eggert <eggert@cs.ucla.edu>
2
3 system-name's returned value can vary
4 Fixes Bug#19438.
5 * doc/lispref/os.texi (System Environment):
6 * etc/NEWS: Document this.
7 * doc/misc/efaq.texi:
8 (Displaying the current file name in the titlebar):
9 * lisp/desktop.el (desktop-save-frameset):
10 * lisp/dnd.el (dnd-get-local-file-uri):
11 * lisp/gnus/nnvirtual.el (nnvirtual-retrieve-headers)
12 (nnvirtual-update-xref-header):
13 * lisp/nxml/rng-uri.el (rng-uri-file-name-1):
14 * lisp/org/org-clock.el (org-clock-save):
15 * src/filelock.c (current_lock_owner):
16 * src/xrdb.c (get_environ_db):
17 * src/xterm.c (same_x_server):
18 * src/xterm.c (x_term_init):
19 Prefer (system-name) to system-name.
20 * doc/misc/smtpmail.texi (Server workarounds): Fix grammar.
21 * src/editfns.c (cached_system_name): New static var.
22 (init_and_cache_system_name): New function.
23 (init_editfns, Fsystem_name): Use it.
24 (syms_of_editfns): Initialize it and Vsystem_name to the same value.
25 * src/sysdep.c (init_system_name): Don't create a new string if
26 the current value is already correct.
27
12014-12-28 Paul Eggert <eggert@cs.ucla.edu> 282014-12-28 Paul Eggert <eggert@cs.ucla.edu>
2 29
3 * build-aux/git-hooks/commit-msg: Allow tabs. 30 * build-aux/git-hooks/commit-msg: Allow tabs.
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index 1a6a031d013..1300bc70d9a 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -918,10 +918,15 @@ string.
918@end defun 918@end defun
919 919
920 The symbol @code{system-name} is a variable as well as a function. In 920 The symbol @code{system-name} is a variable as well as a function. In
921fact, the function returns whatever value the variable 921fact, the function normally returns whatever value the variable
922@code{system-name} currently holds. Thus, you can set the variable 922@code{system-name} currently holds. Thus, you can set the variable
923@code{system-name} in case Emacs is confused about the name of your 923@code{system-name} in case Emacs is confused about the name of your
924system. The variable is also useful for constructing frame titles 924system. If you do not set the variable, the function updates
925the variable to the current system name; this behavior can be useful
926if your Emacs process has changed systems or if the system has changed
927names.
928
929The @code{system-name} variable is also useful for constructing frame titles
925(@pxref{Frame Titles}). 930(@pxref{Frame Titles}).
926 931
927@c FIXME seems like this section is not the best place for this option? 932@c FIXME seems like this section is not the best place for this option?
diff --git a/doc/misc/efaq.texi b/doc/misc/efaq.texi
index 0159101916d..71c5ae0a6c2 100644
--- a/doc/misc/efaq.texi
+++ b/doc/misc/efaq.texi
@@ -1469,7 +1469,7 @@ machine at which Emacs was invoked. This is done by setting
1469@code{frame-title-format} to the default value of 1469@code{frame-title-format} to the default value of
1470 1470
1471@lisp 1471@lisp
1472(multiple-frames "%b" ("" invocation-name "@@" system-name)) 1472(multiple-frames "%b" ("" invocation-name "@@" (system-name)))
1473@end lisp 1473@end lisp
1474 1474
1475To modify the behavior such that frame titlebars contain the buffer's 1475To modify the behavior such that frame titlebars contain the buffer's
diff --git a/doc/misc/smtpmail.texi b/doc/misc/smtpmail.texi
index f539cd0e224..9cddbfaf68a 100644
--- a/doc/misc/smtpmail.texi
+++ b/doc/misc/smtpmail.texi
@@ -368,7 +368,7 @@ implement support for common requirements.
368@vindex smtpmail-local-domain 368@vindex smtpmail-local-domain
369 The variable @code{smtpmail-local-domain} controls the hostname sent 369 The variable @code{smtpmail-local-domain} controls the hostname sent
370in the first @code{EHLO} or @code{HELO} command sent to the server. 370in the first @code{EHLO} or @code{HELO} command sent to the server.
371It should only be set if the @code{system-name} function returns a 371It should be set only if the @code{system-name} function returns a
372name that isn't accepted by the server. Do not set this variable 372name that isn't accepted by the server. Do not set this variable
373unless your server complains. 373unless your server complains.
374 374
diff --git a/etc/NEWS b/etc/NEWS
index 548f409348a..e5c988beaad 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -541,6 +541,9 @@ optional repeat-count argument.
541 541
542** Function `sort' can deal with vectors. 542** Function `sort' can deal with vectors.
543 543
544** Function `system-name' now returns an updated value if the current
545system's name has changed, or if the Emacs process has changed systems.
546
544--- 547---
545** New utilities in subr-x.el: 548** New utilities in subr-x.el:
546*** New macros `if-let' and `when-let' allow defining bindings and to 549*** New macros `if-let' and `when-let' allow defining bindings and to
diff --git a/lisp/desktop.el b/lisp/desktop.el
index bad0073fbba..bcf038762da 100644
--- a/lisp/desktop.el
+++ b/lisp/desktop.el
@@ -940,7 +940,7 @@ Frames with a non-nil `desktop-dont-save' parameter are not saved."
940 (and desktop-restore-frames 940 (and desktop-restore-frames
941 (frameset-save nil 941 (frameset-save nil
942 :app desktop--app-id 942 :app desktop--app-id
943 :name (concat user-login-name "@" system-name) 943 :name (concat user-login-name "@" (system-name))
944 :predicate #'desktop--check-dont-save)))) 944 :predicate #'desktop--check-dont-save))))
945 945
946;;;###autoload 946;;;###autoload
diff --git a/lisp/dnd.el b/lisp/dnd.el
index 73b531dfd16..2b68b025ac1 100644
--- a/lisp/dnd.el
+++ b/lisp/dnd.el
@@ -122,17 +122,18 @@ Return nil if URI is not a local file."
122 122
123 ;; The hostname may be our hostname, in that case, convert to a local 123 ;; The hostname may be our hostname, in that case, convert to a local
124 ;; file. Otherwise return nil. TODO: How about an IP-address as hostname? 124 ;; file. Otherwise return nil. TODO: How about an IP-address as hostname?
125 (let ((hostname (when (string-match "^file://\\([^/]*\\)" uri) 125 (let ((system-name (system-name)))
126 (let ((hostname (when (string-match "^file://\\([^/]*\\)" uri)
126 (downcase (match-string 1 uri)))) 127 (downcase (match-string 1 uri))))
127 (system-name-no-dot 128 (system-name-no-dot
128 (downcase (if (string-match "^[^\\.]+" system-name) 129 (downcase (if (string-match "^[^\\.]+" system-name)
129 (match-string 0 system-name) 130 (match-string 0 system-name)
130 system-name)))) 131 system-name))))
131 (when (and hostname 132 (when (and hostname
132 (or (string-equal "localhost" hostname) 133 (or (string-equal "localhost" hostname)
133 (string-equal (downcase system-name) hostname) 134 (string-equal (downcase system-name) hostname)
134 (string-equal system-name-no-dot hostname))) 135 (string-equal system-name-no-dot hostname)))
135 (concat "file://" (substring uri (+ 7 (length hostname))))))) 136 (concat "file://" (substring uri (+ 7 (length hostname))))))))
136 137
137(defsubst dnd-unescape-uri (uri) 138(defsubst dnd-unescape-uri (uri)
138 (replace-regexp-in-string 139 (replace-regexp-in-string
diff --git a/lisp/gnus/nnvirtual.el b/lisp/gnus/nnvirtual.el
index f67943a336a..d13b492ddb3 100644
--- a/lisp/gnus/nnvirtual.el
+++ b/lisp/gnus/nnvirtual.el
@@ -151,7 +151,7 @@ component group will show up when you enter the virtual group.")
151 ;; and clean up the xrefs. 151 ;; and clean up the xrefs.
152 (princ article nntp-server-buffer) 152 (princ article nntp-server-buffer)
153 (nnvirtual-update-xref-header cgroup carticle 153 (nnvirtual-update-xref-header cgroup carticle
154 prefix system-name) 154 prefix (system-name))
155 (forward-line 1)) 155 (forward-line 1))
156 ) 156 )
157 157
@@ -393,7 +393,7 @@ component group will show up when you enter the virtual group.")
393 (forward-char -1) 393 (forward-char -1)
394 (delete-char 1)) 394 (delete-char 1))
395 395
396 (insert "Xref: " system-name " " group ":") 396 (insert "Xref: " (system-name) " " group ":")
397 (princ article (current-buffer)) 397 (princ article (current-buffer))
398 (insert " ") 398 (insert " ")
399 399
diff --git a/lisp/nxml/rng-uri.el b/lisp/nxml/rng-uri.el
index b93624a4f22..43218ec7c88 100644
--- a/lisp/nxml/rng-uri.el
+++ b/lisp/nxml/rng-uri.el
@@ -85,7 +85,7 @@ Signal an error if URI is not a valid file URL."
85 ((not (string= (downcase scheme) "file")) 85 ((not (string= (downcase scheme) "file"))
86 (rng-uri-error "URI `%s' does not use the `file:' scheme" uri))) 86 (rng-uri-error "URI `%s' does not use the `file:' scheme" uri)))
87 (when (not (member authority 87 (when (not (member authority
88 (cons system-name '(nil "" "localhost")))) 88 (cons (system-name) '(nil "" "localhost"))))
89 (rng-uri-error "URI `%s' does not start with `file:///' or `file://localhost/'" 89 (rng-uri-error "URI `%s' does not start with `file:///' or `file://localhost/'"
90 uri)) 90 uri))
91 (when query 91 (when query
diff --git a/lisp/org/org-clock.el b/lisp/org/org-clock.el
index 51c87892a9c..c9287586e4e 100644
--- a/lisp/org/org-clock.el
+++ b/lisp/org/org-clock.el
@@ -2811,8 +2811,8 @@ The details of what will be saved are regulated by the variable
2811 (delete-region (point-min) (point-max)) 2811 (delete-region (point-min) (point-max))
2812 ;;Store clock 2812 ;;Store clock
2813 (insert (format ";; org-persist.el - %s at %s\n" 2813 (insert (format ";; org-persist.el - %s at %s\n"
2814 system-name (format-time-string 2814 (system-name) (format-time-string
2815 (cdr org-time-stamp-formats)))) 2815 (cdr org-time-stamp-formats))))
2816 (if (and (memq org-clock-persist '(t clock)) 2816 (if (and (memq org-clock-persist '(t clock))
2817 (setq b (org-clocking-buffer)) 2817 (setq b (org-clocking-buffer))
2818 (setq b (or (buffer-base-buffer b) b)) 2818 (setq b (or (buffer-base-buffer b) b))
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;
93 It is OK (though a bit slower) if the user chooses this value. */ 93 It is OK (though a bit slower) if the user chooses this value. */
94static char dump_tz_string[] = "TZ=UtC0"; 94static char dump_tz_string[] = "TZ=UtC0";
95 95
96/* The cached value of Vsystem_name. This is used only to compare it
97 to Vsystem_name, so it need not be visible to the GC. */
98static Lisp_Object cached_system_name;
99
100static void
101init_and_cache_system_name (void)
102{
103 init_system_name ();
104 cached_system_name = Vsystem_name;
105}
106
96void 107void
97init_editfns (void) 108init_editfns (void)
98{ 109{
@@ -102,7 +113,7 @@ init_editfns (void)
102 Lisp_Object tem; 113 Lisp_Object tem;
103 114
104 /* Set up system_name even when dumping. */ 115 /* Set up system_name even when dumping. */
105 init_system_name (); 116 init_and_cache_system_name ();
106 117
107#ifndef CANNOT_DUMP 118#ifndef CANNOT_DUMP
108 /* When just dumping out, set the time zone to a known unlikely value 119 /* 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,
1365 doc: /* Return the host name of the machine you are running on, as a string. */) 1376 doc: /* Return the host name of the machine you are running on, as a string. */)
1366 (void) 1377 (void)
1367{ 1378{
1379 if (EQ (Vsystem_name, cached_system_name))
1380 init_and_cache_system_name ();
1368 return Vsystem_name; 1381 return Vsystem_name;
1369} 1382}
1370 1383
@@ -4965,6 +4978,7 @@ functions if all the text being accessed has this property. */);
4965 4978
4966 DEFVAR_LISP ("system-name", Vsystem_name, 4979 DEFVAR_LISP ("system-name", Vsystem_name,
4967 doc: /* The host name of the machine Emacs is running on. */); 4980 doc: /* The host name of the machine Emacs is running on. */);
4981 Vsystem_name = cached_system_name = Qnil;
4968 4982
4969 DEFVAR_LISP ("user-full-name", Vuser_full_name, 4983 DEFVAR_LISP ("user-full-name", Vuser_full_name,
4970 doc: /* The full name of the user logged in. */); 4984 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)
592 return -1; 592 return -1;
593 593
594 /* On current host? */ 594 /* On current host? */
595 if (STRINGP (Vsystem_name) 595 Lisp_Object system_name = Fsystem_name ();
596 && dot - (at + 1) == SBYTES (Vsystem_name) 596 if (STRINGP (system_name)
597 && memcmp (at + 1, SSDATA (Vsystem_name), SBYTES (Vsystem_name)) == 0) 597 && dot - (at + 1) == SBYTES (system_name)
598 && memcmp (at + 1, SSDATA (system_name), SBYTES (system_name)) == 0)
598 { 599 {
599 if (pid == getpid ()) 600 if (pid == getpid ())
600 ret = 2; /* We own it. */ 601 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;
1420void 1420void
1421init_system_name (void) 1421init_system_name (void)
1422{ 1422{
1423 char *hostname_alloc = NULL;
1424 char *hostname;
1423#ifndef HAVE_GETHOSTNAME 1425#ifndef HAVE_GETHOSTNAME
1424 struct utsname uts; 1426 struct utsname uts;
1425 uname (&uts); 1427 uname (&uts);
1426 Vsystem_name = build_string (uts.nodename); 1428 hostname = uts.nodename;
1427#else /* HAVE_GETHOSTNAME */ 1429#else /* HAVE_GETHOSTNAME */
1428 char *hostname_alloc = NULL;
1429 char hostname_buf[256]; 1430 char hostname_buf[256];
1430 ptrdiff_t hostname_size = sizeof hostname_buf; 1431 ptrdiff_t hostname_size = sizeof hostname_buf;
1431 char *hostname = hostname_buf; 1432 hostname = hostname_buf;
1432 1433
1433 /* Try to get the host name; if the buffer is too short, try 1434 /* Try to get the host name; if the buffer is too short, try
1434 again. Apparently, the only indication gethostname gives of 1435 again. Apparently, the only indication gethostname gives of
@@ -1541,15 +1542,15 @@ init_system_name (void)
1541#endif /* !HAVE_GETADDRINFO */ 1542#endif /* !HAVE_GETADDRINFO */
1542 } 1543 }
1543#endif /* HAVE_SOCKETS */ 1544#endif /* HAVE_SOCKETS */
1544 Vsystem_name = build_string (hostname);
1545 xfree (hostname_alloc);
1546#endif /* HAVE_GETHOSTNAME */ 1545#endif /* HAVE_GETHOSTNAME */
1547 { 1546 char *p;
1548 char *p; 1547 for (p = hostname; *p; p++)
1549 for (p = SSDATA (Vsystem_name); *p; p++) 1548 if (*p == ' ' || *p == '\t')
1550 if (*p == ' ' || *p == '\t') 1549 *p = '-';
1551 *p = '-'; 1550 if (! (STRINGP (Vsystem_name) && SBYTES (Vsystem_name) == p - hostname
1552 } 1551 && strcmp (SSDATA (Vsystem_name), hostname) == 0))
1552 Vsystem_name = build_string (hostname);
1553 xfree (hostname_alloc);
1553} 1554}
1554 1555
1555sigset_t empty_mask; 1556sigset_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)
385 { 385 {
386 char *home = gethomedir (); 386 char *home = gethomedir ();
387 ptrdiff_t homelen = strlen (home); 387 ptrdiff_t homelen = strlen (home);
388 Lisp_Object system_name = Fsystem_name ();
388 ptrdiff_t filenamesize = (homelen + sizeof xdefaults 389 ptrdiff_t filenamesize = (homelen + sizeof xdefaults
389 + SBYTES (Vsystem_name)); 390 + SBYTES (system_name));
390 p = filename = xrealloc (home, filenamesize); 391 p = filename = xrealloc (home, filenamesize);
391 lispstpcpy (stpcpy (filename + homelen, xdefaults), Vsystem_name); 392 lispstpcpy (stpcpy (filename + homelen, xdefaults), system_name);
392 } 393 }
393 394
394 db = XrmGetFileDatabase (p); 395 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
10497same_x_server (const char *name1, const char *name2) 10497same_x_server (const char *name1, const char *name2)
10498{ 10498{
10499 bool seen_colon = false; 10499 bool seen_colon = false;
10500 const char *system_name = SSDATA (Vsystem_name); 10500 Lisp_Object sysname = Fsystem_name ();
10501 ptrdiff_t system_name_length = SBYTES (Vsystem_name); 10501 const char *system_name = SSDATA (sysname);
10502 ptrdiff_t system_name_length = SBYTES (sysname);
10502 ptrdiff_t length_until_period = 0; 10503 ptrdiff_t length_until_period = 0;
10503 10504
10504 while (system_name[length_until_period] != 0 10505 while (system_name[length_until_period] != 0
@@ -10890,14 +10891,15 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10890#endif 10891#endif
10891 10892
10892 lim = min (PTRDIFF_MAX, SIZE_MAX) - sizeof "@"; 10893 lim = min (PTRDIFF_MAX, SIZE_MAX) - sizeof "@";
10893 if (lim - SBYTES (Vinvocation_name) < SBYTES (Vsystem_name)) 10894 Lisp_Object system_name = Fsystem_name ();
10895 if (lim - SBYTES (Vinvocation_name) < SBYTES (system_name))
10894 memory_full (SIZE_MAX); 10896 memory_full (SIZE_MAX);
10895 dpyinfo->x_id = ++x_display_id; 10897 dpyinfo->x_id = ++x_display_id;
10896 dpyinfo->x_id_name = xmalloc (SBYTES (Vinvocation_name) 10898 dpyinfo->x_id_name = xmalloc (SBYTES (Vinvocation_name)
10897 + SBYTES (Vsystem_name) + 2); 10899 + SBYTES (system_name) + 2);
10898 char *nametail = lispstpcpy (dpyinfo->x_id_name, Vinvocation_name); 10900 char *nametail = lispstpcpy (dpyinfo->x_id_name, Vinvocation_name);
10899 *nametail++ = '@'; 10901 *nametail++ = '@';
10900 lispstpcpy (nametail, Vsystem_name); 10902 lispstpcpy (nametail, system_name);
10901 10903
10902 /* Figure out which modifier bits mean what. */ 10904 /* Figure out which modifier bits mean what. */
10903 x_find_modifier_meanings (dpyinfo); 10905 x_find_modifier_meanings (dpyinfo);