summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAGaliuzov <AGaliuzov@luxoft.com>2016-01-27 13:53:33 +0200
committerAGaliuzov <AGaliuzov@luxoft.com>2016-01-27 13:53:33 +0200
commit541359512c3cafca9c90dd72cd4d87e168cc9aed (patch)
tree7dd2f1d336b9165f1088e9e842d862b800e63d19
parentd24c645fea0b3a8d22d6d59b943f803073d4275b (diff)
parent05a70d837c03560eb3af5d56155d8d334ffc1b62 (diff)
downloadsdl_core-541359512c3cafca9c90dd72cd4d87e168cc9aed.tar.gz
Merge pull request #351 from LuxoftSDL/hotfix/SDL_crashes_during_start_if_preloaded_pt_file_is_absent
Hotfix/sdl crashes during start if preloaded pt file is absent
-rw-r--r--src/appMain/life_cycle.cc308
1 files changed, 173 insertions, 135 deletions
diff --git a/src/appMain/life_cycle.cc b/src/appMain/life_cycle.cc
index bf05b3e7fc..0efd61a5d6 100644
--- a/src/appMain/life_cycle.cc
+++ b/src/appMain/life_cycle.cc
@@ -59,64 +59,61 @@ void NameMessageBrokerThread(const System::Thread& thread,
} // namespace
LifeCycle::LifeCycle()
- : transport_manager_(NULL)
- , protocol_handler_(NULL)
- , connection_handler_(NULL)
- , app_manager_(NULL)
+ : transport_manager_(NULL)
+ , protocol_handler_(NULL)
+ , connection_handler_(NULL)
+ , app_manager_(NULL)
#ifdef ENABLE_SECURITY
- , crypto_manager_(NULL)
- , security_manager_(NULL)
+ , crypto_manager_(NULL)
+ , security_manager_(NULL)
#endif // ENABLE_SECURITY
- , hmi_handler_(NULL)
- , hmi_message_adapter_(NULL)
- , media_manager_(NULL)
+ , hmi_handler_(NULL)
+ , hmi_message_adapter_(NULL)
+ , media_manager_(NULL)
#ifdef TIME_TESTER
- , time_tester_(NULL)
+ , time_tester_(NULL)
#endif // TIME_TESTER
#ifdef DBUS_HMIADAPTER
- , dbus_adapter_(NULL)
- , dbus_adapter_thread_(NULL)
+ , dbus_adapter_(NULL)
+ , dbus_adapter_thread_(NULL)
#endif // DBUS_HMIADAPTER
#ifdef MESSAGEBROKER_HMIADAPTER
- , mb_adapter_(NULL)
- , message_broker_(NULL)
- , message_broker_server_(NULL)
- , mb_thread_(NULL)
- , mb_server_thread_(NULL)
- , mb_adapter_thread_(NULL)
+ , mb_adapter_(NULL)
+ , message_broker_(NULL)
+ , message_broker_server_(NULL)
+ , mb_thread_(NULL)
+ , mb_server_thread_(NULL)
+ , mb_adapter_thread_(NULL)
#endif // MESSAGEBROKER_HMIADAPTER
-{ }
+{
+}
bool LifeCycle::StartComponents() {
LOG4CXX_AUTO_TRACE(logger_);
- transport_manager_ =
- transport_manager::TransportManagerDefault::instance();
+ transport_manager_ = transport_manager::TransportManagerDefault::instance();
DCHECK(transport_manager_ != NULL);
- protocol_handler_ =
- new protocol_handler::ProtocolHandlerImpl(transport_manager_,
- profile::Profile::instance()->message_frequency_time(),
- profile::Profile::instance()->message_frequency_count(),
- profile::Profile::instance()->malformed_message_filtering(),
- profile::Profile::instance()->malformed_frequency_time(),
- profile::Profile::instance()->malformed_frequency_count(),
- profile::Profile::instance()->multiframe_waiting_timeout());
+ protocol_handler_ = new protocol_handler::ProtocolHandlerImpl(
+ transport_manager_,
+ profile::Profile::instance()->message_frequency_time(),
+ profile::Profile::instance()->message_frequency_count(),
+ profile::Profile::instance()->malformed_message_filtering(),
+ profile::Profile::instance()->malformed_frequency_time(),
+ profile::Profile::instance()->malformed_frequency_count(),
+ profile::Profile::instance()->multiframe_waiting_timeout());
DCHECK(protocol_handler_ != NULL);
- connection_handler_ =
- connection_handler::ConnectionHandlerImpl::instance();
+ connection_handler_ = connection_handler::ConnectionHandlerImpl::instance();
DCHECK(connection_handler_ != NULL);
- app_manager_ =
- application_manager::ApplicationManagerImpl::instance();
+ app_manager_ = application_manager::ApplicationManagerImpl::instance();
DCHECK(app_manager_ != NULL);
if (!app_manager_->Init()) {
LOG4CXX_ERROR(logger_, "Application manager init failed.");
return false;
}
- hmi_handler_ =
- hmi_message_handler::HMIMessageHandlerImpl::instance();
+ hmi_handler_ = hmi_message_handler::HMIMessageHandlerImpl::instance();
DCHECK(hmi_handler_ != NULL)
#ifdef ENABLE_SECURITY
@@ -125,29 +122,46 @@ bool LifeCycle::StartComponents() {
// FIXME(EZamakhov): move to Config or in Sm initialization method
std::string cert_filename;
profile::Profile::instance()->ReadStringValue(
- &cert_filename, "",
- security_manager::SecurityManagerImpl::ConfigSection(), "CertificatePath");
+ &cert_filename,
+ "",
+ security_manager::SecurityManagerImpl::ConfigSection(),
+ "CertificatePath");
std::string ssl_mode;
profile::Profile::instance()->ReadStringValue(
- &ssl_mode, "CLIENT", security_manager::SecurityManagerImpl::ConfigSection(), "SSLMode");
+ &ssl_mode,
+ "CLIENT",
+ security_manager::SecurityManagerImpl::ConfigSection(),
+ "SSLMode");
crypto_manager_ = new security_manager::CryptoManagerImpl();
std::string key_filename;
profile::Profile::instance()->ReadStringValue(
- &key_filename, "", security_manager::SecurityManagerImpl::ConfigSection(), "KeyPath");
+ &key_filename,
+ "",
+ security_manager::SecurityManagerImpl::ConfigSection(),
+ "KeyPath");
std::string ciphers_list;
profile::Profile::instance()->ReadStringValue(
- &ciphers_list, SSL_TXT_ALL, security_manager::SecurityManagerImpl::ConfigSection(), "CipherList");
+ &ciphers_list,
+ SSL_TXT_ALL,
+ security_manager::SecurityManagerImpl::ConfigSection(),
+ "CipherList");
bool verify_peer;
profile::Profile::instance()->ReadBoolValue(
- &verify_peer, false, security_manager::SecurityManagerImpl::ConfigSection(), "VerifyPeer");
+ &verify_peer,
+ false,
+ security_manager::SecurityManagerImpl::ConfigSection(),
+ "VerifyPeer");
std::string protocol_name;
profile::Profile::instance()->ReadStringValue(
- &protocol_name, "TLSv1.2", security_manager::SecurityManagerImpl::ConfigSection(), "Protocol");
+ &protocol_name,
+ "TLSv1.2",
+ security_manager::SecurityManagerImpl::ConfigSection(),
+ "Protocol");
security_manager::Protocol protocol;
if (protocol_name == "TLSv1.0") {
@@ -164,14 +178,14 @@ bool LifeCycle::StartComponents() {
}
if (!crypto_manager_->Init(
- ssl_mode == "SERVER" ? security_manager::SERVER : security_manager::CLIENT,
- protocol,
- policy::PolicyHandler::instance()->RetrieveCertificate(),
- profile::Profile::instance()->ciphers_list(),
- profile::Profile::instance()->verify_peer(),
- profile::Profile::instance()->ca_cert_path(),
- profile::Profile::instance()->update_before_hours())
- ) {
+ ssl_mode == "SERVER" ? security_manager::SERVER
+ : security_manager::CLIENT,
+ protocol,
+ policy::PolicyHandler::instance()->RetrieveCertificate(),
+ profile::Profile::instance()->ciphers_list(),
+ profile::Profile::instance()->verify_peer(),
+ profile::Profile::instance()->ca_cert_path(),
+ profile::Profile::instance()->update_before_hours())) {
LOG4CXX_ERROR(logger_, "CryptoManager initialization fail.");
return false;
}
@@ -197,7 +211,7 @@ bool LifeCycle::StartComponents() {
connection_handler_->set_protocol_handler(protocol_handler_);
connection_handler_->set_connection_handler_observer(app_manager_);
- // it is important to initialise TimeTester before TM to listen TM Adapters
+// it is important to initialise TimeTester before TM to listen TM Adapters
#ifdef TIME_TESTER
time_tester_ = new time_tester::TimeManager();
time_tester_->Start();
@@ -226,18 +240,16 @@ bool LifeCycle::StartComponents() {
#ifdef MESSAGEBROKER_HMIADAPTER
bool LifeCycle::InitMessageSystem() {
- message_broker_ =
- NsMessageBroker::CMessageBroker::getInstance();
+ message_broker_ = NsMessageBroker::CMessageBroker::getInstance();
if (!message_broker_) {
LOG4CXX_FATAL(logger_, " Wrong pMessageBroker pointer!");
return false;
}
- message_broker_server_ =
- new NsMessageBroker::TcpServer(
- profile::Profile::instance()->server_address(),
- profile::Profile::instance()->server_port(),
- message_broker_);
+ message_broker_server_ = new NsMessageBroker::TcpServer(
+ profile::Profile::instance()->server_address(),
+ profile::Profile::instance()->server_port(),
+ message_broker_);
if (!message_broker_server_) {
LOG4CXX_FATAL(logger_, " Wrong pJSONRPC20Server pointer!");
return false;
@@ -262,43 +274,45 @@ bool LifeCycle::InitMessageSystem() {
LOG4CXX_INFO(logger_, " Message broker server listen successful!");
}
- mb_adapter_ =
- new hmi_message_handler::MessageBrokerAdapter(
- hmi_message_handler::HMIMessageHandlerImpl::instance(),
- profile::Profile::instance()->server_address(),
- profile::Profile::instance()->server_port());
-
- hmi_message_handler::HMIMessageHandlerImpl::instance()->AddHMIMessageAdapter(
- mb_adapter_);
- if (!mb_adapter_->Connect()) {
- LOG4CXX_FATAL(logger_, "Cannot connect to remote peer!");
- return false;
- }
+ mb_adapter_ = new hmi_message_handler::MessageBrokerAdapter(
+ hmi_message_handler::HMIMessageHandlerImpl::instance(),
+ profile::Profile::instance()->server_address(),
+ profile::Profile::instance()->server_port());
+
+ hmi_message_handler::HMIMessageHandlerImpl::instance()->AddHMIMessageAdapter(
+ mb_adapter_);
+ if (!mb_adapter_->Connect()) {
+ LOG4CXX_FATAL(logger_, "Cannot connect to remote peer!");
+ return false;
+ }
LOG4CXX_INFO(logger_, "Start CMessageBroker thread!");
mb_thread_ = new System::Thread(
- new System::ThreadArgImpl<NsMessageBroker::CMessageBroker>(
- *message_broker_, &NsMessageBroker::CMessageBroker::MethodForThread,
- NULL));
+ new System::ThreadArgImpl<NsMessageBroker::CMessageBroker>(
+ *message_broker_,
+ &NsMessageBroker::CMessageBroker::MethodForThread,
+ NULL));
mb_thread_->Start(false);
// Thread can be named only when started because before that point
// thread doesn't have valid Id to associate name with
NameMessageBrokerThread(*mb_thread_, "MessageBroker");
LOG4CXX_INFO(logger_, "Start MessageBroker TCP server thread!");
- mb_server_thread_ = new System::Thread(
- new System::ThreadArgImpl<NsMessageBroker::TcpServer>(
- *message_broker_server_, &NsMessageBroker::TcpServer::MethodForThread,
- NULL));
+ mb_server_thread_ =
+ new System::Thread(new System::ThreadArgImpl<NsMessageBroker::TcpServer>(
+ *message_broker_server_,
+ &NsMessageBroker::TcpServer::MethodForThread,
+ NULL));
mb_server_thread_->Start(false);
NameMessageBrokerThread(*mb_server_thread_, "MB TCPServer");
LOG4CXX_INFO(logger_, "StartAppMgr JSONRPC 2.0 controller receiver thread!");
- mb_adapter_thread_ = new System::Thread(
- new System::ThreadArgImpl<hmi_message_handler::MessageBrokerAdapter>(
- *mb_adapter_,
- &hmi_message_handler::MessageBrokerAdapter::SubscribeAndBeginReceiverThread,
- NULL));
+ mb_adapter_thread_ = new System::Thread(
+ new System::ThreadArgImpl<hmi_message_handler::MessageBrokerAdapter>(
+ *mb_adapter_,
+ &hmi_message_handler::MessageBrokerAdapter::
+ SubscribeAndBeginReceiverThread,
+ NULL));
mb_adapter_thread_->Start(false);
NameMessageBrokerThread(*mb_adapter_thread_, "MB Adapter");
@@ -313,10 +327,10 @@ bool LifeCycle::InitMessageSystem() {
*/
bool LifeCycle::InitMessageSystem() {
dbus_adapter_ = new hmi_message_handler::DBusMessageAdapter(
- hmi_message_handler::HMIMessageHandlerImpl::instance());
+ hmi_message_handler::HMIMessageHandlerImpl::instance());
hmi_message_handler::HMIMessageHandlerImpl::instance()->AddHMIMessageAdapter(
- dbus_adapter_);
+ dbus_adapter_);
if (!dbus_adapter_->Init()) {
LOG4CXX_FATAL(logger_, "Cannot init DBus service!");
return false;
@@ -326,10 +340,10 @@ bool LifeCycle::InitMessageSystem() {
LOG4CXX_INFO(logger_, "Start DBusMessageAdapter thread!");
dbus_adapter_thread_ = new System::Thread(
- new System::ThreadArgImpl<hmi_message_handler::DBusMessageAdapter>(
- *dbus_adapter_,
- &hmi_message_handler::DBusMessageAdapter::MethodForReceiverThread,
- NULL));
+ new System::ThreadArgImpl<hmi_message_handler::DBusMessageAdapter>(
+ *dbus_adapter_,
+ &hmi_message_handler::DBusMessageAdapter::MethodForReceiverThread,
+ NULL));
dbus_adapter_thread_->Start(false);
return true;
@@ -339,85 +353,105 @@ bool LifeCycle::InitMessageSystem() {
#ifdef MQUEUE_HMIADAPTER
bool LifeCycle::InitMessageSystem() {
hmi_message_adapter_ = new hmi_message_handler::MqueueAdapter(
- hmi_message_handler::HMIMessageHandlerImpl::instance());
+ hmi_message_handler::HMIMessageHandlerImpl::instance());
hmi_message_handler::HMIMessageHandlerImpl::instance()->AddHMIMessageAdapter(
- hmi_message_adapter_);
+ hmi_message_adapter_);
return true;
}
#endif // MQUEUE_HMIADAPTER
namespace {
- pthread_t main_thread;
- void sig_handler(int sig) {
- switch(sig) {
- case SIGINT:
- LOG4CXX_DEBUG(logger_, "SIGINT signal has been caught");
- break;
- case SIGTERM:
- LOG4CXX_DEBUG(logger_, "SIGTERM signal has been caught");
- break;
- case SIGSEGV:
- LOG4CXX_DEBUG(logger_, "SIGSEGV signal has been caught");
- break;
- default:
- LOG4CXX_DEBUG(logger_, "Unexpected signal has been caught");
- break;
- }
- /*
- * Resend signal to the main thread in case it was
- * caught by another thread
- */
- if(pthread_equal(pthread_self(), main_thread) == 0) {
- LOG4CXX_DEBUG(logger_, "Resend signal to the main thread");
- if(pthread_kill(main_thread, sig) != 0) {
- LOG4CXX_FATAL(logger_, "Send signal to thread error");
- }
+pthread_t main_thread;
+void sig_handler(int sig) {
+ switch (sig) {
+ case SIGINT:
+ LOG4CXX_DEBUG(logger_, "SIGINT signal has been caught");
+ break;
+ case SIGTERM:
+ LOG4CXX_DEBUG(logger_, "SIGTERM signal has been caught");
+ break;
+ case SIGSEGV:
+ LOG4CXX_DEBUG(logger_, "SIGSEGV signal has been caught");
+ break;
+ default:
+ LOG4CXX_DEBUG(logger_, "Unexpected signal has been caught");
+ break;
+ }
+ /*
+ * Resend signal to the main thread in case it was
+ * caught by another thread
+ */
+ if (pthread_equal(pthread_self(), main_thread) == 0) {
+ LOG4CXX_DEBUG(logger_, "Resend signal to the main thread");
+ if (pthread_kill(main_thread, sig) != 0) {
+ LOG4CXX_FATAL(logger_, "Send signal to thread error");
}
}
+}
} // namespace
void LifeCycle::Run() {
LOG4CXX_AUTO_TRACE(logger_);
main_thread = pthread_self();
// First, register signal handlers
- if(!::utils::SubscribeToInterruptSignal(&sig_handler) ||
- !::utils::SubscribeToTerminateSignal(&sig_handler) ||
- !::utils::SubscribeToFaultSignal(&sig_handler)) {
+ if (!::utils::SubscribeToInterruptSignal(&sig_handler) ||
+ !::utils::SubscribeToTerminateSignal(&sig_handler) ||
+ !::utils::SubscribeToFaultSignal(&sig_handler)) {
LOG4CXX_FATAL(logger_, "Subscribe to system signals error");
}
// Now wait for any signal
pause();
}
-
void LifeCycle::StopComponents() {
LOG4CXX_AUTO_TRACE(logger_);
- hmi_handler_->set_message_observer(NULL);
- connection_handler_->set_connection_handler_observer(NULL);
- protocol_handler_->RemoveProtocolObserver(app_manager_);
- app_manager_->Stop();
-
+ if (hmi_handler_) {
+ hmi_handler_->set_message_observer(NULL);
+ }
+ if (connection_handler_) {
+ connection_handler_->set_connection_handler_observer(NULL);
+ }
+ if (protocol_handler_) {
+ protocol_handler_->RemoveProtocolObserver(app_manager_);
+ }
+ if (app_manager_) {
+ app_manager_->Stop();
+ }
LOG4CXX_INFO(logger_, "Stopping Protocol Handler");
- protocol_handler_->RemoveProtocolObserver(media_manager_);
+ if (protocol_handler_) {
+ protocol_handler_->RemoveProtocolObserver(media_manager_);
#ifdef ENABLE_SECURITY
- protocol_handler_->RemoveProtocolObserver(security_manager_);
- security_manager_->RemoveListener(app_manager_);
+ protocol_handler_->RemoveProtocolObserver(security_manager_);
#endif // ENABLE_SECURITY
- protocol_handler_->Stop();
+ }
+#ifdef ENABLE_SECURITY
+ if (security_manager_) {
+ security_manager_->RemoveListener(app_manager_);
+ }
+#endif // ENABLE_SECURITY
+ if (protocol_handler_) {
+ protocol_handler_->Stop();
+ }
LOG4CXX_INFO(logger_, "Destroying Media Manager");
- media_manager_->SetProtocolHandler(NULL);
+ if (media_manager_) {
+ media_manager_->SetProtocolHandler(NULL);
+ }
media_manager::MediaManagerImpl::destroy();
LOG4CXX_INFO(logger_, "Destroying Transport Manager.");
- transport_manager_->Visibility(false);
- transport_manager_->Stop();
+ if (transport_manager_) {
+ transport_manager_->Visibility(false);
+ transport_manager_->Stop();
+ }
transport_manager::TransportManagerDefault::destroy();
LOG4CXX_INFO(logger_, "Stopping Connection Handler.");
- connection_handler::ConnectionHandlerImpl::instance()->Stop();
+ if (connection_handler_) {
+ connection_handler_->Stop();
+ }
LOG4CXX_INFO(logger_, "Destroying Protocol Handler");
delete protocol_handler_;
@@ -472,7 +506,6 @@ void LifeCycle::StopComponents() {
#endif // MESSAGEBROKER_HMIADAPTER
-
#ifdef MESSAGEBROKER_HMIADAPTER
LOG4CXX_INFO(logger_, "Destroying Message Broker");
if (mb_server_thread_) {
@@ -485,9 +518,14 @@ void LifeCycle::StopComponents() {
mb_thread_->Join();
delete mb_thread_;
}
- message_broker_server_->Close();
+ if (message_broker_server_) {
+ message_broker_server_->Close();
+ }
delete message_broker_server_;
- message_broker_->stopMessageBroker();
+
+ if (message_broker_) {
+ message_broker_->stopMessageBroker();
+ }
networking::cleanup();
#endif // MESSAGEBROKER_HMIADAPTER