emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/server.el,v


From: Stefan Monnier
Subject: [Emacs-diffs] Changes to emacs/lisp/server.el,v
Date: Thu, 02 Nov 2006 23:46:16 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Stefan Monnier <monnier>        06/11/02 23:46:15

Index: server.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/server.el,v
retrieving revision 1.117
retrieving revision 1.118
diff -u -b -r1.117 -r1.118
--- server.el   2 Nov 2006 01:29:41 -0000       1.117
+++ server.el   2 Nov 2006 23:46:14 -0000       1.118
@@ -112,10 +112,6 @@
   :version "22.1")
 (put 'server-auth-dir 'risky-local-variable t)
 
-(defvar server-auth-key nil
-  "The current server authentication key.")
-(put 'server-auth-key 'risky-local-variable t)
-
 (defcustom server-visit-hook nil
   "*Hook run when visiting a file for the Emacs server."
   :group 'server
@@ -228,6 +224,12 @@
   (when (and (eq (process-status proc) 'open)
             (process-query-on-exit-flag proc))
     (set-process-query-on-exit-flag proc nil))
+  ;; Delete the associated connection file, if applicable.
+  ;; This is actually problematic: the file may have been overwritten by
+  ;; another Emacs server in the mean time, so it's not ours any more.
+  ;; (and (process-contact proc :server)
+  ;;      (eq (process-status proc) 'closed)
+  ;;      (ignore-errors (delete-file (process-get proc :server-file))))
   (server-log (format "Status changed to %s" (process-status proc)) proc))
 
 (defun server-select-display (display)
@@ -307,23 +309,19 @@
   (interactive "P")
   (when server-process
     ;; kill it dead!
-    (ignore-errors (delete-process server-process))
-    (ignore-errors
-      ;; Delete the socket or authentication files made by previous
-      ;; server invocations.
-      (if (eq (process-contact server-process :family) 'local)
-          (delete-file (expand-file-name server-name server-socket-dir))
-        (setq server-auth-key nil)
-        (delete-file (expand-file-name server-name server-auth-dir)))))
+    (ignore-errors (delete-process server-process)))
   ;; If this Emacs already had a server, clear out associated status.
   (while server-clients
     (let ((buffer (nth 1 (car server-clients))))
       (server-buffer-done buffer)))
   ;; Now any previous server is properly stopped.
   (unless leave-dead
+    (let* ((server-dir (if server-use-tcp server-auth-dir server-socket-dir))
+           (server-file (expand-file-name server-name server-dir)))
     ;; Make sure there is a safe directory in which to place the socket.
-    (server-ensure-safe-dir
-     (if server-use-tcp server-auth-dir server-socket-dir))
+      (server-ensure-safe-dir server-dir)
+      ;; Remove any leftover socket or authentication file.
+      (ignore-errors (delete-file server-file))
     (when server-process
       (server-log (message "Restarting server")))
     (letf (((default-file-modes) ?\700))
@@ -345,23 +343,24 @@
                              :host (or server-host 'local)
                              :plist '(:authenticated nil))
                      (list :family 'local
-                           :service (expand-file-name server-name 
server-socket-dir)
+                             :service server-file
                            :plist '(:authenticated t)))))
       (unless server-process (error "Could not start server process"))
       (when server-use-tcp
-        (setq server-auth-key
+        (let ((auth-key
               (loop
                  ;; The auth key is a 64-byte string of random chars in the
                  ;; range `!'..`~'.
                 for i below 64
                  collect (+ 33 (random 94)) into auth
-                 finally return (concat auth)))
-        (with-temp-file (expand-file-name server-name server-auth-dir)
+                  finally return (concat auth))))
+          (process-put server-process :auth-key auth-key)
+          (with-temp-file server-file
           (set-buffer-multibyte nil)
           (setq buffer-file-coding-system 'no-conversion)
           (insert (format-network-address
                    (process-contact server-process :local))
-                  "\n" server-auth-key))))))
+                    "\n" auth-key))))))))
 
 ;;;###autoload
 (define-minor-mode server-mode
@@ -382,7 +381,7 @@
   ;; First things first: let's check the authentication
   (unless (process-get proc :authenticated)
     (if (and (string-match "-auth \\(.*?\\)\n" string)
-             (string= (match-string 1 string) server-auth-key))
+             (equal (match-string 1 string) (process-get proc :auth-key)))
         (progn
           (setq string (substring string (match-end 0)))
           (process-put proc :authenticated t)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]