unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Lost socket for detached Emacs, how to regain control?
@ 2008-11-04 15:32 Ulrich Mueller
  2008-11-06  1:31 ` Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Ulrich Mueller @ 2008-11-04 15:32 UTC (permalink / raw)
  To: emacs-devel

Consider the following scenario:
  - emacs --daemon is running in the background without any open frame
  - server-start is also called in another Emacs process

Now there is no more way to connect to the detached Emacs. (Or am I
missing something?)

Maybe it would be feasible to add a recovery mechanism for such a
case, like binding [sigusr1] to server-start?

Ulrich




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Lost socket for detached Emacs, how to regain control?
  2008-11-04 15:32 Lost socket for detached Emacs, how to regain control? Ulrich Mueller
@ 2008-11-06  1:31 ` Stefan Monnier
  2008-11-06  9:47   ` Juanma Barranquero
  2008-11-07  6:48   ` Ulrich Mueller
  0 siblings, 2 replies; 10+ messages in thread
From: Stefan Monnier @ 2008-11-06  1:31 UTC (permalink / raw)
  To: Ulrich Mueller; +Cc: emacs-devel

> Consider the following scenario:
>   - emacs --daemon is running in the background without any open frame
>   - server-start is also called in another Emacs process

> Now there is no more way to connect to the detached Emacs. (Or am I
> missing something?)

> Maybe it would be feasible to add a recovery mechanism for such a
> case, like binding [sigusr1] to server-start?

That would be easy to do, indeed.  Another option is for server-start to
try and detect that there's already an active socket (using
server-running-p) and refuse to start.


        Stefan




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Lost socket for detached Emacs, how to regain control?
  2008-11-06  1:31 ` Stefan Monnier
@ 2008-11-06  9:47   ` Juanma Barranquero
  2008-11-06 14:15     ` Stefan Monnier
  2008-11-07  6:48   ` Ulrich Mueller
  1 sibling, 1 reply; 10+ messages in thread
From: Juanma Barranquero @ 2008-11-06  9:47 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Ulrich Mueller, emacs-devel

On Thu, Nov 6, 2008 at 02:31, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> Another option is for server-start to
> try and detect that there's already an active socket (using
> server-running-p) and refuse to start.

That would be useful even for local servers using TCP sockets, but
server-running-p currently does work only for local sockets.

The following is a simple way to at least know whether there's a
process called Emacs with the same pid that is stored in the
authentication file.

(with-temp-buffer
  (insert-file-contents-literally (expand-file-name server-name
server-auth-dir))
  (skip-chars-forward "0-9:.")
  (let ((case-fold-search t)
        (proc (assq 'comm (system-process-attributes (read (point-marker))))))
    (and proc
         (string-match-p "emacs" (cdr proc)))))

  Juanma




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Lost socket for detached Emacs, how to regain control?
  2008-11-06  9:47   ` Juanma Barranquero
@ 2008-11-06 14:15     ` Stefan Monnier
  2008-11-06 15:50       ` Juanma Barranquero
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2008-11-06 14:15 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: Ulrich Mueller, emacs-devel

>> Another option is for server-start to try and detect that there's
>> already an active socket (using server-running-p) and refuse
>> to start.

> That would be useful even for local servers using TCP sockets, but
> server-running-p currently does work only for local sockets.

Indeed, for TCP sockets it would be useful as well, but it risks
suffering from a long timeout.

> The following is a simple way to at least know whether there's a
> process called Emacs with the same pid that is stored in the
> authentication file.

That's a good alternative, tho it should check somehow that the server
is supposed to run on the same machine.


        Stefan




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Lost socket for detached Emacs, how to regain control?
  2008-11-06 14:15     ` Stefan Monnier
@ 2008-11-06 15:50       ` Juanma Barranquero
  2008-11-07  2:15         ` Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Juanma Barranquero @ 2008-11-06 15:50 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Ulrich Mueller, emacs-devel

On Thu, Nov 6, 2008 at 15:15, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> That's a good alternative, tho it should check somehow that the server
> is supposed to run on the same machine.

The simplest way to do it without any networking (and so, without
risking delays) is just checking that the address in the server auth
file is 127.0.0.1.

But I have a doubt. What is the intended use of `server-running-p'?
That affects whether to check for local sockets, TCP sockets, or both.

   Juanma




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Lost socket for detached Emacs, how to regain control?
  2008-11-06 15:50       ` Juanma Barranquero
@ 2008-11-07  2:15         ` Stefan Monnier
  2008-11-07 14:47           ` Juanma Barranquero
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2008-11-07  2:15 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: Ulrich Mueller, emacs-devel

>> That's a good alternative, tho it should check somehow that the server
>> is supposed to run on the same machine.

> The simplest way to do it without any networking (and so, without
> risking delays) is just checking that the address in the server auth
> file is 127.0.0.1.

> But I have a doubt. What is the intended use of `server-running-p'?
> That affects whether to check for local sockets, TCP sockets, or both.

Currently it's not used (except in some people's .emacs).  The intended
use is in start-server to try and prevent hijacking the socket of
a pre-existing server.  So it's probably not less important for TCP where
two servers of the same name can actually co-exist on different ports.


        Stefan




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Lost socket for detached Emacs, how to regain control?
  2008-11-06  1:31 ` Stefan Monnier
  2008-11-06  9:47   ` Juanma Barranquero
@ 2008-11-07  6:48   ` Ulrich Mueller
  2008-11-07 14:39     ` Stefan Monnier
  2008-11-07 14:54     ` Dan Nicolaescu
  1 sibling, 2 replies; 10+ messages in thread
From: Ulrich Mueller @ 2008-11-07  6:48 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

>>>>> On Wed, 05 Nov 2008, Stefan Monnier wrote:

>> Consider the following scenario:
>> - emacs --daemon is running in the background without any open frame
>> - server-start is also called in another Emacs process

>> Now there is no more way to connect to the detached Emacs. (Or am I
>> missing something?)

>> Maybe it would be feasible to add a recovery mechanism for such a
>> case, like binding [sigusr1] to server-start?

> That would be easy to do, indeed.  Another option is for server-start
> to try and detect that there's already an active socket (using
> server-running-p) and refuse to start.

Or both? The server process or socket could be non-functional for other
reasons.

In case server-start is changed, maybe an option to force a restart
should be added.

Ulrich




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Lost socket for detached Emacs, how to regain control?
  2008-11-07  6:48   ` Ulrich Mueller
@ 2008-11-07 14:39     ` Stefan Monnier
  2008-11-07 14:54     ` Dan Nicolaescu
  1 sibling, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2008-11-07 14:39 UTC (permalink / raw)
  To: Ulrich Mueller; +Cc: emacs-devel

>>> Maybe it would be feasible to add a recovery mechanism for such a
>>> case, like binding [sigusr1] to server-start?
>> That would be easy to do, indeed.  Another option is for server-start
>> to try and detect that there's already an active socket (using
>> server-running-p) and refuse to start.
> Or both? The server process or socket could be non-functional for other
> reasons.

If you want.  I don't find the feature of "sigusr1 causes
server-restart" very useful, since in the rare remaining cases where the
problem may happen, you may as well kill the server process altogether
and start a new one.  But I wouldn't care to oppose it either.


        Stefan





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Lost socket for detached Emacs, how to regain control?
  2008-11-07  2:15         ` Stefan Monnier
@ 2008-11-07 14:47           ` Juanma Barranquero
  0 siblings, 0 replies; 10+ messages in thread
From: Juanma Barranquero @ 2008-11-07 14:47 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Ulrich Mueller, emacs-devel

On Fri, Nov 7, 2008 at 03:15, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> Currently it's not used (except in some people's .emacs).  The intended
> use is in start-server to try and prevent hijacking the socket of
> a pre-existing server.  So it's probably not less important for TCP where
> two servers of the same name can actually co-exist on different ports.

But, you cannot have two TCP servers co-existing with the same name on
the same computer unless you customize `server-auth-dir' with
different values in each instance.

At that point, how do you direct `server-running-p' to decide what
director(y|ies) to look for?

  Juanma




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Lost socket for detached Emacs, how to regain control?
  2008-11-07  6:48   ` Ulrich Mueller
  2008-11-07 14:39     ` Stefan Monnier
@ 2008-11-07 14:54     ` Dan Nicolaescu
  1 sibling, 0 replies; 10+ messages in thread
From: Dan Nicolaescu @ 2008-11-07 14:54 UTC (permalink / raw)
  To: Ulrich Mueller; +Cc: Stefan Monnier, emacs-devel

Ulrich Mueller <ulm@gentoo.org> writes:

  > >>>>> On Wed, 05 Nov 2008, Stefan Monnier wrote:
  > 
  > >> Consider the following scenario:
  > >> - emacs --daemon is running in the background without any open frame
  > >> - server-start is also called in another Emacs process
  > 
  > >> Now there is no more way to connect to the detached Emacs. (Or am I
  > >> missing something?)
  > 
  > >> Maybe it would be feasible to add a recovery mechanism for such a
  > >> case, like binding [sigusr1] to server-start?
  > 
  > > That would be easy to do, indeed.  Another option is for server-start
  > > to try and detect that there's already an active socket (using
  > > server-running-p) and refuse to start.
  > 
  > Or both? The server process or socket could be non-functional for other
  > reasons.

Like a silly cron job removing the socket from /tmp.  I've had a
[sigusr2] binding to server-start in my .emacs for a long time for
exactly that reason.  It has been very useful quite a few times.




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-11-07 14:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-04 15:32 Lost socket for detached Emacs, how to regain control? Ulrich Mueller
2008-11-06  1:31 ` Stefan Monnier
2008-11-06  9:47   ` Juanma Barranquero
2008-11-06 14:15     ` Stefan Monnier
2008-11-06 15:50       ` Juanma Barranquero
2008-11-07  2:15         ` Stefan Monnier
2008-11-07 14:47           ` Juanma Barranquero
2008-11-07  6:48   ` Ulrich Mueller
2008-11-07 14:39     ` Stefan Monnier
2008-11-07 14:54     ` Dan Nicolaescu

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).