ctrl_c_handler() vs. cygrunsrv shutdown handling problem

Jason Tishler jason@tishler.net
Mon Jun 2 15:54:00 GMT 2003

On Thu, May 29, 2003 at 01:12:36PM -0400, Jason Tishler wrote:
> The SIGTERM signal sent by Cygwin's ctrl_c_handler() is interfering
> with cygrunsrv's shutdown handling -- at least for PostgreSQL.  See
> the attached for an example of this problem.
> [snip]
> I'm willing to work up a patch to fix this problem properly.
> Unfortunately, the only solution I can think of is a new CYGWIN
> setting.  Is this acceptable?  If not, any other ideas?

After more reflection, I propose the attached patch as a solution to the
problem.  In short, I feel that the best (i.e., most general) solution
to the problem is to leave it up to the individual daemon to handle
shutdown events and not hardcode this behavior into the Cygwin DLL.

The following is a more detailed explanation of my reasoning:

    1. The MSDN states the following:


       Note that this signal is received only by services. Interactive
       applications are terminated at logoff, so they are not present
       when the system sends this signal. Services also have their own
       notification mechanism for shutdown events. For more information,
       see Handler. [1]

    2. Unix daemons ported to Cygwin will either run as a native NT
       service (e.g., inetd) or under cygrunsrv (e.g., sshd). [2]

The above implies the current ctrl_c_handler() CTRL_SHUTDOWN_EVENT code

    1. invoked only for services -- never for normal applications
    2. redundant since services have their own notification mechanism

Hence, I feel the hardcoded ctrl_c_handler() CTRL_SHUTDOWN_EVENT code
should be removed, giving daemons full control over their shutdown

Do others agree?  If so, then I'm willing to submit this patch (and the
associated ChangeLog) to cygwin-patches@.  Additionally, I'm will to
patch inetd to handle shutdown events too.  If not, then please help me
resolve this issue.



[1] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/handlerroutine.asp
[2] NT/2000/XP only

PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D  8784 1AFD E4CC ECF4 8EF6
-------------- next part --------------
Index: exceptions.cc
RCS file: /cvs/src/src/winsup/cygwin/exceptions.cc,v
retrieving revision 1.145
diff -u -p -r1.145 exceptions.cc
--- exceptions.cc	17 Apr 2003 20:05:15 -0000	1.145
+++ exceptions.cc	2 Jun 2003 15:03:03 -0000
@@ -932,10 +932,7 @@ ctrl_c_handler (DWORD type)
      for each Cygwin process window that's open when the computer
      is shut down or console window is closed. */
   if (type == CTRL_SHUTDOWN_EVENT)
-    {
-      sig_send (NULL, SIGTERM);
-      return FALSE;
-    }
+    return FALSE;
   if (type == CTRL_CLOSE_EVENT)
       sig_send (NULL, SIGHUP);

More information about the Cygwin-developers mailing list