From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Juanma Barranquero" Newsgroups: gmane.emacs.devel Subject: Re: error in server-running-p on M$ Date: Mon, 24 Nov 2008 15:46:08 +0100 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1227548025 13722 80.91.229.12 (24 Nov 2008 17:33:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 24 Nov 2008 17:33:45 +0000 (UTC) Cc: Eli Zaretskii , Ulrich Mueller , emacs-devel@gnu.org To: "Stefan Monnier" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Nov 24 18:34:49 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1L4fKc-00055D-GI for ged-emacs-devel@m.gmane.org; Mon, 24 Nov 2008 18:34:42 +0100 Original-Received: from localhost ([127.0.0.1]:53377 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L4fJT-0005uw-3P for ged-emacs-devel@m.gmane.org; Mon, 24 Nov 2008 12:33:31 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L4e9g-0000cw-4i for emacs-devel@gnu.org; Mon, 24 Nov 2008 11:19:20 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L4e9f-0000cU-J2 for emacs-devel@gnu.org; Mon, 24 Nov 2008 11:19:19 -0500 Original-Received: from [199.232.76.173] (port=50556 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L4djX-00027s-KD for emacs-devel@gnu.org; Mon, 24 Nov 2008 10:52:19 -0500 Original-Received: from an-out-0708.google.com ([209.85.132.240]:38316) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1L4chW-0003WZ-Cs for emacs-devel@gnu.org; Mon, 24 Nov 2008 09:46:10 -0500 Original-Received: by an-out-0708.google.com with SMTP id c38so850347ana.21 for ; Mon, 24 Nov 2008 06:46:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=9lqdEkqbsFtZoNXe8U1wwBkK0NlY+41r7c4a5RDuVpc=; b=TQ+F3ndjuqsmlU+jS3/IQTYOEKguyQgJITy/ZLjUGcafkf50FRTxRCuVWH0n/8xe3e pvakr5MbxUgCRBI3xfpQZUzp661FNYtdeF63JRzcw2x1g8kCP1edJYGFq3XqdNa39SUc pNxZxLLUTd9gLgmB1ubGl3Skt4weTpLDDR47c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=DDmEDnwxr4wqs8vvm4NkqleGR3qYyWPVqRjppEP7pIMPlbUpQgrEjDKMUTlRJz9P3O LqaCu9MTYQUtzkpFCiRhismVf3eBzx6uApP1Flo6UJYuvyTL0/D2YRD8VY/c3y2e0hMO HtXyM70HdwbAtDwo384ZNCNi2Z2VKylOxL6UI= Original-Received: by 10.100.249.10 with SMTP id w10mr1543720anh.0.1227537968917; Mon, 24 Nov 2008 06:46:08 -0800 (PST) Original-Received: by 10.100.13.13 with HTTP; Mon, 24 Nov 2008 06:46:08 -0800 (PST) In-Reply-To: Content-Disposition: inline X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:106089 Archived-At: On Mon, Nov 24, 2008 at 03:55, Stefan Monnier wrote: > That's OK: when we add server-running-p to server-start this objection > will disappear so we can change the code at the same time to remove the > entry when stopping the server. WDYT about the following patch? Juanma 2008-11-24 Juanma Barranquero * server.el (server-sentinel): Uncomment code to delete connection file. (server-running-p): Return t for TCP servers if the auth file says there's a local server and we find an Emacs process with the right PID. Doc fix. (server-start): Save the connection file in the process' property list. Delete it only when we are reasonably convinced that it is not owned by a running server. Index: lisp/server.el =================================================================== RCS file: /sources/emacs/emacs/lisp/server.el,v retrieving revision 1.175 diff -u -2 -b -r1.175 server.el --- lisp/server.el 18 Nov 2008 16:27:09 -0000 1.175 +++ lisp/server.el 24 Nov 2008 14:40:52 -0000 @@ -326,9 +326,7 @@ (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)))) + (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: %s" (process-status proc) msg) proc) (server-delete-client proc)) @@ -465,12 +463,14 @@ (yes-or-no-p "The current server still has clients; delete them? ")) + (let* ((server-dir (if server-use-tcp server-auth-dir server-socket-dir)) + (server-file (expand-file-name server-name server-dir))) (when server-process ;; kill it dead! (ignore-errors (delete-process server-process))) ;; Delete the socket files made by previous server invocations. - (when server-socket-dir - (condition-case () - (delete-file (expand-file-name server-name server-socket-dir)) - (error nil))) + (if (not (server-running-p server-name)) + (ignore-errors (delete-file server-file)) + (setq server-mode nil) ;; already set by the minor mode code + (error "Server %S is already running" server-name)) ;; If this Emacs already had a server, clear out associated status. (while server-clients @@ -481,6 +481,4 @@ (server-log (message "Server stopped")) (setq server-process nil)) - (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 server-dir) @@ -517,4 +515,5 @@ :plist '(:authenticated t))))) (unless server-process (error "Could not start server process")) + (process-put server-process :server-file server-file) (when server-use-tcp (let ((auth-key @@ -535,5 +534,7 @@ (defun server-running-p (&optional name) - "Test whether server NAME is running." + "Test whether server NAME is running. +NOTE: This function is intended to be called from `server-start' +and it is NOT 100% reliable." (interactive (list (if current-prefix-arg @@ -541,5 +542,15 @@ (unless name (setq name server-name)) (condition-case nil - (progn + (if server-use-tcp + (with-temp-buffer + (insert-file-contents-literally + (expand-file-name name server-auth-dir)) + (and (looking-at "127\.0\.0\.1:[0-9]+ \\([0-9]+\\)") + (let ((case-fold-search t) + (proc (assq 'comm + (system-process-attributes + (string-to-number (match-string 1)))))) + (and proc + (string-match-p "emacs" (cdr proc)))))) (delete-process (make-network-process