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

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

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