aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMatthew Leach2018-02-12 12:52:43 -0800
committerPaul Eggert2018-02-12 12:57:58 -0800
commite1ca0ea87222e70710b3878ac80ed01f2378f050 (patch)
treecc79162baa9b968066aafc8d5f2279c5755e5316 /lisp
parentb3f45140ec441bf88fa25f4e615b18e076d51342 (diff)
downloademacs-e1ca0ea87222e70710b3878ac80ed01f2378f050.tar.gz
emacs-e1ca0ea87222e70710b3878ac80ed01f2378f050.zip
Fix `server-name' and `server-socket-dir' for (Bug#24218)
* lisp/server.el: (server-external-socket-initialised): New (server-name): Compute server name from `get-external-sockname'. (server-socket-dir): Compute socket dir from `get-external-sockname'. (server-start): Don't check for existing server when an uninitialised external socket has been passed to Emacs. * src/emacs.c: (main): Obtain socket name via getsockname and pass to `init_process_emacs'. * src/lisp.h: (init_process_emacs): Add second parameter. * src/process.c: (external_sock_name): New. (get-external-sockname): New. (init_process_emacs): Set `external_sock_name' to `sockname' parameter.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/server.el56
1 files changed, 36 insertions, 20 deletions
diff --git a/lisp/server.el b/lisp/server.el
index d91a51e425a..d2406e21bdf 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -251,8 +251,16 @@ This means that the server should not kill the buffer when you say you
251are done with it in the server.") 251are done with it in the server.")
252(make-variable-buffer-local 'server-existing-buffer) 252(make-variable-buffer-local 'server-existing-buffer)
253 253
254;;;###autoload 254(defvar server-external-socket-initialised nil
255(defcustom server-name "server" 255 "When an external socket is passed into Emacs, we need to call
256`server-start' in order to initialise the connection. This flag
257prevents multiple initialisations when an external socket has
258been consumed.")
259
260(defcustom server-name
261 (if (get-external-sockname)
262 (file-name-nondirectory (get-external-sockname))
263 "server")
256 "The name of the Emacs server, if this Emacs process creates one. 264 "The name of the Emacs server, if this Emacs process creates one.
257The command `server-start' makes use of this. It should not be 265The command `server-start' makes use of this. It should not be
258changed while a server is running." 266changed while a server is running."
@@ -263,8 +271,10 @@ changed while a server is running."
263;; We do not use `temporary-file-directory' here, because emacsclient 271;; We do not use `temporary-file-directory' here, because emacsclient
264;; does not read the init file. 272;; does not read the init file.
265(defvar server-socket-dir 273(defvar server-socket-dir
266 (and (featurep 'make-network-process '(:family local)) 274 (if (get-external-sockname)
267 (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid))) 275 (file-name-directory (get-external-sockname))
276 (and (featurep 'make-network-process '(:family local))
277 (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid))))
268 "The directory in which to place the server socket. 278 "The directory in which to place the server socket.
269If local sockets are not supported, this is nil.") 279If local sockets are not supported, this is nil.")
270 280
@@ -618,23 +628,29 @@ To force-start a server, do \\[server-force-delete] and then
618 (when server-process 628 (when server-process
619 ;; kill it dead! 629 ;; kill it dead!
620 (ignore-errors (delete-process server-process))) 630 (ignore-errors (delete-process server-process)))
621 ;; Delete the socket files made by previous server invocations. 631 ;; Check to see if an uninitialised external socket has been
622 (if (not (eq t (server-running-p server-name))) 632 ;; passed in, if that is the case, skip checking
623 ;; Remove any leftover socket or authentication file 633 ;; `server-running-p' as this will return the wrong result.
624 (ignore-errors 634 (if (and (get-external-sockname)
625 (let (delete-by-moving-to-trash) 635 (not server-external-socket-initialised))
626 (delete-file server-file))) 636 (setq server-external-socket-initialised t)
627 (setq server-mode nil) ;; already set by the minor mode code 637 ;; Delete the socket files made by previous server invocations.
628 (display-warning 638 (if (not (eq t (server-running-p server-name)))
629 'server 639 ;; Remove any leftover socket or authentication file
630 (concat "Unable to start the Emacs server.\n" 640 (ignore-errors
631 (format "There is an existing Emacs server, named %S.\n" 641 (let (delete-by-moving-to-trash)
632 server-name) 642 (delete-file server-file)))
633 (substitute-command-keys 643 (setq server-mode nil) ;; already set by the minor mode code
634 "To start the server in this Emacs process, stop the existing 644 (display-warning
645 'server
646 (concat "Unable to start the Emacs server.\n"
647 (format "There is an existing Emacs server, named %S.\n"
648 server-name)
649 (substitute-command-keys
650 "To start the server in this Emacs process, stop the existing
635server or call `\\[server-force-delete]' to forcibly disconnect it.")) 651server or call `\\[server-force-delete]' to forcibly disconnect it."))
636 :warning) 652 :warning)
637 (setq leave-dead t)) 653 (setq leave-dead t)))
638 ;; If this Emacs already had a server, clear out associated status. 654 ;; If this Emacs already had a server, clear out associated status.
639 (while server-clients 655 (while server-clients
640 (server-delete-client (car server-clients))) 656 (server-delete-client (car server-clients)))