Skip to content

Commit

Permalink
vsomeip 2.9.4
Browse files Browse the repository at this point in the history
  • Loading branch information
juergengehring committed Jan 25, 2018
1 parent c3e889f commit e47085c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changes
=======
v2.9.4
- Fixed deadlock on suspend to RAM / resume, triggered
by signal handler.

v2.9.3
- Fixed race condition on application shutdown
- Fixed bug that application object was not destroyed
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project (vsomeip)

set (VSOMEIP_MAJOR_VERSION 2)
set (VSOMEIP_MINOR_VERSION 9)
set (VSOMEIP_PATCH_VERSION 3)
set (VSOMEIP_PATCH_VERSION 4)
set (VSOMEIP_VERSION ${VSOMEIP_MAJOR_VERSION}.${VSOMEIP_MINOR_VERSION}.${VSOMEIP_PATCH_VERSION})
set (PACKAGE_VERSION ${VSOMEIP_VERSION}) # Used in documentatin/doxygen.in
set (CMAKE_VERBOSE_MAKEFILE off)
Expand Down
71 changes: 61 additions & 10 deletions daemon/vsomeipd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <sys/stat.h>
#include <signal.h>
#include <unistd.h>
#include <thread>
#include <condition_variable>

#include <iostream>

Expand All @@ -20,23 +22,29 @@
#endif

static std::shared_ptr<vsomeip::application> its_application;
static vsomeip::routing_state_e routing_state = vsomeip::routing_state_e::RS_RUNNING;
static bool stop_application = false;
static bool stop_sighandler = false;
static std::condition_variable_any sighandler_condition;
static std::recursive_mutex sighandler_mutex;

#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
/*
* Handle signal to stop the daemon
*/
void vsomeipd_stop(int _signal) {
// Do not log messages in signal handler as this can cause deadlock in boost logger
if (_signal == SIGINT || _signal == SIGTERM) {
its_application->stop();
stop_application = true;
}
if (_signal == SIGUSR1) {
VSOMEIP_INFO << "Suspending service discovery";
its_application->set_routing_state(vsomeip::routing_state_e::RS_SUSPENDED);
routing_state = vsomeip::routing_state_e::RS_SUSPENDED;
}
if (_signal == SIGUSR2) {
VSOMEIP_INFO << "Resuming service discovery";
its_application->set_routing_state(vsomeip::routing_state_e::RS_RESUMED);
routing_state = vsomeip::routing_state_e::RS_RESUMED;
}
std::unique_lock<std::recursive_mutex> its_lock(sighandler_mutex);
sighandler_condition.notify_one();
}
#endif

Expand All @@ -61,19 +69,56 @@ int vsomeipd_process(bool _is_quiet) {
// Create the application object
its_application = its_runtime->create_application(VSOMEIP_ROUTING);
#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
// Handle signals
signal(SIGINT, vsomeipd_stop);
signal(SIGTERM, vsomeipd_stop);
signal(SIGUSR1, vsomeipd_stop);
signal(SIGUSR2, vsomeipd_stop);
std::thread sighandler_thread([]() {
// Unblock signals for this thread only
sigset_t handler_mask;
sigemptyset(&handler_mask);
sigaddset(&handler_mask, SIGUSR2);
sigaddset(&handler_mask, SIGUSR1);
sigaddset(&handler_mask, SIGTERM);
sigaddset(&handler_mask, SIGINT);
sigaddset(&handler_mask, SIGSEGV);
sigaddset(&handler_mask, SIGABRT);
pthread_sigmask(SIG_UNBLOCK, &handler_mask, NULL);

// Handle the following signals
signal(SIGINT, vsomeipd_stop);
signal(SIGTERM, vsomeipd_stop);
signal(SIGUSR1, vsomeipd_stop);
signal(SIGUSR2, vsomeipd_stop);

while (!stop_sighandler) {
std::unique_lock<std::recursive_mutex> its_lock(sighandler_mutex);
sighandler_condition.wait(its_lock);

if (stop_application) {
its_application->stop();
return;
} else if (routing_state == vsomeip::routing_state_e::RS_RESUMED ||
routing_state == vsomeip::routing_state_e::RS_SUSPENDED){
VSOMEIP_INFO << "Received signal for setting routing_state to: 0x"
<< std::hex << static_cast<int>(routing_state );
its_application->set_routing_state(routing_state);
}
}
});
#endif
if (its_application->init()) {
if (its_application->is_routing()) {
its_application->start();
#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
sighandler_thread.join();
#endif
return 0;
}
VSOMEIP_ERROR << "vsomeipd has not been configured as routing - abort";
}
#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
std::unique_lock<std::recursive_mutex> its_lock(sighandler_mutex);
stop_sighandler = true;
sighandler_condition.notify_one();
sighandler_thread.join();
#endif
return -1;
}

Expand All @@ -86,6 +131,12 @@ int vsomeipd_process(bool _is_quiet) {
* and start processing.
*/
int main(int argc, char **argv) {
#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
// Block all signals
sigset_t mask;
sigfillset(&mask);
sigprocmask(SIG_SETMASK, &mask, NULL);
#endif
bool must_daemonize(false);
bool is_quiet(false);
if (argc > 1) {
Expand Down

0 comments on commit e47085c

Please sign in to comment.