summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuerra Mattia <mguerra@de.adit-jv.com>2017-10-17 16:55:53 +0200
committerJens Lorenz <jlorenz@de.adit-jv.com>2017-11-07 12:25:45 +0100
commitdc16c37e79d356632e230d699932523f5994fef2 (patch)
treeca6fe89f6e5e29d5d93ee9b491b0f2f1ab54287a
parentf620be8a774f966fbd76ca8892a39ce28037a213 (diff)
downloadaudiomanager-dc16c37e79d356632e230d699932523f5994fef2.tar.gz
AMDaemon: set pthread_sigmask for signalfd
Sets the mask for potential spawned threads (e.g. DLT) so that they won't interfere with the implementation of signalfd Signed-off-by: Guerra Mattia <mguerra@de.adit-jv.com>
-rwxr-xr-xAudioManagerDaemon/src/main.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp
index 5c0582e..8271db4 100755
--- a/AudioManagerDaemon/src/main.cpp
+++ b/AudioManagerDaemon/src/main.cpp
@@ -75,6 +75,9 @@ using namespace am;
std::vector<std::string> listCommandPluginDirs;
std::vector<std::string> listRoutingPluginDirs;
+// List of signals to be handled with signalfd
+std::vector<uint8_t> listOfSignalsFD = {SIGHUP, SIGTERM, SIGCHLD};
+
//commandline options used by the Audiomanager itself
TCLAP::ValueArg<std::string> controllerPlugin("c","controllerPlugin","use controllerPlugin full path with .so ending",false,CONTROLLER_PLUGIN_DIR,"string");
TCLAP::ValueArg<std::string> additionalCommandPluginDirs("L","additionalCommandPluginDirs","additional path for looking for command plugins, can be used after -l option",false," ","string");
@@ -251,7 +254,7 @@ void mainProgram(int argc, char *argv[])
throw std::runtime_error(std::string("CAmSocketHandler: Could not create pipe or file descriptor is invalid."));
}
- if( E_OK!=iSocketHandler.listenToSignals({SIGHUP, SIGTERM, SIGCHLD}) )
+ if(E_OK != iSocketHandler.listenToSignals(listOfSignalsFD))
{
logWarning("CAmSocketHandler failed to register itself as signal handler.");
}
@@ -399,8 +402,20 @@ int main(int argc, char *argv[], char** envp)
//register new out of memory handler
std::set_new_handler(&OutOfMemoryHandler);
+ sigset_t signal_mask;
+ sigemptyset(&signal_mask);
+ for (auto it : listOfSignalsFD)
+ {
+ sigaddset(&signal_mask, it);
+ }
+
try
{
+ if (pthread_sigmask(SIG_BLOCK, &signal_mask, NULL) != 0)
+ {
+ throw std::runtime_error(std::string("Couldn't set mask for potential future threads"));
+ }
+
//we do this to catch all exceptions and have a graceful ending just in case
mainProgram(argc,argv);
}