From 6681a98594680fe6ab15abeeb0ea915c44d7ad6a Mon Sep 17 00:00:00 2001 From: christian mueller Date: Thu, 3 May 2012 14:40:20 +0200 Subject: * [GAM-74] resolving issues found by coverity scan Signed-off-by: christian mueller --- AudioManagerDaemon/src/main.cpp | 92 ++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 37 deletions(-) (limited to 'AudioManagerDaemon/src/main.cpp') diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp index b01b98d..ad908ec 100644 --- a/AudioManagerDaemon/src/main.cpp +++ b/AudioManagerDaemon/src/main.cpp @@ -270,44 +270,8 @@ static void signalHandler(int sig, siginfo_t *siginfo, void *context) exit(1); } -/** - * main - * @param argc - * @param argv - * @return - */ -int main(int argc, char *argv[]) +void mainProgram() { - listCommandPluginDirs.push_back(std::string(DEFAULT_PLUGIN_COMMAND_DIR)); - listRoutingPluginDirs.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR)); - - //parse the commandline options - parseCommandLine(argc, (char**) argv); - - CAmDltWrapper::instance(enableNoDLTDebug)->registerApp("AudioManagerDeamon", "AudioManagerDeamon"); - CAmDltWrapper::instance()->registerContext(AudioManager, "Main", "Main Context"); - logInfo("The Audiomanager is started"); - logInfo("The version of the Audiomanager", DAEMONVERSION); - - //now the signal handler: - 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); - sigaction(SIGQUIT, &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); - //Instantiate all classes. Keep in same order ! CAmSocketHandler iSocketHandler; @@ -351,6 +315,60 @@ int main(int argc, char *argv[]) //start the mainloop here.... iSocketHandler.start_listenting(); +} + +/** + * main + * @param argc + * @param argv + * @return + */ +int main(int argc, char *argv[]) +{ + listCommandPluginDirs.push_back(std::string(DEFAULT_PLUGIN_COMMAND_DIR)); + listRoutingPluginDirs.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR)); + + //parse the commandline options + parseCommandLine(argc, (char**) argv); + + CAmDltWrapper::instance(enableNoDLTDebug)->registerApp("AudioManagerDeamon", "AudioManagerDeamon"); + CAmDltWrapper::instance()->registerContext(AudioManager, "Main", "Main Context"); + logInfo("The Audiomanager is started"); + logInfo("The version of the Audiomanager", DAEMONVERSION); + + //now the signal handler: + 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); + sigaction(SIGQUIT, &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); + + try + { + //we do this to catch all exceptions and have a graceful ending just in case + mainProgram(); + } + + catch (std::exception& exc) + { + logError("The AudioManager ended by throwing the exception", exc.what()); + //todo: ergency exit here... call destructors etc... + exit(EXIT_FAILURE); + } + + close(fd0); close(fd1); close(fd2); -- cgit v1.2.1