From 1ed95be609c9af283fe0c1b21b760b3abc0792f8 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Tue, 16 Dec 2003 23:28:03 +0000 Subject: [PATCH] * exceptions.cc (set_signal_mask): Report on input argument rather than getsigmask. * fhandler.h (fhandler_base): Make friends with close_all_files. * pinfo.cc (_pinfo::set_ctty): Add more debugging. * sigproc.cc (proc_can_be_signalled): Detect state when signal handler thread is gone in target process as an EPERM situation. Set errno to ESRCH if process doesn't exist. (sigproc_terminate): Set sendsig to illegal value when closed. (sig_send): Rely on proc_can_be_signalled setting the proper errno. * syscalls.cc (close_all_files): Detect when all ttys are closed prior to calling close_all_files. The ctty needs to be closed explicitly in this case. --- winsup/cygwin/ChangeLog | 16 ++++++++++++++++ winsup/cygwin/exceptions.cc | 2 +- winsup/cygwin/fhandler.h | 1 + winsup/cygwin/pinfo.cc | 6 +++++- winsup/cygwin/sigproc.cc | 21 ++++++++++++++++----- winsup/cygwin/syscalls.cc | 10 ++++++++-- 6 files changed, 47 insertions(+), 9 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 926f6e722..291d4ac44 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,19 @@ +2003-12-16 Christopher Faylor + + * exceptions.cc (set_signal_mask): Report on input argument rather than + getsigmask. + + * fhandler.h (fhandler_base): Make friends with close_all_files. + * pinfo.cc (_pinfo::set_ctty): Add more debugging. + * sigproc.cc (proc_can_be_signalled): Detect state when signal handler + thread is gone in target process as an EPERM situation. Set errno to + ESRCH if process doesn't exist. + (sigproc_terminate): Set sendsig to illegal value when closed. + (sig_send): Rely on proc_can_be_signalled setting the proper errno. + * syscalls.cc (close_all_files): Detect when all ttys are closed prior + to calling close_all_files. The ctty needs to be closed explicitly in + this case. + 2003-12-16 Corinna Vinschen * include/cygwin/ipc.h: Include sys/types.h. diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 29323ae7b..341ae732f 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -978,7 +978,7 @@ set_signal_mask (sigset_t newmask, sigset_t& oldmask) { mask_sync->acquire (INFINITE); newmask &= ~SIG_NONMASKABLE; - sigproc_printf ("old mask = %x, new mask = %x", myself->getsigmask (), newmask); + sigproc_printf ("old mask %p, new mask %p", oldmask, newmask); myself->setsigmask (newmask); // Set a new mask mask_sync->release (); if (oldmask & ~newmask) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 4ab7f0264..3e0f3fb3a 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -98,6 +98,7 @@ enum bg_check_types class fhandler_base { friend class dtable; + friend void close_all_files (); protected: DWORD status; private: diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index f1c1c8cff..805f96b0b 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -278,6 +278,7 @@ _pinfo::set_ctty (tty_min *tc, int flags, fhandler_tty_slave *arch) tc->setpgid (pgid); if (cygheap->ctty != arch) { + debug_printf ("cygheap->ctty %p, arch %p", cygheap->ctty, arch); if (!cygheap->ctty) syscall_printf ("ctty NULL"); else @@ -289,7 +290,10 @@ _pinfo::set_ctty (tty_min *tc, int flags, fhandler_tty_slave *arch) } cygheap->ctty = arch; if (arch) - arch->usecount++; + { + arch->usecount++; + debug_printf ("arch usecount for tty%d is %d", tc->ntty, arch->usecount); + } } } } diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 026e847d1..5150e54df 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -248,9 +248,19 @@ proc_can_be_signalled (_pinfo *p) return true; } - return ISSTATE (p, PID_INITIALIZING) || - (((p)->process_state & (PID_ACTIVE | PID_IN_USE)) == - (PID_ACTIVE | PID_IN_USE)); + if (p->sendsig == INVALID_HANDLE_VALUE) + { + set_errno (EPERM); + return false; + } + + if (ISSTATE (p, PID_INITIALIZING) || + (((p)->process_state & (PID_ACTIVE | PID_IN_USE)) == + (PID_ACTIVE | PID_IN_USE))) + return true; + + set_errno (ESRCH); + return false; } bool __stdcall @@ -638,7 +648,9 @@ sigproc_terminate (void) sig_loop_wait = 0; // Tell wait_sig to exit when it is // finished with anything it is doing ForceCloseHandle (sigcomplete_main); - CloseHandle (myself->sendsig); + HANDLE sendsig = myself->sendsig; + myself->sendsig = INVALID_HANDLE_VALUE; + CloseHandle (sendsig); } proc_terminate (); // Terminate process handling thread @@ -679,7 +691,6 @@ sig_send (_pinfo *p, int sig, void *tls) { sigproc_printf ("invalid pid %d(%x), signal %d", p->pid, p->process_state, sig); - set_errno (ESRCH); goto out; } diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 2bb701d8e..cf60e11f4 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -91,14 +91,20 @@ close_all_files (void) if (cygheap->ctty) { - debug_printf ("decrementing ctty usecount"); - cygheap->ctty->usecount--; + if (cygheap->ctty->usecount == 1) + cygheap->ctty->close (); + else + cygheap->ctty->usecount--; + debug_printf ("ctty usecount %d", cygheap->ctty->archetype->usecount); } fhandler_base *fh; for (int i = 0; i < (int) cygheap->fdtab.size; i++) if ((fh = cygheap->fdtab[i]) != NULL) { +#ifdef DEBUGGING + debug_printf ("closing fd %d", i); +#endif fh->close (); cygheap->fdtab.release (i); }