From b5973a25a6fa99115556acaa7dcb78b75cf8fa03 Mon Sep 17 00:00:00 2001 From: rahuel Date: Thu, 9 Dec 2004 13:37:06 +0000 Subject: [PATCH] Some debugs about pthread_cancel/Kill_impl() to reset correctly _ThreadId field in case of signal (SIGSEGV, etc...) --- src/Container/Component_i.cxx | 42 ++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/Container/Component_i.cxx b/src/Container/Component_i.cxx index b83598b23..381dedd2e 100644 --- a/src/Container/Component_i.cxx +++ b/src/Container/Component_i.cxx @@ -205,7 +205,7 @@ void Engines_Component_i::beginService(const char *serviceName) // --- for supervisor : all strings given with setProperties // are set in environment - bool overwrite = true; +// bool overwrite = true; map::iterator it; for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++) { @@ -219,7 +219,7 @@ void Engines_Component_i::beginService(const char *serviceName) s+='='; s+=value; //char* cast because 1st arg of linux putenv function is not a const char* !!! - int ret=putenv((char *)s.c_str()); + putenv((char *)s.c_str()); //End of CCRT porting //int ret = setenv(cle.c_str(), value, overwrite); MESSAGE("--- setenv: "< 0 ) { if ( signum == 0 ) { - if ( pthread_cancel( ThreadId ) ) { - perror("Killer pthread_cancel error") ; + int sts = pthread_cancel( ThreadId ) ; + if ( sts != 0 && sts != ESRCH ) { + perror("perror Killer pthread_cancel error") ; + cout << pthread_self() << "Killer : ThreadId " << ThreadId << " sts " << sts + << " errno " << errno << endl ; return false ; } else { - MESSAGE(pthread_self() << "Killer : ThreadId " << ThreadId << " pthread_canceled") ; + cout << pthread_self() << "Killer : ThreadId " << ThreadId << " pthread_canceled" << endl ; } } else { @@ -298,16 +301,21 @@ bool Engines_Component_i::Killer( pthread_t ThreadId , int signum ) { } } } + else { + return false ; + } return true ; } bool Engines_Component_i::Kill_impl() { - MESSAGE( "Engines_Component_i::Kill_impl() pthread_t "<< pthread_self() - << " _ThreadId " << _ThreadId << endl ) ; + cout << "Engines_Component_i::Kill_impl() pthread_t "<< pthread_self() + << " _ThreadId " << _ThreadId << " errno " << errno << endl ; bool RetVal = false ; - if ( _ThreadId > 0 && pthread_self() != _ThreadId ) { - RetVal = Killer( _ThreadId , 0 ) ; - _ThreadId = (pthread_t ) -1 ; + if ( _ThreadId > 0 ) { + if ( pthread_self() != _ThreadId ) { // Do not kill myself ... + RetVal = Killer( _ThreadId , 0 ) ; + } + _ThreadId = 0 ; } return RetVal ; } @@ -316,9 +324,11 @@ bool Engines_Component_i::Stop_impl() { MESSAGE( "Engines_Component_i::Stop_impl() pthread_t "<< pthread_self() << " _ThreadId " << _ThreadId << endl ) ; bool RetVal = false ; - if ( _ThreadId > 0 && pthread_self() != _ThreadId ) { - RetVal = Killer( _ThreadId , 0 ) ; - _ThreadId = (pthread_t ) -1 ; + if ( _ThreadId > 0 ) { + if ( pthread_self() != _ThreadId ) { // Do not kill myself ... + RetVal = Killer( _ThreadId , 0 ) ; + } + _ThreadId = 0 ; } return RetVal ; } -- 2.39.2