This is the mail archive of the cygwin-developers@cygwin.com 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]

ctrl_c_handler() vs. cygrunsrv shutdown handling problem


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.

The bottom line is ctrl_c_handler()'s SIGTERM signal arrives before the
SIGINT signal sent by cygrunsrv.  This causes PostgreSQL to perform a
"smart" instead of a "fast" shutdown which can cause an improper
shutdown -- at least under XP.  It is possible that other Unix daemons
may be adversely affected by this double signal problem too.

I verified that preventing Cygwin from sending the SIGTERM:

    @@ -933,7 +933,7 @@ ctrl_c_handler (DWORD type)
          is shut down or console window is closed. */
       if (type == CTRL_SHUTDOWN_EVENT)
         {
    -      sig_send (NULL, SIGTERM);
    +      // sig_send (NULL, SIGTERM);
           return FALSE;
         }
       if (type == CTRL_CLOSE_EVENT)

works around the problem.

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?

Thanks,
Jason

-- 
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D  8784 1AFD E4CC ECF4 8EF6
--- Begin Message --- Jason,

I'm noticing that my suggestion in the writeup I did--regarding deleting the postmaster.pid file on startup--isn't working properly all the time. Took some investigating, but basically what I'm finding is that sometimes, after a Windows shutdown/start or restart, for reasons I'm not 100% clear on, the file

/usr/share/postgresql/data/postmaster.pid

is left behind. Needless to say, this is a problem, as postmaster will fail to startup automatically if that file lingers. And just as important, does this indicate that PostgreSQL is not being given the time it needs to clean house prior to reboot?

My suggestion to add lines to /etc/rc.d/rc.sysinit were based on the presumption that somehow Cygwin (via cygwin1.dll??) made sure this script was run after a restart and before any Cygwin compiled apps kicked in. But this does not appear to be the case.

I'm not sure, but I believe the fact that postmaster is configured via cygrunsrv as an NT service may have something to do with it. That is, unless my hunch is wrong, postmaster in this kind of configuration acts like any NT service. But the init scripts aren't really executed until someone fires up a BASH shell. This, of course, won't work for having PostgreSQL automatically fire up on a Windows restart.

[Further testing is showing that rc.init is not fired up at all on restart, but rather rc.local is. The only problem is that rc.local doesn't seem to kick in until AFTER the NT services have been fired up, making it useless for the purposes here.]

I've spent the better part of my time trying to find a nice, clean, simple way to delete a file on Windows startup (but prior to NT services kicking in), and I'll be darned...it's a lot more difficult than I would have imagined. It seems Microsoft didn't really provide a nice clean boot order mechanism like *nix where you can add commands where needed. I mean, in Linux, you have the bootstrap process, the kernel loading, then init, which uses inittab, which then leads to the rc.* files. If you need to have commands executed at a certain point in the startup procedure, just add the commands to the relevant portion of the bootup process.

But Windows appears not to have such functionality. They have their StartUp folder, but that's useless unless you only need something done AFTER everything like NT services are fired up AND someone has logged in. But there are no obvious built-in mechanisms for running scripts/commands/apps on startup or shutdown at various stages of the processes. At least none I have found so far.

Any thoughts? Also, just as importantly, does the fact a postmaster.pid file exists indicate any issues with the whole cygrunsrv/postmaster configuration? For example, the Windows NT Resource Kit always had a utility called 'srvany.exe', which one could use to do what cygrunsrv is doing (making a non NT service act like one), but they're basically 'wrappers' as it were. When one shuts down Windows, Windows turns around and sends out kill signals to the running apps/services, and in the case of srvany.exe or cygrunsrv, they must then turn around and shutdown the apps under their control.

Is cygrunsrv replying to the Windows kill signal before postmaster has fully shutdown? I honestly don't know. I know that if I manually do a 'net start postmaster' and 'net stop postmaster', PostgreSQL properly creates and deletes the postmaster.pid file without incident. What does it indicate if I do a simple Windows restart when the postmaster.pid file is still there on reboot? And how can I be sure PostgreSQL has properly shutdown (other than checking /var/log/postmaster.log...which doesn't timestamp all its messages)?



---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

--- End Message ---

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