unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* y-or-n-p and emacs --daemon
@ 2008-12-03 10:44 Ulrich Mueller
  2008-12-03 11:11 ` Espen Wiborg
  0 siblings, 1 reply; 13+ messages in thread
From: Ulrich Mueller @ 2008-12-03 10:44 UTC (permalink / raw)
  To: emacs-devel

Considering bugs like #1474, I wonder if y-or-n-p DTRT?

Try the following:

   $ emacs-23 -Q --daemon --eval '(y-or-n-p "hello? ")'

1. It hangs indefinitely,
2. it does not detach properly (it forks, but the parent doesn't exit),
3. it doesn't start the server.

Of course 2. and 3. are a consequence of 1. since it doesn't come to
the point where daemon-initialized gets called.

Now the problem is that y-or-n-p is called from many places, so
depending on the configuration there is some chance that Emacs will
ask for user interaction before initialisation is finished. There is
even one in server-start (which AFAICS won't be triggered in daemon
mode, but still...).

Shouldn't y-or-n-p signal an error if there is nobody to answer its
question? (Where necessary, its call could be condition-cased then.)

Same arguments apply to yes-or-no-p, of course.

Ulrich




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

* Re: y-or-n-p and emacs --daemon
  2008-12-03 10:44 y-or-n-p and emacs --daemon Ulrich Mueller
@ 2008-12-03 11:11 ` Espen Wiborg
  2008-12-03 19:33   ` Chong Yidong
  0 siblings, 1 reply; 13+ messages in thread
From: Espen Wiborg @ 2008-12-03 11:11 UTC (permalink / raw)
  To: emacs-devel

Ulrich Mueller <ulm@gentoo.org> writes:
> Considering bugs like #1474, I wonder if y-or-n-p DTRT?
>
> Try the following:
>
>    $ emacs-23 -Q --daemon --eval '(y-or-n-p "hello? ")'
>
> 1. It hangs indefinitely,
> 2. it does not detach properly (it forks, but the parent doesn't exit),
> 3. it doesn't start the server.
>
> Of course 2. and 3. are a consequence of 1. since it doesn't come to
> the point where daemon-initialized gets called.
>
> Now the problem is that y-or-n-p is called from many places, so
> depending on the configuration there is some chance that Emacs will
> ask for user interaction before initialisation is finished. There is
> even one in server-start (which AFAICS won't be triggered in daemon
> mode, but still...).

Actually, this yes-or-no-p *is* triggered in daemon mode, but only
(AFAICT) in the case uncovered by bug #1310, where a client's X
connection is lost and the daemon tries to shut down.

-- 
Espen Wiborg <espenhw@grumblesmurf.org> - Veritas vos liberabit
'Pooh?' he said.  'Yes, Piglet?' Pooh replied. 'Nothing,' Piglet
said, taking Pooh's paw, 'I just wanted to throw an exception.'




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

* Re: y-or-n-p and emacs --daemon
  2008-12-03 11:11 ` Espen Wiborg
@ 2008-12-03 19:33   ` Chong Yidong
  2008-12-03 19:53     ` Dan Nicolaescu
  0 siblings, 1 reply; 13+ messages in thread
From: Chong Yidong @ 2008-12-03 19:33 UTC (permalink / raw)
  To: Espen Wiborg; +Cc: emacs-devel

Espen Wiborg <espenhw@grumblesmurf.org> writes:

>>    $ emacs-23 -Q --daemon --eval '(y-or-n-p "hello? ")'
>>
>> 1. It hangs indefinitely,
>> 2. it does not detach properly (it forks, but the parent doesn't exit),
>> 3. it doesn't start the server.
>>
>> Now the problem is that y-or-n-p is called from many places, so
>> depending on the configuration there is some chance that Emacs will
>> ask for user interaction before initialisation is finished. There is
>> even one in server-start (which AFAICS won't be triggered in daemon
>> mode, but still...).
>
> Actually, this yes-or-no-p *is* triggered in daemon mode, but only
> (AFAICT) in the case uncovered by bug #1310, where a client's X
> connection is lost and the daemon tries to shut down.

The only thing I can think of is to make y-or-n-p and yes-or-no-p
default to "no" when only the daemon's dummy terminal is open.  Does
anyone have a better suggestion?




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

* Re: y-or-n-p and emacs --daemon
  2008-12-03 19:33   ` Chong Yidong
@ 2008-12-03 19:53     ` Dan Nicolaescu
  2008-12-03 21:07       ` Chong Yidong
  0 siblings, 1 reply; 13+ messages in thread
From: Dan Nicolaescu @ 2008-12-03 19:53 UTC (permalink / raw)
  To: Chong Yidong; +Cc: emacs-devel, Espen Wiborg

Chong Yidong <cyd@stupidchicken.com> writes:

  > Espen Wiborg <espenhw@grumblesmurf.org> writes:
  > 
  > >>    $ emacs-23 -Q --daemon --eval '(y-or-n-p "hello? ")'
  > >>
  > >> 1. It hangs indefinitely,
  > >> 2. it does not detach properly (it forks, but the parent doesn't exit),
  > >> 3. it doesn't start the server.
  > >>
  > >> Now the problem is that y-or-n-p is called from many places, so
  > >> depending on the configuration there is some chance that Emacs will
  > >> ask for user interaction before initialisation is finished. There is
  > >> even one in server-start (which AFAICS won't be triggered in daemon
  > >> mode, but still...).
  > >
  > > Actually, this yes-or-no-p *is* triggered in daemon mode, but only
  > > (AFAICT) in the case uncovered by bug #1310, where a client's X
  > > connection is lost and the daemon tries to shut down.
  > 
  > The only thing I can think of is to make y-or-n-p and yes-or-no-p
  > default to "no" when only the daemon's dummy terminal is open.  

Bad idea:
(unless (y-or-n-p "Stop me from removing all your files") 
        /bin/rm -rf /
        )

  > Does anyone have a better suggestion?

Ignore it, or fix it properly: so that it works like y-or-n-p when using -batch.




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

* Re: y-or-n-p and emacs --daemon
  2008-12-03 19:53     ` Dan Nicolaescu
@ 2008-12-03 21:07       ` Chong Yidong
  2008-12-03 21:53         ` Dan Nicolaescu
  2008-12-04  2:16         ` Stefan Monnier
  0 siblings, 2 replies; 13+ messages in thread
From: Chong Yidong @ 2008-12-03 21:07 UTC (permalink / raw)
  To: Dan Nicolaescu; +Cc: emacs-devel, Espen Wiborg

Dan Nicolaescu <dann@ics.uci.edu> writes:

>   > The only thing I can think of is to make y-or-n-p and yes-or-no-p
>   > default to "no" when only the daemon's dummy terminal is open.  
>
> Bad idea:
> (unless (y-or-n-p "Stop me from removing all your files") 
>         /bin/rm -rf /
>         )
>
>   > Does anyone have a better suggestion?
>
> Ignore it, or fix it properly: so that it works like y-or-n-p when
> using -batch.

I don't think that would solve the problem either, since AFAIU the
daemon might not have a user accessible terminal at all (as bug#1310).

What we could do is to make y-or-n-p signal an error.  Individual
callers will then have to check for daemon-mode and do something else
before calling y-or-n-p; which is also probably the way to fix bug#1310.




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

* Re: y-or-n-p and emacs --daemon
  2008-12-03 21:07       ` Chong Yidong
@ 2008-12-03 21:53         ` Dan Nicolaescu
  2008-12-04  1:05           ` Stephen J. Turnbull
  2008-12-04  2:16         ` Stefan Monnier
  1 sibling, 1 reply; 13+ messages in thread
From: Dan Nicolaescu @ 2008-12-03 21:53 UTC (permalink / raw)
  To: Chong Yidong; +Cc: emacs-devel, Espen Wiborg

Chong Yidong <cyd@stupidchicken.com> writes:

  > Dan Nicolaescu <dann@ics.uci.edu> writes:
  > 
  > >   > The only thing I can think of is to make y-or-n-p and yes-or-no-p
  > >   > default to "no" when only the daemon's dummy terminal is open.  
  > >
  > > Bad idea:
  > > (unless (y-or-n-p "Stop me from removing all your files") 
  > >         /bin/rm -rf /
  > >         )
  > >
  > >   > Does anyone have a better suggestion?
  > >
  > > Ignore it, or fix it properly: so that it works like y-or-n-p when
  > > using -batch.
  > 
  > I don't think that would solve the problem either, since AFAIU the
  > daemon might not have a user accessible terminal at all (as bug#1310).

Bug#1310 is a long standing Gtk+ bug, Jan has made workarounds for it a
few times, and it is looking at this instance too.  So that bug is not
related to this issue.  BTW, the patch in #1310 is probably correct.

  > What we could do is to make y-or-n-p signal an error.  

IMO redefining the meaning of y-or-n-p is still not a good idea.




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

* Re: y-or-n-p and emacs --daemon
  2008-12-03 21:53         ` Dan Nicolaescu
@ 2008-12-04  1:05           ` Stephen J. Turnbull
  0 siblings, 0 replies; 13+ messages in thread
From: Stephen J. Turnbull @ 2008-12-04  1:05 UTC (permalink / raw)
  To: Dan Nicolaescu; +Cc: Chong Yidong, Espen Wiborg, emacs-devel

Dan Nicolaescu writes:

 > IMO redefining the meaning of y-or-n-p is still not a good idea.

The problem is that y-or-n-p is not defined at all if there's no
interactive terminal.  It's not a redefinition.




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

* Re: y-or-n-p and emacs --daemon
  2008-12-03 21:07       ` Chong Yidong
  2008-12-03 21:53         ` Dan Nicolaescu
@ 2008-12-04  2:16         ` Stefan Monnier
  2008-12-04  3:02           ` Dan Nicolaescu
  2008-12-04 11:15           ` Ulrich Mueller
  1 sibling, 2 replies; 13+ messages in thread
From: Stefan Monnier @ 2008-12-04  2:16 UTC (permalink / raw)
  To: Chong Yidong; +Cc: Dan Nicolaescu, Espen Wiborg, emacs-devel

>> Bad idea:
>> (unless (y-or-n-p "Stop me from removing all your files") 
>> /bin/rm -rf /
>> )

Such a question would be a bug that we need fixing.  Usually Emacs is
pretty consistent in asking questions in such a way that `n' is
a safe answer.

>> Ignore it, or fix it properly: so that it works like y-or-n-p when
>> using -batch.
> I don't think that would solve the problem either, since AFAIU the
> daemon might not have a user accessible terminal at all (as bug#1310).

Does someone know the reason for this problem?  E.g. it's not clear to
me why the y-or-n-p question is displayed (even though it's after
"Starting Emacs daemon", so stdout should have been closed) but the
answer is ignored (or is it?).

Ideally, either the question comes before detaching and it should then
behave as it does in -batch, or the question comes after detaching and
it should then wait for a frame to be created to display the question
in there.


        Stefan




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

* Re: y-or-n-p and emacs --daemon
  2008-12-04  2:16         ` Stefan Monnier
@ 2008-12-04  3:02           ` Dan Nicolaescu
  2008-12-04  5:29             ` Stefan Monnier
  2008-12-04 11:15           ` Ulrich Mueller
  1 sibling, 1 reply; 13+ messages in thread
From: Dan Nicolaescu @ 2008-12-04  3:02 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Chong Yidong, emacs-devel, Espen Wiborg

Stefan Monnier <monnier@iro.umontreal.ca> writes:

  > >> Bad idea:
  > >> (unless (y-or-n-p "Stop me from removing all your files") 
  > >> /bin/rm -rf /
  > >> )
  > 
  > Such a question would be a bug that we need fixing.  Usually Emacs is
  > pretty consistent in asking questions in such a way that `n' is
  > a safe answer.

That's not safe enough, this might happen for code that is in the user's
.emacs.

  > >> Ignore it, or fix it properly: so that it works like y-or-n-p when
  > >> using -batch.
  > > I don't think that would solve the problem either, since AFAIU the
  > > daemon might not have a user accessible terminal at all (as bug#1310).
  > 
  > Does someone know the reason for this problem?  E.g. it's not clear to
  > me why the y-or-n-p question is displayed (even though it's after
  > "Starting Emacs daemon", so stdout should have been closed) but the

"Starting Emacs daemon" is printed at the beginning of `command-line-1',
before detaching.
--eval is also run before detaching.

  > answer is ignored (or is it?).

It's not ignored, the input is not setup right.  
strace shows:
select(1, [], NULL, NULL, {100000, 0}
          ^^^
          select is waiting on a empty set of descriptors

so noninteractive || IS_DAEMON is probably missing in some place(s).





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

* Re: y-or-n-p and emacs --daemon
  2008-12-04  3:02           ` Dan Nicolaescu
@ 2008-12-04  5:29             ` Stefan Monnier
  0 siblings, 0 replies; 13+ messages in thread
From: Stefan Monnier @ 2008-12-04  5:29 UTC (permalink / raw)
  To: Dan Nicolaescu; +Cc: Chong Yidong, emacs-devel, Espen Wiborg

>> answer is ignored (or is it?).
> It's not ignored, the input is not setup right.  
> strace shows:
> select(1, [], NULL, NULL, {100000, 0}
>           ^^^
>           select is waiting on a empty set of descriptors

Oh, I see.

> so noninteractive || IS_DAEMON is probably missing in some place(s).

Yes sounds right, tho I'd probably use FRAME_INITIAL_P (SELECTED_FRAME ())
isntead.


        Stefan




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

* Re: y-or-n-p and emacs --daemon
  2008-12-04  2:16         ` Stefan Monnier
  2008-12-04  3:02           ` Dan Nicolaescu
@ 2008-12-04 11:15           ` Ulrich Mueller
  2008-12-04 11:28             ` Thierry Volpiatto
  2008-12-04 13:15             ` Stefan Monnier
  1 sibling, 2 replies; 13+ messages in thread
From: Ulrich Mueller @ 2008-12-04 11:15 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Chong Yidong, Dan Nicolaescu, emacs-devel, Espen Wiborg

>>>>> On Wed, 03 Dec 2008, Stefan Monnier wrote:

> Ideally, either the question comes before detaching and it should then
> behave as it does in -batch,

I think that this is unaccaptable. A daemon shouldn't be interactive
before detaching. Besides, there might not be any terminal associated
with stdin, so this doesn't solve the problem for this case.

Can't y-or-n-p signal an error if it's called before detaching?

Ulrich




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

* Re: y-or-n-p and emacs --daemon
  2008-12-04 11:15           ` Ulrich Mueller
@ 2008-12-04 11:28             ` Thierry Volpiatto
  2008-12-04 13:15             ` Stefan Monnier
  1 sibling, 0 replies; 13+ messages in thread
From: Thierry Volpiatto @ 2008-12-04 11:28 UTC (permalink / raw)
  To: emacs-devel

Ulrich Mueller <ulm@gentoo.org> writes:

>>>>>> On Wed, 03 Dec 2008, Stefan Monnier wrote:
>
>> Ideally, either the question comes before detaching and it should then
>> behave as it does in -batch,
>
> I think that this is unaccaptable. A daemon shouldn't be interactive
> before detaching. Besides, there might not be any terminal associated
> with stdin, so this doesn't solve the problem for this case.
>
> Can't y-or-n-p signal an error if it's called before detaching?

Note:
y-or-n-p is not the only case of interactivity that can happen when
starting daemon:
if desktop save buffer that has been opened as /su:... or /sudo 
it will prompt for password and will hang until user kill process.
 
-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France





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

* Re: y-or-n-p and emacs --daemon
  2008-12-04 11:15           ` Ulrich Mueller
  2008-12-04 11:28             ` Thierry Volpiatto
@ 2008-12-04 13:15             ` Stefan Monnier
  1 sibling, 0 replies; 13+ messages in thread
From: Stefan Monnier @ 2008-12-04 13:15 UTC (permalink / raw)
  To: Ulrich Mueller; +Cc: Chong Yidong, Dan Nicolaescu, emacs-devel, Espen Wiborg

>> Ideally, either the question comes before detaching and it should then
>> behave as it does in -batch,
> I think that this is unaccaptable.  A daemon shouldn't be interactive
> before detaching.  Besides, there might not be any terminal associated
> with stdin, so this doesn't solve the problem for this case.

My comment was not intended to imply that this will solve all problems.
But it will at least make the code work as close to its intended
behavior as possible.

Now it will indeed be the case that the daemon will often be started
non-interactively, in which case any form of interactivity is
undesirable.  This is a separate problem.  I'm not sure how best to
solve it, tho if we can detect that stdin=/dev/null (i.e. when we reach
EOF on stdin) we might want to signal an error, like you propose.


        Stefan




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

end of thread, other threads:[~2008-12-04 13:15 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-03 10:44 y-or-n-p and emacs --daemon Ulrich Mueller
2008-12-03 11:11 ` Espen Wiborg
2008-12-03 19:33   ` Chong Yidong
2008-12-03 19:53     ` Dan Nicolaescu
2008-12-03 21:07       ` Chong Yidong
2008-12-03 21:53         ` Dan Nicolaescu
2008-12-04  1:05           ` Stephen J. Turnbull
2008-12-04  2:16         ` Stefan Monnier
2008-12-04  3:02           ` Dan Nicolaescu
2008-12-04  5:29             ` Stefan Monnier
2008-12-04 11:15           ` Ulrich Mueller
2008-12-04 11:28             ` Thierry Volpiatto
2008-12-04 13:15             ` Stefan Monnier

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