From dc16c37e79d356632e230d699932523f5994fef2 Mon Sep 17 00:00:00 2001 From: Guerra Mattia Date: Tue, 17 Oct 2017 16:55:53 +0200 Subject: 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 --- AudioManagerDaemon/src/main.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 listCommandPluginDirs; std::vector listRoutingPluginDirs; +// List of signals to be handled with signalfd +std::vector listOfSignalsFD = {SIGHUP, SIGTERM, SIGCHLD}; + //commandline options used by the Audiomanager itself TCLAP::ValueArg controllerPlugin("c","controllerPlugin","use controllerPlugin full path with .so ending",false,CONTROLLER_PLUGIN_DIR,"string"); TCLAP::ValueArg 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); } -- cgit v1.2.1