I was trying to hookup a debugger to registrar when discovered my
breakpoints were getting diverted to a running thread OsSignalTask.
This thread awaited for *any* possible OS signal, then
indiscriminately terminated the server. If the signal was SIGTERM, it
did a graceful shutdown, but none the less: always a shutdown. The
normal way AFAIK to perform a graceful shutdown is to register a
procedure pointer with what signal you want to trigger that procedure
I have 2 points
1.) Why have an extra thread spinning when OS will already call your
shutdown asynchronously for you?
2.) Why reinvent the wheel on signal handling, let's remove
sipXportLib's awaitSignal() as it adds no value?
Attach is a patch of new method
diff --git a/sipXregistry/src/main.cpp b/sipXregistry/src/main.cpp
index 69455d5..5b8fc06 100644
--- a/sipXregistry/src/main.cpp
+++ b/sipXregistry/src/main.cpp
@@ -166,56 +166,17 @@ initSysLog(OsConfigDb* pConfig)
}
-class SignalTask : public OsTask
+void shutdown_handler(int sig)
{
-public:
- SignalTask() : OsTask() {}
-
- int
- run(void *pArg)
- {
- int sig_num ;
- OsStatus res ;
-
- // Wait for a signal. This will unblock signals
- // for THIS thread only, so this will be the only thread
- // to catch an async signal directed to the process
- // from the outside.
- res = awaitSignal(sig_num);
- if (res == OS_SUCCESS)
- {
- if (SIGTERM == sig_num)
- {
- OsSysLog::add( LOG_FACILITY, PRI_INFO, "SignalTask: terminate signal received.");
- }
- else
- {
- OsSysLog::add( LOG_FACILITY, PRI_CRIT, "SignalTask: caught signal: %d", sig_num );
- }
- }
- else
- {
- OsSysLog::add( LOG_FACILITY, PRI_CRIT, "SignalTask: awaitSignal() failed");
- }
- // set the global shutdown flag
- gShutdownFlag = TRUE ;
- return 0 ;
- }
-} ;
+ OsSysLog::add(LOG_FACILITY, PRI_INFO, "main: terminate signal received. %d", sig);
+ // set the global shutdown flag
+ gShutdownFlag = TRUE ;
+}
/** The main entry point to the sipregistrar */
int
main(int argc, char* argv[] )
-{
- // Block all signals in this the main thread.
- // Any threads created from now on will have all signals masked.
- OsTask::blockSignals();
-
- // Create a new task to wait for signals. Only that task
- // will ever see a signal from the outside.
- SignalTask* signalTask = new SignalTask();
- signalTask->start();
-
+{
// Configuration Database (used for OsSysLog)
OsConfigDb* configDb = new OsConfigDb();
@@ -303,7 +264,9 @@ main(int argc, char* argv[] )
pServerTask = static_cast<OsServerTask*>(registrar);
// Do not exit, let the services run...
- while( !gShutdownFlag && !pServerTask->isShutDown() )
+ OsSysLog::add(LOG_FACILITY, PRI_DEBUG, "main: registering shutdown handler.");
+ signal(SIGTERM, shutdown_handler);
+ while( !gShutdownFlag && !pServerTask->isShutDown() )
{
OsTask::delay(1 * OsTime::MSECS_PER_SEC);
}
_______________________________________________
sipx-dev mailing list
[email protected]
List Archive: http://list.sipfoundry.org/archive/sipx-dev/