Commit 46ebb465 authored by Pavel Vainerman's avatar Pavel Vainerman

(UniSetActivator): исправил SIGSEGV при завершении процесса.

Добавил signal_terminate_event(), чтобы можно было подключаться к сигналу и завершать работу (сторонним потокам).
parent 8a390c1d
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<AutoStartUpTime name="1"/> <AutoStartUpTime name="1"/>
<DumpStateTime name="10"/> <DumpStateTime name="10"/>
<SleepTickMS name="500"/> <SleepTickMS name="500"/>
<UniSetDebug levels="crit,warn" name="ulog"/> <UniSetDebug levels="" name="ulog"/>
<ConfDir name="./"/> <ConfDir name="./"/>
<DataDir name="./"/> <DataDir name="./"/>
<BinDir name="./"/> <BinDir name="./"/>
......
...@@ -264,7 +264,7 @@ CORBA::Boolean SharedMemory::exist() ...@@ -264,7 +264,7 @@ CORBA::Boolean SharedMemory::exist()
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void SharedMemory::sigterm( int signo ) void SharedMemory::sigterm( int signo )
{ {
if( signo == SIGTERM ) if( signo == SIGTERM && wdt )
wdt->stop(); wdt->stop();
// raise(SIGKILL); // raise(SIGKILL);
IONotifyController_LT::sigterm(signo); IONotifyController_LT::sigterm(signo);
......
...@@ -27,7 +27,26 @@ const unsigned int MaxAddNum = 10; ...@@ -27,7 +27,26 @@ const unsigned int MaxAddNum = 10;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
static void help_print( int argc, const char* argv[] ); static void help_print( int argc, const char* argv[] );
static LogServer* run_logserver( const std::string& cnamem, DebugStream& log ); static LogServer* run_logserver( const std::string& cnamem, DebugStream& log );
static LogServer* logserver = 0;
#ifdef UNISET_ENABLE_IO
std::list< ThreadCreator<IOControl>* > lst_iothr;
#endif
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
void activator_terminate( int signo )
{
if( logserver )
{
delete logserver;
logserver = 0;
}
#ifdef UNISET_IO_ENABLE
for( auto& i: lst_iothr )
i->stop();
#endif
}
// --------------------------------------------------------------------------
int main( int argc, const char **argv ) int main( int argc, const char **argv )
{ {
if( argc>1 && ( strcmp(argv[1],"--help")==0 || strcmp(argv[1],"-h")==0 ) ) if( argc>1 && ( strcmp(argv[1],"--help")==0 || strcmp(argv[1],"-h")==0 ) )
...@@ -48,6 +67,7 @@ int main( int argc, const char **argv ) ...@@ -48,6 +67,7 @@ int main( int argc, const char **argv )
conf->initDebug(UniSetExtensions::dlog,"dlog"); conf->initDebug(UniSetExtensions::dlog,"dlog");
UniSetActivator* act = UniSetActivator::Instance(); UniSetActivator* act = UniSetActivator::Instance();
act->signal_terminate_event().connect( &activator_terminate );
// ------------ SharedMemory ---------------- // ------------ SharedMemory ----------------
SharedMemory* shm = SharedMemory::init_smemory(argc,argv); SharedMemory* shm = SharedMemory::init_smemory(argc,argv);
if( shm == NULL ) if( shm == NULL )
...@@ -57,7 +77,7 @@ int main( int argc, const char **argv ) ...@@ -57,7 +77,7 @@ int main( int argc, const char **argv )
#ifdef UNISET_ENABLE_IO #ifdef UNISET_ENABLE_IO
// ------------ IOControl ---------------- // ------------ IOControl ----------------
std::list< ThreadCreator<IOControl>* > lst_iothr; // std::list< ThreadCreator<IOControl>* > lst_iothr;
for( unsigned int i=0; i<MaxAddNum; i++ ) for( unsigned int i=0; i<MaxAddNum; i++ )
{ {
stringstream s; stringstream s;
...@@ -183,23 +203,25 @@ int main( int argc, const char **argv ) ...@@ -183,23 +203,25 @@ int main( int argc, const char **argv )
act->broadcast( sm.transport_msg() ); act->broadcast( sm.transport_msg() );
#ifdef UNISET_IO_ENABLE #ifdef UNISET_IO_ENABLE
for( std::list< ThreadCreator<IOControl>* >::iterator it=lst_iothr.begin(); it!=lst_iothr.end(); ++it ) for( auto& i: lst_iothr )
(*it)->start(); i->start();
#endif #endif
LogAgregator la; LogAgregator la;
la.add(ulog); la.add(ulog);
la.add(dlog); la.add(dlog);
if( run_logserver("smplus",la) == 0 ) #if 0
logserver = run_logserver("smplus",la);
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);
return 0; return 0;
} }
catch(Exception& ex) catch(Exception& ex)
...@@ -293,6 +315,7 @@ LogServer* run_logserver( const std::string& cname, DebugStream& log ) ...@@ -293,6 +315,7 @@ LogServer* run_logserver( const std::string& cname, DebugStream& log )
return 0; return 0;
} }
cout << "logserver: " << host << ":" << port << endl;
ls->run(host, port, true); ls->run(host, port, true);
return ls; return ls;
} }
......
...@@ -30,8 +30,8 @@ ${START} -f ./uniset2-smemory-plus --smemory-id SharedMemory --confile test.xml ...@@ -30,8 +30,8 @@ ${START} -f ./uniset2-smemory-plus --smemory-id SharedMemory --confile test.xml
--mbtcp2-gateway-port 2049 \ --mbtcp2-gateway-port 2049 \
--mbtcp2-recv-timeout 200 \ --mbtcp2-recv-timeout 200 \
--mbtcp2-force-out 1 \ --mbtcp2-force-out 1 \
# --dlog-add-levels any \ --ulog-add-levels system \
# $* $*
# --add-rtu \ # --add-rtu \
# --rs-dev /dev/cbsideA1 \ # --rs-dev /dev/cbsideA1 \
# --rs-id RTUExchange \ # --rs-id RTUExchange \
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#include <deque> #include <deque>
#include <omniORB4/CORBA.h> #include <omniORB4/CORBA.h>
#include <cc++/socket.h>
#include "UniSetTypes.h" #include "UniSetTypes.h"
#include "UniSetObject.h" #include "UniSetObject.h"
#include "UniSetManager.h" #include "UniSetManager.h"
...@@ -67,6 +68,9 @@ class UniSetActivator: ...@@ -67,6 +68,9 @@ class UniSetActivator:
virtual UniSetTypes::ObjectType getType() override { return UniSetTypes::ObjectType("UniSetActivator"); } virtual UniSetTypes::ObjectType getType() override { return UniSetTypes::ObjectType("UniSetActivator"); }
typedef sigc::signal<void,int> TerminateEvent_Signal;
TerminateEvent_Signal signal_terminate_event();
protected: protected:
/*! Команды доступные при заказе сигналов /*! Команды доступные при заказе сигналов
...@@ -118,6 +122,7 @@ class UniSetActivator: ...@@ -118,6 +122,7 @@ class UniSetActivator:
ThreadCreator<UniSetActivator> *orbthr; ThreadCreator<UniSetActivator> *orbthr;
CORBA::ORB_var orb; CORBA::ORB_var orb;
TerminateEvent_Signal s_term;
bool omDestroy; bool omDestroy;
bool sig; bool sig;
......
...@@ -77,7 +77,7 @@ class UniSetManager: ...@@ -77,7 +77,7 @@ class UniSetManager:
virtual bool addManager( UniSetManager *mngr ); virtual bool addManager( UniSetManager *mngr );
virtual bool removeManager( UniSetManager *mngr ); virtual bool removeManager( UniSetManager *mngr );
/*! Получение доступа к подчиненному менеджеру по идентификатору /*! Получение доступа к подчиненному менеджеру по идентификатору
* \return объект ненайден будет возвращен 0. * \return объект ненайден будет возвращен 0.
*/ */
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
class WDTInterface class WDTInterface
{ {
public: public:
WDTInterface(const std::string& dev); WDTInterface( const std::string& dev );
~WDTInterface(); ~WDTInterface();
bool ping(); bool ping();
......
...@@ -225,10 +225,10 @@ const ObjectInfo* ObjectIndex_idXML::getObjectInfo( const ObjectId id ) ...@@ -225,10 +225,10 @@ const ObjectInfo* ObjectIndex_idXML::getObjectInfo( const ObjectId id )
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
const ObjectInfo* ObjectIndex_idXML::getObjectInfo( const std::string& name ) const ObjectInfo* ObjectIndex_idXML::getObjectInfo( const std::string& name )
{ {
auto it = mok.find(name); auto it = mok.find(name);
if( it != mok.end() ) if( it != mok.end() )
return getObjectInfo(it->second); return getObjectInfo(it->second);
return NULL; return NULL;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
...@@ -48,7 +48,7 @@ using namespace std; ...@@ -48,7 +48,7 @@ using namespace std;
В этом обработчике происходит вызов UniSetActivator::oaDestroy(int signo) для фактического В этом обработчике происходит вызов UniSetActivator::oaDestroy(int signo) для фактического
завершения работы и заказывается сигнал SIG_ALRM на время TERMINATE_TIMEOUT, завершения работы и заказывается сигнал SIG_ALRM на время TERMINATE_TIMEOUT,
c обработчиком UniSetActivator::finishterm в котором происходит c обработчиком UniSetActivator::finishterm в котором происходит
"надежное" прибивание текущего процесса (raise(SIGKILL)). Это сделано на тот случай, если "надежное" прибивание текущего процесса (kill(getpid(),SIGKILL)). Это сделано на тот случай, если
в oaDestroy произойдет зависание. в oaDestroy произойдет зависание.
*/ */
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
...@@ -140,7 +140,7 @@ void UniSetActivator::init() ...@@ -140,7 +140,7 @@ void UniSetActivator::init()
UniSetActivator::~UniSetActivator() UniSetActivator::~UniSetActivator()
{ {
if(!procterm ) if( !procterm )
{ {
ulogsys << myname << "(destructor): ..."<< endl << flush; ulogsys << myname << "(destructor): ..."<< endl << flush;
if( !omDestroy ) if( !omDestroy )
...@@ -153,7 +153,27 @@ UniSetActivator::~UniSetActivator() ...@@ -153,7 +153,27 @@ UniSetActivator::~UniSetActivator()
} }
if( orbthr ) if( orbthr )
{
orbthr->stop();
if( orbthr->isRunning() )
orbthr->join();
delete orbthr; delete orbthr;
orbthr = 0;
}
#if 0
try
{
if( !CORBA::is_nil(orb) )
{
ulogsys << myname << "(oaDestroy): orb destroy... " << endl;
orb->destroy();
ulogsys << myname << "(oaDestroy): orb destroy ok."<< endl;
}
}
catch(...){}
#endif
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
...@@ -170,30 +190,62 @@ void UniSetActivator::oaDestroy(int signo) ...@@ -170,30 +190,62 @@ void UniSetActivator::oaDestroy(int signo)
ulogsys << myname << "(oaDestroy): terminate ok. " << endl; ulogsys << myname << "(oaDestroy): terminate ok. " << endl;
try try
{ {
stop(); stop();
} }
catch(...){} catch(...){}
try
{
deactivateObject();
}
catch(...){}
ulogsys << myname << "(oaDestroy): pman deactivate... " << endl; ulogsys << myname << "(oaDestroy): pman deactivate... " << endl;
pman->deactivate(false,true); pman->deactivate(false,true);
ulogsys << myname << "(oaDestroy): pman deactivate ok. " << endl; ulogsys << myname << "(oaDestroy): pman deactivate ok. " << endl;
ulogsys << myname << "(oaDestroy): orb destroy... " << endl; ulogsys << myname << "(oaDestroy): orbthr=" << orbthr << endl;
try if( orbthr )
{ {
orb->destroy(); ulogsys << myname << "(oaDestroy): orb thread stop... " << endl;
orbthr->stop();
if( orbthr->isRunning() )
orbthr->join();
ulogsys << myname << "(oaDestroy): orb thread stop ok. " << endl;
} }
catch(...){}
ulogsys << myname << "(oaDestroy): orb destroy ok."<< endl; try
{
ulogsys << myname << "(stop):: shutdown orb... "<<endl;
orb->shutdown(false);
}
catch(...){}
ulogsys << myname << "(stop): shutdown ok."<< endl;
#if 0
try
{
if( !CORBA::is_nil(orb) )
{
ulogsys << myname << "(oaDestroy): orb destroy... " << endl;
orb->destroy();
ulogsys << myname << "(oaDestroy): orb destroy ok."<< endl;
}
}
catch(...){}
#endif
/*
if( orbthr ) if( orbthr )
{ {
delete orbthr; delete orbthr;
orbthr = 0; orbthr = 0;
} }
*/
} }
// waittermMutex.unlock(); // waittermMutex.unlock();
} }
...@@ -225,7 +277,7 @@ void UniSetActivator::run(bool thread) ...@@ -225,7 +277,7 @@ void UniSetActivator::run(bool thread)
pman->activate(); pman->activate();
msleep(50); msleep(50);
set_signals(true); set_signals(true);
if( thread ) if( thread )
{ {
uinfo << myname << "(run): запускаемся с созданием отдельного потока... "<< endl; uinfo << myname << "(run): запускаемся с созданием отдельного потока... "<< endl;
...@@ -266,16 +318,15 @@ void UniSetActivator::stop() ...@@ -266,16 +318,15 @@ void UniSetActivator::stop()
ulogsys << myname << "(stop): discard request ok."<< endl; ulogsys << myname << "(stop): discard request ok."<< endl;
/* #if 1
try try
{ {
ulogsys << myname << "(stop):: shutdown orb... "<<endl; ulogsys << myname << "(stop):: shutdown orb... "<<endl;
orb->shutdown(false); orb->shutdown(true);
} }
catch(...){} catch(...){}
ulogsys << myname << "(stop): shutdown ok."<< endl; ulogsys << myname << "(stop): shutdown ok."<< endl;
*/ #endif
} }
} }
...@@ -283,7 +334,7 @@ void UniSetActivator::stop() ...@@ -283,7 +334,7 @@ void UniSetActivator::stop()
void UniSetActivator::work() void UniSetActivator::work()
{ {
ulogsys << myname << "(work): запускаем orb на обработку запросов..."<< endl; ulogsys << myname << "(work): запускаем orb на обработку запросов...(orbthr=" << orbthr << ")" << endl;
try try
{ {
if( orbthr ) if( orbthr )
...@@ -313,17 +364,17 @@ void UniSetActivator::work() ...@@ -313,17 +364,17 @@ void UniSetActivator::work()
ucrit << myname << "(work): catch ..." << endl; ucrit << myname << "(work): catch ..." << endl;
} }
ulogsys << myname << "(work): orb стоп!!!"<< endl; ulogsys << myname << "(work): orb thread stopped!" << endl;
/*
ulogsys << myname << "(oaDestroy): orb destroy... " << endl; ulogsys << myname << "(oaDestroy): orb destroy... " << endl;
try try
{ {
orb->destroy(); orb->destroy();
} }
catch(...){} catch(...){}
ulogsys << myname << "(oaDestroy): orb destroy ok."<< endl; ulogsys << myname << "(oaDestroy): orb destroy ok."<< endl;
*/
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void UniSetActivator::getinfo() void UniSetActivator::getinfo()
...@@ -364,18 +415,8 @@ void UniSetActivator::sysCommand( const UniSetTypes::SystemMessage *sm ) ...@@ -364,18 +415,8 @@ void UniSetActivator::sysCommand( const UniSetTypes::SystemMessage *sm )
} }
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
/*
void UniSetActivator::sig_child(int signo)
{
ulogsys << gActivator->getName() << "(sig_child): дочерний процесс закончил работу...(sig=" << signo << ")" << endl;
while( waitpid(-1, 0, WNOHANG) > 0);
}
*/
// ------------------------------------------------------------------------------------------
void UniSetActivator::set_signals(bool ask) void UniSetActivator::set_signals(bool ask)
{ {
struct sigaction act, oact; struct sigaction act, oact;
sigemptyset(&act.sa_mask); sigemptyset(&act.sa_mask);
sigemptyset(&oact.sa_mask); sigemptyset(&oact.sa_mask);
...@@ -397,7 +438,7 @@ void UniSetActivator::set_signals(bool ask) ...@@ -397,7 +438,7 @@ void UniSetActivator::set_signals(bool ask)
act.sa_handler = terminated; act.sa_handler = terminated;
else else
act.sa_handler = SIG_DFL; act.sa_handler = SIG_DFL;
sigaction(SIGINT, &act, &oact); sigaction(SIGINT, &act, &oact);
sigaction(SIGTERM, &act, &oact); sigaction(SIGTERM, &act, &oact);
sigaction(SIGABRT, &act, &oact); sigaction(SIGABRT, &act, &oact);
...@@ -419,10 +460,15 @@ void UniSetActivator::finishterm( int signo ) ...@@ -419,10 +460,15 @@ void UniSetActivator::finishterm( int signo )
sigset(SIGALRM, SIG_DFL); sigset(SIGALRM, SIG_DFL);
doneterm = 1; doneterm = 1;
raise(SIGKILL); kill(getpid(),SIGKILL);
} }
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
UniSetActivator::TerminateEvent_Signal UniSetActivator::signal_terminate_event()
{
return s_term;
}
// ------------------------------------------------------------------------------------------
void UniSetActivator::terminated( int signo ) void UniSetActivator::terminated( int signo )
{ {
if( !signo || doneterm || !gActivator || procterm ) if( !signo || doneterm || !gActivator || procterm )
...@@ -447,17 +493,24 @@ void UniSetActivator::terminated( int signo ) ...@@ -447,17 +493,24 @@ void UniSetActivator::terminated( int signo )
alarm(TERMINATE_TIMEOUT); alarm(TERMINATE_TIMEOUT);
sigrelse(SIGALRM); sigrelse(SIGALRM);
if( gActivator ) if( gActivator )
{
ulogsys << ( gActivator ? gActivator->getName() : "" ) << "(terminated): call oaDestroy.." << endl;
gActivator->oaDestroy(SIGNO); // gActivator->term(SIGNO); gActivator->oaDestroy(SIGNO); // gActivator->term(SIGNO);
}
doneterm = 1; doneterm = 1;
ulogsys << ( gActivator ? gActivator->getName() : "" ) << "(terminated): завершаемся..."<< endl<< flush; ulogsys << ( gActivator ? gActivator->getName() : "" ) << "(terminated): завершаемся..."<< endl<< flush;
if( gActivator ) if( gActivator )
{
UniSetActivator::set_signals(false); UniSetActivator::set_signals(false);
delete gActivator;
gActivator = 0;
}
sigset(SIGALRM, SIG_DFL); sigset(SIGALRM, SIG_DFL);
raise(SIGNO); kill(getpid(), SIGNO );
} }
} }
} }
...@@ -490,7 +543,7 @@ void UniSetActivator::term( int signo ) ...@@ -490,7 +543,7 @@ void UniSetActivator::term( int signo )
{ {
ulogsys << myname << "(term): вызываем sigterm()" << endl; ulogsys << myname << "(term): вызываем sigterm()" << endl;
sigterm(signo); sigterm(signo);
s_term.emit(signo);
ulogsys << myname << "(term): sigterm() ok." << endl; ulogsys << myname << "(term): sigterm() ok." << endl;
} }
catch(Exception& ex) catch(Exception& ex)
...@@ -506,7 +559,5 @@ void UniSetActivator::waitDestroy() ...@@ -506,7 +559,5 @@ void UniSetActivator::waitDestroy()
{ {
while( !doneterm && gActivator ) while( !doneterm && gActivator )
msleep(50); msleep(50);
gActivator = 0;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
...@@ -115,9 +115,16 @@ UniSetManager::~UniSetManager() ...@@ -115,9 +115,16 @@ UniSetManager::~UniSetManager()
catch(...){} catch(...){}
try try
{ {
managers(deactiv); managers(deactiv);
} }
catch(...){} catch(...){}
for( auto& i: olist )
delete i;
for( auto& i: mlist )
delete i;
olist.clear(); olist.clear();
mlist.clear(); mlist.clear();
} }
......
...@@ -621,7 +621,8 @@ bool UniSetObject::deactivate() ...@@ -621,7 +621,8 @@ bool UniSetObject::deactivate()
} }
setActive(false); // завершаем поток обработки сообщений setActive(false); // завершаем поток обработки сообщений
tmr->stop(); if( tmr )
tmr->stop();
// Очищаем очередь // Очищаем очередь
{ // lock { // lock
......
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