From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#7225: 23.2.50; [PATCH] C-c C-c doesn't work in shell mode (Cygwin) Date: Mon, 18 Oct 2010 02:59:57 -0400 Message-ID: References: <4CB8E584.1090800@cornell.edu> <83iq12bnjj.fsf@gnu.org> <4CB99E2C.5030904@cornell.edu> <838w1yb757.fsf@gnu.org> <4CBB6D57.3040108@cornell.edu> <83sk04a2v9.fsf@gnu.org> <4CBB8293.2020401@cornell.edu> Reply-To: Eli Zaretskii NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1287385965 7877 80.91.229.12 (18 Oct 2010 07:12:45 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 18 Oct 2010 07:12:45 +0000 (UTC) Cc: 7225@debbugs.gnu.org To: Ken Brown Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Oct 18 09:12:43 2010 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1P7jtg-0001sX-Qo for geb-bug-gnu-emacs@m.gmane.org; Mon, 18 Oct 2010 09:12:41 +0200 Original-Received: from localhost ([127.0.0.1]:44409 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P7jtf-0000yq-Ra for geb-bug-gnu-emacs@m.gmane.org; Mon, 18 Oct 2010 03:12:39 -0400 Original-Received: from [140.186.70.92] (port=43874 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P7jtW-0000y1-0P for bug-gnu-emacs@gnu.org; Mon, 18 Oct 2010 03:12:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P7jtU-0004rU-Sp for bug-gnu-emacs@gnu.org; Mon, 18 Oct 2010 03:12:29 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:54751) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P7jtU-0004rM-QO for bug-gnu-emacs@gnu.org; Mon, 18 Oct 2010 03:12:28 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1P7jeX-0002vu-MK; Mon, 18 Oct 2010 02:57:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 18 Oct 2010 06:57:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 7225 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 7225-submit@debbugs.gnu.org id=B7225.128738497811263 (code B ref 7225); Mon, 18 Oct 2010 06:57:01 +0000 Original-Received: (at 7225) by debbugs.gnu.org; 18 Oct 2010 06:56:18 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1P7jdo-0002vc-WD for submit@debbugs.gnu.org; Mon, 18 Oct 2010 02:56:17 -0400 Original-Received: from fencepost.gnu.org ([140.186.70.10]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1P7jdn-0002vX-ED for 7225@debbugs.gnu.org; Mon, 18 Oct 2010 02:56:16 -0400 Original-Received: from eliz by fencepost.gnu.org with local (Exim 4.69) (envelope-from ) id 1P7jhN-0004eE-4E; Mon, 18 Oct 2010 02:59:57 -0400 In-reply-to: <4CBB8293.2020401@cornell.edu> (message from Ken Brown on Sun, 17 Oct 2010 19:11:15 -0400) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Mon, 18 Oct 2010 02:57:01 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:40946 Archived-At: > Date: Sun, 17 Oct 2010 19:11:15 -0400 > From: Ken Brown > 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. Does this make sense? If it does, then I think you should add SIGNALS_VIA_CHARACTERS, and leave the rest unaltered, because that's the best Emacs can do if TIOCGPGRP is not supported. > > It's not the wrong process. The problem is that its children might > > not get the signal. > > It is the wrong process on Cygwin. Here's an example. I start a shell > and then run 'cat'. In another shell I run 'ps'. The relevant part of > the output is: > > PID PPID PGID WINPID TTY UID STIME COMMAND > 508 920 508 3552 1 1009 18:50:15 /usr/bin/sh > I 916 508 916 1832 1 1009 18:50:18 /usr/bin/cat > > 508 is the PID as well as the PGID of the shell. But cat is in a > different process group, even though it's a child of the shell (as we > see from the PPID). On the other hand, it has the same controlling tty > as the shell, so we'd be in business if we could get the PGID of the > foreground process of the controlling tty of the shell. That's what I > thought emacs_get_tty_pgrp was doing (according to its comment). When I > type C-c C-c, emacs sends a signal to PGID 508, which is not the right > thing to do. For the case of a foreground command run by the shell, when we want to interrupt that command, yes. But that case is solved by using SIGNALS_VIA_CHARACTERS.