Subject: Re: bug#11102: 24.0.94; C-x C-c from a client frame sometimes kills the whole Emacs process

From: Eli Zaretskii <[email-masked]>
Date: Fri, 13 Apr 2012 17:38:20 +0300

> From: Juanma Barranquero <[email-masked]>
> Date: Thu, 12 Apr 2012 20:11:38 +0200
> Cc: Chong Yidong <[email-masked]>, [email-masked], [email-masked]
> 
> On Fri, Mar 30, 2012 at 19:45, Eli Zaretskii <[email-masked]> wrote:
> 
> > It most probably is.  Juanma, could you take a look, please?
> 
> A little after current_frame is forced to 0 on Windows (in the -c / -t cases):
> 
> #ifdef WINDOWSNT
>   /* Emacs on Windows does not support GUI and console frames in the same
>      instance.  So, it makes sense to treat the -t and -c options as
>      equivalent, and open a new frame regardless of whether the running
>      instance is GUI or console.  Ideally, we would only set tty = 1 when
>      the instance is running in a console, but alas we don't know that.
>      The simplest workaround is to always ask for a tty frame, and let
>      server.el check whether it makes sense.  */
>   if (tty || !current_frame)
>     {
>       display = (const char *) ttyname (fileno (stdout));
>       current_frame = 0;
>       tty = 1;
>     }
> #endif
> 
> there's this bit of code (non-WINDOWSNT-specific):
> 
>   /* --no-wait implies --current-frame on ttys when there are file
>      arguments or expressions given.  */
>   if (nowait && tty && argc - optind > 0)
>     current_frame = 1;
> 
> which causes the bug. I'm not sure I understand the logic after that
> code, and even less sure it makes sense on Windows. WDYT?

In that case, I don't understand why did Dani expect something
different from what he saw.  I see the same behavior on GNU/Linux: if
emacsclient is invoked with -n, "C-x C-c" kills Emacs.  Perhaps the
bug is that we create a new frame on Windows even though the server
receives the -current-frame parameter.  Why doesn't server.el on
Windows honor that parameter?

As for the logic behind the above code, AFAIU -n means emacsclient is
used as a way of asking Emacs to visit a file without any special
handling; in particular, "C-x #" does _not_ kill the buffer visiting
that file.  So killing the entire session upon "C-x C-c" makes sense
in this case.