all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: "Juanma Barranquero" <lekktu@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>,
	Ulrich Mueller <ulm@kph.uni-mainz.de>,
	emacs-devel@gnu.org
Subject: Re: error in server-running-p on M$
Date: Thu, 11 Dec 2008 13:47:12 -0500	[thread overview]
Message-ID: <jwvy6ym5zlk.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <f7ccd24b0812110830mbfb33dey5ff7e6455bffbfe@mail.gmail.com> (Juanma Barranquero's message of "Thu, 11 Dec 2008 17:30:27 +0100")

>> I usually prefer it if the command just fails and lets the user run some
>> other command to do what she wants.  Sometimes asking the question is
>> a better option, but here I don't thinkg that its worth it.  The main
>> problem with asking a question is that it's modal.

> I've implemented `server-force-delete', as you suggested.

>> Most/all Unix locks based on process-ids (like the ones used by Emacs,
>> for example) don't pay attention to the process name.  So experience
>> shows it's usually good enough.

> OK. Now `server-running-p' will return t for a matching PID process,
> and does not check the name. It is the safer behavior anyway.

>> We can also reduce the likelihood of leaving behind some obsolete
>> socket/file using kill-emacs-hook.

> When the server is running, `kill-emacs-hook' already contains code to
> turn the server off; (with the patch) that deletes the connection
> file.

> Please, take a look at the attached patch.

Looks good.  I've added some more nitpicks, with which you can install it.

>    ;; 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))))

I didn't mean to leave the comment as is.  Please update the comment to
say that the file *should* be ours thanks to the server-wunning-p check
in server-start.

> +If `server-running-p' returns t, the server is not started.

I'd just write it as "If a server is already running, the server is not
started".

> +      (if (memq (server-running-p server-name) '(nil :other))

Better check (not (eq t (server-running-p server-name))).

> -	;; Remove any leftover socket or authentication file.

You've moved the subsequent line but left out this comment that goes
with it.

> +;;;###autoload
> +(defun server-force-delete (&optional name)
> +  "Unconditionally delete connection file for server NAME.
> +NAME defaults to `server-name'.  With argument, ask for NAME."
> +  (interactive
> +   (list (if current-prefix-arg
> +	     (read-string "Server name: " nil nil server-name))))
> +  (let ((file (expand-file-name (or name server-name)
> +				(if server-use-tcp
> +				    server-auth-dir
> +				  server-socket-dir))))
> +    (condition-case nil
> +	(progn
> +	  (delete-file file)
> +	  (message "Connection file %S deleted" file))
> +      (file-error
> +       (message "Connection file %S not found or not deleted" file)))))

This should first stop our own server.  The user will usually not run
it when our server is running, but she might do it occasionally.

>  (defun server-running-p (&optional name)
> -  "Test whether server NAME is running."
> +  "Test whether server NAME is running.
> +
> +NOTE: This function is designed to return immediately, rather than
> +risking non-termination.  In some cases it returns `:other' when it
> +cannot completely determine whether there's a server running or not."

The docstring should say:
nil => the server is definitely not running.
t   => the server seems to be running.
something else => we cannot determine whether it's running without
    using commands which may have to wait for a long time.

No need to document the :other value.

> +	    (or (and (looking-at "127\.0\.0\.1:[0-9]+ \\([0-9]+\\)")
> +		     (assq 'comm
> +			   (system-process-attributes
> +			    (string-to-number (match-string 1))))

                     t)

> +		:other))

-- Stefan




  reply	other threads:[~2008-12-11 18:47 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-22 11:44 error in server-running-p on M$ dhruva
2008-11-22 11:58 ` Juanma Barranquero
2008-11-22 12:51   ` Eli Zaretskii
2008-11-22 13:00     ` Juanma Barranquero
2008-11-22 13:20       ` Eli Zaretskii
2008-11-22 13:37         ` Juanma Barranquero
2008-11-22 13:53           ` Eli Zaretskii
2008-11-22 14:13             ` Ulrich Mueller
2008-11-22 14:17               ` Juanma Barranquero
2008-11-22 14:29                 ` Ulrich Mueller
2008-11-22 14:36                   ` Juanma Barranquero
2008-11-22 15:35                     ` Ulrich Mueller
2008-11-22 16:04                       ` Juanma Barranquero
2008-11-22 16:52                         ` Ulrich Mueller
2008-11-22 21:47                           ` Juanma Barranquero
2008-11-23  3:56                             ` dhruva
2008-11-23  3:59                               ` Juanma Barranquero
2008-11-23  4:01                                 ` dhruva
2008-11-23  4:03                                   ` Juanma Barranquero
2008-11-23  4:10                                     ` dhruva
2008-11-23  4:15                                       ` Juanma Barranquero
2008-11-23  4:17                                         ` dhruva
2008-11-23  4:19                                           ` Juanma Barranquero
2008-11-23  8:14                                             ` Server protocol (was: Re: error in server-running-p on M$) Ulrich Mueller
2008-11-23 11:33                                               ` Juanma Barranquero
2008-11-23 16:33                                                 ` dhruva
2008-11-23 17:48                                                   ` Juanma Barranquero
2008-11-23  4:02                 ` error in server-running-p on M$ Stefan Monnier
2008-11-23  4:10                   ` Juanma Barranquero
2008-11-23  5:21                     ` Stefan Monnier
2008-11-23  5:32                       ` Juanma Barranquero
2008-11-23  5:57                         ` Stefan Monnier
2008-11-23 11:26                           ` Juanma Barranquero
2008-11-23 12:46                             ` Juanma Barranquero
2008-11-23 13:13                               ` Ulrich Mueller
2008-11-24  2:55                               ` Stefan Monnier
2008-11-24 14:46                                 ` Juanma Barranquero
2008-11-24 15:10                                   ` Ulrich Mueller
2008-11-24 15:16                                     ` Juanma Barranquero
2008-11-24 15:34                                       ` Ulrich Mueller
2008-11-24 15:45                                         ` Juanma Barranquero
2008-12-09 20:46                                   ` Stefan Monnier
2008-12-10  7:05                                     ` Chetan Pandya
2008-12-10 12:59                                     ` Juanma Barranquero
2008-12-10 18:30                                       ` Stefan Monnier
2008-12-10 18:47                                         ` Juanma Barranquero
2008-12-11  2:07                                           ` Stefan Monnier
2008-12-11 16:30                                             ` Juanma Barranquero
2008-12-11 18:47                                               ` Stefan Monnier [this message]
2008-12-12  0:40                                                 ` Juanma Barranquero
2008-12-12  4:51                                                   ` Stefan Monnier
2008-12-12  8:19                                                     ` Juanma Barranquero
2008-12-12 18:49                                                       ` Stefan Monnier
2008-12-12 20:20                                                         ` Juanma Barranquero
2008-11-23  3:58               ` Stefan Monnier
2008-11-23  3:59           ` Stefan Monnier
2008-11-23  4:12             ` Juanma Barranquero
2008-11-23  5:19               ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvy6ym5zlk.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=lekktu@gmail.com \
    --cc=ulm@kph.uni-mainz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.