Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Message-ID: <8F23E55D511AD5119A6800D0B76FDDE11E1026@cpex3.channelpoint.com> From: Troy Noble To: "'cygwin AT cygwin DOT com'" Subject: RE: Brainstorming a fix for CTRL-C handling in an emacs shell buf fer (non-TTY) Date: Tue, 8 May 2001 13:57:59 -0600 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" X-Scanned-By: MIMEDefang 1.0 (http://www.roaringpenguin.com/mimedefang/) > >Maybe this code that calls set_console_ctty needs to be moved out > >of dtable.cc:stdio_init and into the constructor or init method of > >the fhandler_console? > It's already in the open method for any tty device. A grep of the code in winsup/cygwin says that set_console_ctty is only getting called in one place, and that's in dtable.cc:stdio_init. .../winsup/cygwin$ grep -n set_console_ctty *.cc dtable.cc:90: extern void set_console_ctty (); dtable.cc:124: set_console_ctty (); fhandler_console.cc:117:set_console_ctty () So maybe just need to remove it from stdio_init and move it to the open method for the tty as intended? But if I don't re-add it to fhandler_console::init (or somewhere in the console setup code) I get undesirable behavior as you can imagine. > > The problem is that stdio_init gets called all the time when > > a process starts, and since ctty<0 and GetConsoleCP() is always > > going to return > 0, my ctty and tty->pgid always get set. > The set_console_ctty function is only called when a cygwin program > is invoked by a non-cygwin program. My statement above was incorrect. I worded this poorly. What I was wanting to say was, in the cases I'm testing where emacs creates a console then starts bash, ctty<0 and GetConsoleCP() is always > 0. So my ctty always gets set by bash when it starts. That's OK, but the problem is that all subsequent child processes that get started by that BASH process can't change ctty (see below). > >I don't think you'd want to run this except when you were creating actual > >fhandler_console instances, right? > A program should have a controlling tty even if it doesn't have a handle open > to the tty. That means that you can't wait until you initialize a console > or a tty before seting the process's controlling tty. I thought all of the (non-console) piped processes would share "nada"? That seems to be the intent of tty_list::get_tty(). That's the approach my last two patches took, as they ensured ctty == -1 for processes that didn't have a fhandler_console. I'm probably just not reading the code right. > So, I guess the question is, why is t->getpgid != myself->pid when > ctrl_c_handler is invoked? What is the value of those two variabl Funny you should ask. Once bash has set the t->pgid, any subsequent child processes never seem to set t->pgid. So the only process that thinks t->getpgid == myself->pid is BASH, which happily ignores the SIGINT. The child processes always exit the handler prematurely because they all perceive that t->getpgid != myself->pid This all goes back to the isatty(0) test I sent a few patches back. But you said we were just fixing the symptom and not the problem, so I didn't pursue that further. Here's the data I've been looking at. I added the aforementioned printf in ctrl_c_handler in the section of code we are looking at. Again, running WITHOUT "tty" in my CYGWIN variable. WHEN RUNNING IN AN EMACS BUFFER: GetConsoleCP=437 isatty=0 pid_exists=1 t->getpgid()=1552 myself->pid=1764 pgid=1520 ppid=1520 progname=c:\cygwin\bin\md5sum.exe GetConsoleCP=437 isatty=0 pid_exists=1 t->getpgid()=1552 myself->pid=1520 pgid=1520 ppid=1552 progname=c:\cygwin\bin\find.exe *> GetConsoleCP=437 isatty=0 pid_exists=1 t->getpgid()=1552 *> myself->pid=1552 pgid=1552 ppid=1 | progname=c:\cygwin\bin\bash.exe | |-- BASH still thinks its controlling the tty as a comparison... WHEN RUNNING IN A CONSOLE WINDOW: .../cygwin$ find . -type f -exec md5sum {} \; 339f1f9844f011af4ceae353070209c6 *./bin/aclocal --> pressed CTRL-C GetConsoleCP=437 isatty=1 pid_exists=1 t->getpgid()=1544 myself->pid=1712 pgid=1544 ppid=1544 progname=c:\cygwin\bin\md5sum.exe GetConsoleCP=437 isatty=1 pid_exists=1 t->getpgid()=1544 myself->pid=1544 pgid=1544 ppid=1868 progname=c:\cygwin\bin\find.exe GetConsoleCP=437 isatty=1 pid_exists=1 t->getpgid()=1544 myself->pid=1868 pgid=1868 ppid=1 progname=c:\cygwin\bin\bash.exe -----Original Message----- From: Christopher Faylor [mailto:cgf AT redhat DOT com] Sent: Tuesday, May 08, 2001 1:08 PM To: 'cygwin AT cygwin DOT com' Subject: Re: Brainstorming a fix for CTRL-C handling in an emacs shell buf fer (non-TTY) On Tue, May 08, 2001 at 12:45:27PM -0600, Troy Noble wrote: >Thanks for your patience. > >I tried the latest patch you checked in for exceptions.cc. >That didn't do it either. I have another alternative though. > >I'm beginning to regret the "brainstorming" in the subject of this >thread, as I'm now feeling somewhat stumped and stupid. I've fixed >it 4 different ways now, but haven't quite hit on the right one. >Sorry for being dense. > >Maybe this code that calls set_console_ctty needs to be moved out >of dtable.cc:stdio_init and into the constructor or init method of >the fhandler_console? It's already in the open method for any tty device. The problem is that stdio_init gets called all the >time when >a process starts, and since ctty<0 and GetConsoleCP() is always >going to return > 0, my ctty and tty->pgid always get set. The set_console_ctty function is only called when a cygwin program is invoked by a non-cygwin program. >I don't think you'd want to run this except when you were creating actual >fhandler_console instances, right? A program should have a controlling tty even if it doesn't have a handle open to the tty. That means that you can't wait until you initialize a console or a tty before seting the process's controlling tty. So, I guess the question is, why is t->getpgid != myself->pid when ctrl_c_handler is invoked? What is the value of those two variables? cgf -- Want to unsubscribe from this list? Check out: http://cygwin.com/ml/#unsubscribe-simple -- Want to unsubscribe from this list? Check out: http://cygwin.com/ml/#unsubscribe-simple