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

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

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