Subject: Bash and CTRL-C. Problem (almost :-) solved.
From: [email-masked] (Sergey Okhapkin)

31 Mar 1997 02:33:28 -0800
Sender: [email-masked]
Approved: [email-masked]
Distribution: cygnus
Message-ID: <01BC3DA2.E628EF90.cygnus.gnu-win32@sos>
Original-To: "'Gnu-win32'" <[email-masked]>
Original-Cc: "'Geoffrey Noer'" <[email-masked]>, "'Jeremy Allison'" <[email-masked]>
Encoding: 174 TEXT
Original-Sender: [email-masked]

Hi!

*** /g/cdk/winsup/exceptions.cc	Tue Dec 17 01:03:37 1996
--- exceptions.cc	Sun Mar 30 19:39:05 1997
***************
*** 26,31 ****
--- 26,37 ----
  static BOOL ctrl_c_handler (DWORD);
  static void really_exit (int);
  
+ /* When our process is spawned from other cygwin process, u->self->hTread
+    contains not our thread id, but thread id of parent Win32 process.
+    So, save our thread id here for call_handler()
+ */
+ static HANDLE OurhThread;
+ 
  static const struct
  {
    unsigned int code;
***************
*** 99,104 ****
--- 105,117 ----
  #endif
  
    SetConsoleCtrlHandler (ctrl_c_handler, 1);
+   DuplicateHandle (GetCurrentProcess (),
+ 	     GetCurrentThread (),
+ 	     GetCurrentProcess (),
+ 	     &OurhThread,
+ 	     0,
+ 	     1, /* Want kids to see thread id */
+ 	     DUPLICATE_SAME_ACCESS);
  }
  
  /* Utilities for dumping the stack, etc.  */
***************
*** 308,324 ****
       we have to do that since sometimes they don't return - and if
       this thread doesn't return, you won't ever get another exception. */
  
!   res =   SuspendThread (u->self->hThread);
!   debug_printf ("suspend said %d\n", res);
    orig.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER;
!   res =   GetThreadContext (u->self->hThread,  &orig);
  
    rethere = orig.Eip;
    orig.Eip =  (unsigned)&&wrap;
!   SetThreadContext (u->self->hThread,  &orig); /* Restart the thread */
    sigfunc = pfunc;
    sigarg = n;
!   ResumeThread (u->self->hThread);
    return;
    /* This code is run in the standard thread space */
   wrap:
--- 321,337 ----
       we have to do that since sometimes they don't return - and if
       this thread doesn't return, you won't ever get another exception. */
  
!   res =   SuspendThread (OurhThread);
!   debug_printf ("suspend said %d error %d\n", res, GetLastError());
    orig.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER;
!   res =   GetThreadContext (OurhThread,  &orig);
  
    rethere = orig.Eip;
    orig.Eip =  (unsigned)&&wrap;
!   SetThreadContext (OurhThread,  &orig); /* Restart the thread */
    sigfunc = pfunc;
    sigarg = n;
!   ResumeThread (OurhThread);
    return;
    /* This code is run in the standard thread space */
   wrap:
***************
*** 587,593 ****
  	 This is so that ordinary dos progs can look at our
  	 exit value. */
        /* FIXME: exit calls atexit handlers.  */
!       exit ((sig<<8) | 0x10000);
      }
    if ((void *)u->self->sigs[sig].sa_handler == (void *)SIG_IGN)
      {
--- 600,611 ----
  	 This is so that ordinary dos progs can look at our
  	 exit value. */
        /* FIXME: exit calls atexit handlers.  */
!       /*exit ((sig<<8) | 0x10000);*/
! 	 debug_printf ("ctrl_c_handler: type %d, sig %d, about to call exit\n",
! 		type, sig);
! 	 call_handler (exit, (sig<<8) | 0x10000,
! 		(EXCEPTION_RECORD *)0, (CONTEXT *)0);
! 	 return 1;
      }
    if ((void *)u->self->sigs[sig].sa_handler == (void *)SIG_IGN)
      {
***************
*** 595,601 ****
      }
    if ((void *)u->self->sigs[sig].sa_handler == (void *)SIG_ERR)
      {
!       exit (4);
      }
  
    debug_printf ("ctrl_c_handler: type %d, sig %d, about to call %p\n",
--- 613,624 ----
      }
    if ((void *)u->self->sigs[sig].sa_handler == (void *)SIG_ERR)
      {
!       /*exit (4);*/
!       debug_printf ("ctrl_c_handler: type %d, sig %d, about to call exit\n",
! 		type, sig);
!       call_handler (exit, 4,
! 		(EXCEPTION_RECORD *)0, (CONTEXT *)0);
!       return 1;
      }
  
    debug_printf ("ctrl_c_handler: type %d, sig %d, about to call %p\n",
*** /g/cdk/winsup/syscalls.cc	Tue Feb 04 11:51:37 1997
--- syscalls.cc	Sun Mar 30 19:41:26 1997
***************
*** 155,163 ****
  {
    int i;
  
!   for (i = 0; i < getdtablesize(); ++i)
!     if (this_procinfo ()->hmap[i].is_open ()) 
!       _close (i);
  
    process_deletion_queue ();
  }
--- 156,167 ----
  {
    int i;
  
! /* FIXME: This buggy code causes an exception when hmap[i] does not exists.
!    Comment it out for a now
! */
! //  for (i = 0; i < getdtablesize(); ++i)
! //    if (this_procinfo ()->hmap[i].is_open ())
! //      _close (i);
  
    process_deletion_queue ();
  }
*** g:signal.cc Tue Dec 03 13:04:05 1996
--- signal.cc   Sun Mar 30 22:34:46 1997
***************
*** 158,164 ****
        }
        else
        {
!         int res = TerminateProcess (dest->hProcess, sig);
          if (!res)
            {
              __seterrno ();
--- 158,170 ----
        }
        else
        {
!         /* BUG! We cannot use dest->hProcess because this handle is
!            valid only from within childs!
!         */
!         /* int res = TerminateProcess (dest->hProcess, sig);*/
!         HANDLE hP = OpenProcess(PROCESS_TERMINATE, 0, dest->dwProcessId);
!         int res = TerminateProcess (hP, sig);
!         CloseHandle(hP);
          if (!res)
            {
              __seterrno ();

But this patch doesn't help to kill "make" with single ctrl-c... It seems to me, due to missing SIGCLD support in cygwin.dll.

-- 
Sergey Okhapkin
Moscow, Russia
Looking for a job

-
For help on using this list, send a message to
"[email-masked]" with one line of text: "help".