Subject: bug#23378: 25.0.94; Enacs daemon "get-device-terminal" error

From: Eli Zaretskii <[email-masked]>
Date: Sat, 09 Jul 2016 13:47:06 +0300

> From: Live System User <[email-masked]>
> Date: Sun, 03 Jul 2016 16:12:28 -0400
> 
>         This bug is still present in Emacs 25.0.94
> 
>         When trying to kill it via C-x C-c `save-buffers-kill-terminal'
>         I just see the message:
> 
> get-device-terminal: Invalid argument #<terminal 9> in
> 'get-device-terminal'
> 
>         Neither "File->Quit" or "File->Delete Frame" from the menubar
>         nor clicking on X to close the frame kills Emacs or closes
>         its frame -- the Emacs frame remains on the screen.

Does this happen only with Emacs started as a daemon?  If not, can you
show a recipe without the dameon?

Also, does this happen if you start Emacs with -Q?  If not, there's a
chance some of your customizations are an important factor here.

I looked at the code which signals this error, and the only way
forward with this bug seems to be to step with a debugger through the
code in terminal-live-p (Fterminal_live_p in terminal.c), and see what
happens there.  Presumably, this mysterious terminal belongs to a
frame that was already deleted or something, but I don't see how that
could happen, and your description is not detailed enough.

(Also, your Emacs build lacks the debugging symbols, so before you try
debugging it further, please rebuild with debugging information.)

In a merged bug #22362, you give the following procedure for
reproducing the bug:

  % emacs --daemon=daemon2
  % emacsclient -f ~/emacs.d/server/daemon2 -e "(daemonp)"
  (emacs pops up a window)

  From a gnome-terminal:
  % emacsclient -nw -f ~/emacs.d/server/daemon2 -e "(daemonp)"
  (I get an emacs terminal window)
  ^X^C
  ^Z
  % bg

Does the problem go away if you first type "fg" from the same terminal
where you typed "bg"?  Also, doesn't "C-x C-c" you type before "bg"
already close the terminal frame that the previous emacsclient command
created?  If so, what exactly does ^Z after it do?

>         I'll be able to keep the process around for a little while
>         (i.e. not kill it from the command line) if more info
>         is reqested to dbug this.

As mentioned above, your Emacs binary cannot be debugged, as it lacks
debugging info, so please prepare a build with that info first.

Thanks.