apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wes Garland <...@page.ca>
Subject Re: Graceful server shutdown?
Date Tue, 05 Jul 2011 15:00:44 GMT
> On both cases I imagine the server cleanup (apr_pool_destroy) should
> be performed after the server loop, and not in the signal handler,
> right?

Correct. Your signal handler should just set a flag and return.  The list of
functions which can be safely run from a signal handler is very short, and
malloc/free are not among them.

b) Shall I set a "keep-running" flag (using mutexes, i.e, a
> synchronized flag) for shutdown on the SIGINT handler?


Not mutexes.  There is no need and the pthread mutex functions (which APR is
implemented on top of on UNIX) are not async-signal safe.  Here is my basic
pattern:

int die = 0;
int signalHandler(signal)
{
  die = signal;
}

while (!die)
{
  /* accept, fork */
}

Wes

-- 
Wesley W. Garland
Director, Product Development
PageMail, Inc.
+1 613 542 2787 x 102

Mime
View raw message