summaryrefslogtreecommitdiff
path: root/AudioManagerDaemon/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'AudioManagerDaemon/src/main.cpp')
-rwxr-xr-xAudioManagerDaemon/src/main.cpp57
1 files changed, 37 insertions, 20 deletions
diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp
index 26d7cea..5c0582e 100755
--- a/AudioManagerDaemon/src/main.cpp
+++ b/AudioManagerDaemon/src/main.cpp
@@ -195,7 +195,7 @@ static void signalHandler(int sig, siginfo_t *siginfo, void *context)
switch (sig)
{
/*ctl +c lets call direct controllerRundown, because we might be blocked at the moment.
- But there is the risk of interrupting something important */https://asc.bmwgroup.net/wiki/display/MGUROTO/Lastest+and+greatest
+ But there is the risk of interrupting something important */
case SIGINT:
CAmControlSender::CallsetControllerRundown(sig);
break;
@@ -204,21 +204,12 @@ static void signalHandler(int sig, siginfo_t *siginfo, void *context)
case SIGQUIT:
CAmControlSender::CallsetControllerRundown(sig);
break;
-
- /* more friendly here assuming systemd wants to stop us, so we can use the mainloop */
- case SIGTERM:
- CAmControlSender::CallsetControllerRundownSafe(sig);
- break;
-
- /* looks friendly, too, so lets take the long run */
- case SIGHUP:
- CAmControlSender::CallsetControllerRundownSafe(sig);
- break;
default:
break;
}
}
+
void mainProgram(int argc, char *argv[])
{
@@ -255,6 +246,39 @@ void mainProgram(int argc, char *argv[])
//Instantiate all classes. Keep in same order !
CAmSocketHandler iSocketHandler;
+ if(iSocketHandler.fatalErrorOccurred())
+ {
+ throw std::runtime_error(std::string("CAmSocketHandler: Could not create pipe or file descriptor is invalid."));
+ }
+
+ if( E_OK!=iSocketHandler.listenToSignals({SIGHUP, SIGTERM, SIGCHLD}) )
+ {
+ logWarning("CAmSocketHandler failed to register itself as signal handler.");
+ }
+ //Register signal handler
+ sh_pollHandle_t signalHandler;
+ iSocketHandler.addSignalHandler([&](const sh_pollHandle_t handle, const signalfd_siginfo & info, void* userData){
+
+ unsigned sig = info.ssi_signo;
+ unsigned user = info.ssi_uid;
+
+ logInfo("signal handler was called from user", user, "with signal ",sig);
+
+ switch (sig)
+ {
+ /* more friendly here assuming systemd wants to stop us, so we can use the mainloop */
+ case SIGTERM:
+ CAmControlSender::CallsetControllerRundownSafe(sig);
+ break;
+
+ /* looks friendly, too, so lets take the long run */
+ case SIGHUP:
+ CAmControlSender::CallsetControllerRundownSafe(sig);
+ break;
+ default:
+ break;
+ }
+ },signalHandler,NULL);
if(commandPluginDir.isSet())
{
@@ -364,21 +388,14 @@ int main(int argc, char *argv[], char** envp)
listCommandPluginDirs.push_back(std::string(DEFAULT_PLUGIN_COMMAND_DIR));
listRoutingPluginDirs.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR));
- //now the signal handler:
+ //critical signals are registered here:
struct sigaction signalAction;
memset(&signalAction, '\0', sizeof(signalAction));
signalAction.sa_sigaction = &signalHandler;
signalAction.sa_flags = SA_SIGINFO;
sigaction(SIGINT, &signalAction, NULL);
sigaction(SIGQUIT, &signalAction, NULL);
- sigaction(SIGTERM, &signalAction, NULL);
- sigaction(SIGHUP, &signalAction, NULL);
-
- struct sigaction signalChildAction;
- memset(&signalChildAction, '\0', sizeof(signalChildAction));
- signalChildAction.sa_flags = SA_NOCLDWAIT;
- sigaction(SIGCHLD, &signalChildAction, NULL);
-
+
//register new out of memory handler
std::set_new_handler(&OutOfMemoryHandler);