Commit 7e0f414b authored by Pavel Vainerman's avatar Pavel Vainerman

(SmemoryPlus): Решение проблеммы с "FATAL: exception not rethrown".

Заодно немного переформатировал код.
parent 46ebb465
...@@ -165,13 +165,19 @@ MBExchange::~MBExchange() ...@@ -165,13 +165,19 @@ MBExchange::~MBExchange()
{ {
if( it1->second->rtu ) if( it1->second->rtu )
{ {
try {
delete it1->second->rtu; delete it1->second->rtu;
it1->second->rtu = 0; it1->second->rtu = 0;
}catch(...){}
} }
RTUDevice* d(it1->second); RTUDevice* d(it1->second);
for( auto it=d->regmap.begin(); it!=d->regmap.end(); ++it ) for( auto it=d->regmap.begin(); it!=d->regmap.end(); ++it )
{
try {
delete it->second; delete it->second;
}catch(...){}
}
delete it1->second; delete it1->second;
} }
...@@ -193,6 +199,7 @@ void MBExchange::waitSMReady() ...@@ -193,6 +199,7 @@ void MBExchange::waitSMReady()
ostringstream err; ostringstream err;
err << myname << "(waitSMReady): failed waiting SharedMemory " << ready_timeout << " msec"; err << myname << "(waitSMReady): failed waiting SharedMemory " << ready_timeout << " msec";
dcrit << err.str() << endl; dcrit << err.str() << endl;
if( checkProcActive() )
throw SystemError(err.str()); throw SystemError(err.str());
} }
} }
...@@ -233,7 +240,15 @@ void MBExchange::sigterm( int signo ) ...@@ -233,7 +240,15 @@ void MBExchange::sigterm( int signo )
{ {
dwarn << myname << ": ********* SIGTERM(" << signo << ") ********" << endl; dwarn << myname << ": ********* SIGTERM(" << signo << ") ********" << endl;
setProcActive(false); setProcActive(false);
try
{
UniSetObject_LT::sigterm(signo); UniSetObject_LT::sigterm(signo);
}
catch( ... )
{
// std::exception_ptr p = std::current_exception();
// std::clog <<(p ? p.__cxa_exception_type()->name() : "null") << std::endl;
}
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void MBExchange::readConfiguration() void MBExchange::readConfiguration()
...@@ -2580,7 +2595,8 @@ void MBExchange::askSensors( UniversalIO::UIOCommand cmd ) ...@@ -2580,7 +2595,8 @@ void MBExchange::askSensors( UniversalIO::UIOCommand cmd )
dcrit << err.str() << endl; dcrit << err.str() << endl;
kill(SIGTERM,getpid()); // прерываем (перезапускаем) процесс... kill(SIGTERM,getpid()); // прерываем (перезапускаем) процесс...
throw SystemError(err.str()); // throw SystemError(err.str());
return;
} }
try try
......
...@@ -75,6 +75,12 @@ pollThread(0) ...@@ -75,6 +75,12 @@ pollThread(0)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
MBTCPMaster::~MBTCPMaster() MBTCPMaster::~MBTCPMaster()
{ {
if( pollThread )
{
pollThread->stop();
if( pollThread->isRunning() )
pollThread->join();
}
delete pollThread; delete pollThread;
//delete mbtcp; //delete mbtcp;
} }
...@@ -146,12 +152,20 @@ void MBTCPMaster::poll_thread() ...@@ -146,12 +152,20 @@ void MBTCPMaster::poll_thread()
if( sidExchangeMode != DefaultObjectId && force ) if( sidExchangeMode != DefaultObjectId && force )
exchangeMode = shm->localGetValue(itExchangeMode,sidExchangeMode); exchangeMode = shm->localGetValue(itExchangeMode,sidExchangeMode);
} }
catch(...){} catch(...)
{
throw;
}
try try
{ {
poll(); poll();
} }
catch(...){} catch(...)
{
// if( !checkProcActive() )
throw;
}
if( !checkProcActive() ) if( !checkProcActive() )
break; break;
...@@ -160,6 +174,36 @@ void MBTCPMaster::poll_thread() ...@@ -160,6 +174,36 @@ void MBTCPMaster::poll_thread()
} }
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void MBTCPMaster::sigterm( int signo )
{
setProcActive(false);
if( pollThread )
{
pollThread->stop();
if( pollThread->isRunning() )
pollThread->join();
delete pollThread;
pollThread = 0;
}
try
{
MBExchange::sigterm(signo);
}
catch( const std::exception& ex )
{
cerr << "catch: " << ex.what() << endl;
}
catch( ... )
{
std::exception_ptr p = std::current_exception();
std::clog <<(p ? p.__cxa_exception_type()->name() : "null") << std::endl;
}
}
// -----------------------------------------------------------------------------
void MBTCPMaster::help_print( int argc, const char* const* argv ) void MBTCPMaster::help_print( int argc, const char* const* argv )
{ {
cout << "Default: prefix='mbtcp'" << endl; cout << "Default: prefix='mbtcp'" << endl;
......
...@@ -208,6 +208,7 @@ class MBTCPMaster: ...@@ -208,6 +208,7 @@ class MBTCPMaster:
protected: protected:
virtual void sysCommand( const UniSetTypes::SystemMessage *sm ) override; virtual void sysCommand( const UniSetTypes::SystemMessage *sm ) override;
virtual std::shared_ptr<ModbusClient> initMB( bool reopen=false ) override; virtual std::shared_ptr<ModbusClient> initMB( bool reopen=false ) override;
virtual void sigterm( int signo ) override;
UniSetTypes::uniset_rwmutex mbMutex; UniSetTypes::uniset_rwmutex mbMutex;
std::string iaddr; std::string iaddr;
......
...@@ -78,6 +78,9 @@ int main( int argc, const char** argv ) ...@@ -78,6 +78,9 @@ int main( int argc, const char** argv )
} }
catch(...) catch(...)
{ {
std::exception_ptr p = std::current_exception();
std::clog <<(p ? p.__cxa_exception_type()->name() : "null") << std::endl;
dcrit << "(mbtcpmaster): catch ..." << std::endl; dcrit << "(mbtcpmaster): catch ..." << std::endl;
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
--confile test.xml \ --confile test.xml \
--mbtcp-name MBMaster1 \ --mbtcp-name MBMaster1 \
--smemory-id SharedMemory \ --smemory-id SharedMemory \
--dlog-add-levels info,crit,warn,level4,level3 \ --dlog-add-levels system,info,crit,warn,level4,level3 \
--mbtcp-set-prop-prefix \ --mbtcp-set-prop-prefix \
--mbtcp-filter-field rs \ --mbtcp-filter-field rs \
--mbtcp-filter-value 5 \ --mbtcp-filter-value 5 \
......
...@@ -36,13 +36,23 @@ void activator_terminate( int signo ) ...@@ -36,13 +36,23 @@ void activator_terminate( int signo )
{ {
if( logserver ) if( logserver )
{ {
try
{
delete logserver; delete logserver;
logserver = 0; logserver = 0;
} }
catch(...){}
}
#ifdef UNISET_IO_ENABLE #ifdef UNISET_IO_ENABLE
for( auto& i: lst_iothr ) for( auto& i: lst_iothr )
{
try
{
i->stop(); i->stop();
}
catch(...){}
}
#endif #endif
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -211,14 +221,13 @@ int main( int argc, const char **argv ) ...@@ -211,14 +221,13 @@ int main( int argc, const char **argv )
la.add(ulog); la.add(ulog);
la.add(dlog); la.add(dlog);
#if 0
logserver = run_logserver("smplus",la); logserver = run_logserver("smplus",la);
if( logserver == 0 ) if( logserver == 0 )
{ {
cerr << "(smemory-plus): run logserver for 'smplus' FAILED" << endl; cerr << "(smemory-plus): run logserver for 'smplus' FAILED" << endl;
return 1; return 1;
} }
#endif
act->run(false); act->run(false);
on_sigchild(SIGTERM); on_sigchild(SIGTERM);
......
...@@ -177,9 +177,8 @@ template <class ThreadMaster> ...@@ -177,9 +177,8 @@ template <class ThreadMaster>
void ThreadCreator<ThreadMaster>::run() void ThreadCreator<ThreadMaster>::run()
{ {
pid = getpid(); pid = getpid();
if(m) if( m )
(m->*act)(); (m->*act)();
// PosixThread::stop()
} }
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
template <class ThreadMaster> template <class ThreadMaster>
......
...@@ -191,8 +191,6 @@ void UniSetActivator::oaDestroy(int signo) ...@@ -191,8 +191,6 @@ void UniSetActivator::oaDestroy(int signo)
try try
{ {
stop(); stop();
} }
catch(...){} catch(...){}
...@@ -210,6 +208,8 @@ void UniSetActivator::oaDestroy(int signo) ...@@ -210,6 +208,8 @@ void UniSetActivator::oaDestroy(int signo)
ulogsys << myname << "(oaDestroy): orbthr=" << orbthr << endl; ulogsys << myname << "(oaDestroy): orbthr=" << orbthr << endl;
if( orbthr ) if( orbthr )
{ {
try
{
ulogsys << myname << "(oaDestroy): orb thread stop... " << endl; ulogsys << myname << "(oaDestroy): orb thread stop... " << endl;
orbthr->stop(); orbthr->stop();
...@@ -218,6 +218,8 @@ void UniSetActivator::oaDestroy(int signo) ...@@ -218,6 +218,8 @@ void UniSetActivator::oaDestroy(int signo)
ulogsys << myname << "(oaDestroy): orb thread stop ok. " << endl; ulogsys << myname << "(oaDestroy): orb thread stop ok. " << endl;
} }
catch(...){}
}
try try
{ {
...@@ -520,6 +522,9 @@ void UniSetActivator::normalexit() ...@@ -520,6 +522,9 @@ void UniSetActivator::normalexit()
{ {
if( gActivator ) if( gActivator )
ulogsys << gActivator->getName() << "(default exit): good bye."<< endl << flush; ulogsys << gActivator->getName() << "(default exit): good bye."<< endl << flush;
// std::exception_ptr p = std::current_exception();
// std::clog <<(p ? p.__cxa_exception_type()->name() : "null") << std::endl;
} }
void UniSetActivator::normalterminate() void UniSetActivator::normalterminate()
...@@ -527,6 +532,9 @@ void UniSetActivator::normalterminate() ...@@ -527,6 +532,9 @@ void UniSetActivator::normalterminate()
if( gActivator ) if( gActivator )
ucrit << gActivator->getName() << "(default exception terminate): Никто не выловил исключение!!! Good bye."<< endl<< flush; ucrit << gActivator->getName() << "(default exception terminate): Никто не выловил исключение!!! Good bye."<< endl<< flush;
// abort(); // abort();
// std::exception_ptr p = std::current_exception();
// std::clog <<(p ? p.__cxa_exception_type()->name() : "null") << std::endl;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void UniSetActivator::term( int signo ) void UniSetActivator::term( int signo )
......
...@@ -120,10 +120,22 @@ UniSetManager::~UniSetManager() ...@@ -120,10 +120,22 @@ UniSetManager::~UniSetManager()
catch(...){} catch(...){}
for( auto& i: olist ) for( auto& i: olist )
{
try
{
delete i; delete i;
}
catch(...){}
}
for( auto& i: mlist ) for( auto& i: mlist )
{
try
{
delete i; delete i;
}
catch(...){}
}
olist.clear(); olist.clear();
mlist.clear(); mlist.clear();
...@@ -357,8 +369,18 @@ bool UniSetManager::deactivateObject() ...@@ -357,8 +369,18 @@ bool UniSetManager::deactivateObject()
void UniSetManager::sigterm( int signo ) void UniSetManager::sigterm( int signo )
{ {
sig=signo; sig=signo;
try
{
objects(term); objects(term);
}
catch(...){}
try
{
managers(term); managers(term);
}
catch(...){}
UniSetObject::sigterm(signo); UniSetObject::sigterm(signo);
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
......
...@@ -134,16 +134,27 @@ stCountOfQueueFull(0) ...@@ -134,16 +134,27 @@ stCountOfQueueFull(0)
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
UniSetObject::~UniSetObject() UniSetObject::~UniSetObject()
{ {
try
{
deactivate(); deactivate();
}
catch(...){}
try
{
tmr->terminate(); tmr->terminate();
}
catch(...){}
if( thr ) if( thr )
{ {
try
{
thr->stop(); thr->stop();
if( thr->isRunning() ) if( thr->isRunning() )
thr->join(); thr->join();
}
catch(...){}
delete thr; delete thr;
} }
...@@ -817,10 +828,17 @@ void UniSetObject::processingMessage( UniSetTypes::VoidMessage *msg ) ...@@ -817,10 +828,17 @@ void UniSetObject::processingMessage( UniSetTypes::VoidMessage *msg )
<< " mesg: " << fe.errmsg() << endl; << " mesg: " << fe.errmsg() << endl;
} }
} }
catch(...) catch( const std::exception& ex )
{
ucrit << myname << "(processingMessage): " << ex.what() << endl;
}
/*
catch( ... )
{ {
ucrit << myname << "(processingMessage): catch..." << endl; std::exception_ptr p = std::current_exception();
ucrit <<(p ? p.__cxa_exception_type()->name() : "null") << std::endl;
} }
*/
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment