[omniORB] RE: Catching SIGTERM/SIGHUP using omniORB v3.0

Huw Rogers count0@building2.co.jp
Tue, 18 Sep 2001 18:12:16 +0900


Mixing signal handling, threads and ORBs
is hazardous. In particular, a signal handler
cannot safely acquire a mutex or create
another thread. You can cause core dumps and
deadlocks if you try, particularly on SMP systems.
This means you can't call any ORB library
functions either directly or indirectly from
within signal handlers.

In fact, the only portable and safe thing to do
is have a separate cleanup thread waiting on
a semaphore and call sem_post() in the signal
handler, which is one of the very few pthreads
functions that is portably Async-signal safe
(pthread_cond_broadcast and/or pthread_cond_signal
are not).

Also, use sigaction() to register handlers, to
avoid the usual ambiguities of signal().

Mixing Unix signal handlers and shutdown of
multithreaded libraries is an FAQ - it should be
definitively described somewhere, but isn't
AFAIK.

	-Huw

Mark Johnson wrote:
> 
> Nevermind, I think I got if figured out.... I had been looking at it too
> long...
> 
> > -----Original Message-----
> > From: Mark Johnson
> > Sent: Friday, September 14, 2001 3:07 PM
> > To: OmniOrb Mailing List (E-mail)
> > Subject: Catching SIGTERM/SIGHUP using omniORB v3.0
> >
> >
> > ENV: Solaris 2.8, CC, omniORB3.0
> >
> > I'm trying to catch SIGTERM and SIGHUP but I don't seem to be
> > getting them.  Is there anything special that I need to do to
> > get these to work? I tried to see if any of the examples that
> > came with the distribution came with an example of using
> > signals but all I found were ones for threading...
> >
> > Typically, I do something like this:
> >
> > #include <signal.h>
> > extern "C"
> > {
> >    void CloseController(int sig)
> >    {
> >       signal(sig, CloseController);
> >       // ... etc ...
> >    }
> >    void ReloadController(int sig)
> >    {
> >       signal(sig, ReloadController);
> >       // ... etc ...
> >    }
> > }
> > int main( int argc, char * argv[] )
> > {
> >       // ... etc ...
> >    signal( SIGTERM, CloseController );
> >    signal( SIGINT,  CloseController );
> >    signal( SIGHUP,  ReloadController );
> >       // ... etc ...
> >
> >    return 0;
> > }
> >