This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Sending signals to a subprocess

On Sat, Oct 16, 2010 at 02:06:56PM -0400, Ken Brown wrote:
>On 10/16/2010 1:17 PM, Ken Brown wrote:
>> I could use some help fixing a longstanding bug in the Cygwin build of
>> emacs, in which emacs is unable to send signals to subprocesses.  A
>> symptom from the user's point of view is that one cannot interrupt a
>> process in shell mode by typing C-c C-c.  I've found a workaround that
>> handles that case (SIGINT), as well as SIGQUIT and SIGTSTP.  But as long
>> as I'm fixing this, I'd like to do it right and figure out how to handle
>> all signals.
>> This boils down to finding the right process group ID to pass to 'kill'.
>> On systems that have TIOCGPGRP, emacs uses the following code (in
>> src/process.c) to get this ID:
>> /* Return the foreground process group for the tty/pty that
>>      the process P uses.  */
>> static int
>> emacs_get_tty_pgrp (p)
>>        struct Lisp_Process *p;
>> {
>>     int gid = -1;
>> #ifdef TIOCGPGRP
>>     if (ioctl (p->infd, TIOCGPGRP,&gid) == -1&&  ! NILP (p->tty_name))
>>       {
>>         int fd;
>>         /* Some OS:es (Solaris 8/9) does not allow TIOCGPGRP from the
>> 	 master side.  Try the slave side.  */
>>         fd = emacs_open (SDATA (p->tty_name), O_RDONLY, 0);
>>         if (fd != -1)
>> 	{
>> 	  ioctl (fd, TIOCGPGRP,&gid);
>> 	  emacs_close (fd);
>> 	}
>>       }
>> #endif /* defined (TIOCGPGRP ) */
>>     return gid;
>> }
>> What's the right way to do this in Cygwin?
>I guess it's clear from the context, but I should have said that the 
>problem only arises when emacs has to communicate with the subprocess 
>through a tty that is not the controlling tty of emacs.  So tcgetpgrp() 
>doesn't work.

I am a little confused as to the difference between tcgetpgrp and
TIOCGPGRP given this man page description from "man 4 tty_ioctl" on

       TIOCGPGRP pid_t *argp
              When successful, equivalent to *argp = tcgetpgrp(fd).
              Get the process group ID of the foreground process group on this terminal.

       TIOCSPGRP const pid_t *argp
              Equivalent to tcsetpgrp(fd, *argp).
              Set the foreground process group ID of this terminal.

Do you have a simple test case which demonstrates the difference between
the calls?  It seems odd that TIOCGPGRP would allow more access to a tty
than tcgetpgrp.


Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]