Date: Sun, 17 Oct 2010 19:11:15 -0400
From: Ken Brown<kbrown@cornell.edu>
CC: "7225@debbugs.gnu.org"<7225@debbugs.gnu.org>
The problem that code is trying to solve is how to send a signal to
the whole process group starting at the shell (or whatever process is
the group leader). Failure to do so could mean that the immediate
subprocess of Emacs will get the signal, but its children will not.
If the signal kills the subprocess, its children may remain behind as
orphans.
Am I misunderstanding the comment preceding the definition of
emacs_get_tty_pgrp?
No, you understand it correctly.
Here's what it says:
/* Return the foreground process group for the tty/pty that
the process P uses. */
That's not the same as the process group of the shell, at least in
Cygwin.
Right, these are in general two different groups.
You seem to be assuming that the process group of the shell will
include all of the shell's children.
No, I didn't assume that, sorry for possibly confusing wording.
There's a misunderstanding here: you were talking about the case of
interrupting a command run by a shell, whereas I was talking about the
case of sending a signal to a process that is not the shell, or
perhaps about signaling the shell itself.
For the case you ware talking about, sending the signal to the shell
is indeed the wrong thing, because the shell makes any foreground
command it runs into a separate process group, and it's that process
group that we want to send the signal to. But for that case, you
already found the right solution: use SIGNALS_VIA_CHARACTERS. This
does exactly the right thing, like the INTR character typed on the
tty.
What's left is the case of signals other that SIGINT/SIGQUIT/SIGTSTP.
In that case, in the absence of TIOCGPGRP, the code in process.c
supports sending the signal only to p->pid's process group (if p->pid
is not a group leader, only it itself will be signaled). I think this
is better than punting, because if there _is_ a process group of which
p->pid is the leader, doing what the code does now will not leave
orphans, processes other than p->pid that belonged to p->pid's group.
It is true that this group might not be the foreground process group,
but with signals other than SIGINT/SIGQUIT/SIGTSTP, this matters much
less, I think.