X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/8172e2258d975bcff42e2f2ca5580584f11da890..289d396c8d0684e23c2233291164febfec3947bf:/projects/stargazer/main.cpp?ds=sidebyside diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index 4fff88a1..1e4c677e 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -60,8 +60,6 @@ #include "pidfile.h" #include "eventloop.h" -using namespace std; - #ifdef DEBUG #define MAIN_DEBUG (1) #define NO_DAEMON (1) @@ -69,7 +67,16 @@ using namespace std; #define START_FILE "/._ST_ART_ED_" -set executersPid; +namespace +{ +std::set executersPid; + +bool StartModCmp(const PLUGIN_RUNNER & lhs, const PLUGIN_RUNNER & rhs); +bool StopModCmp(const PLUGIN_RUNNER & lhs, const PLUGIN_RUNNER & rhs); +void StartTimer(); +int StartScriptExecuter(char * procName, int msgKey, int * msgID, SETTINGS_IMPL * settings); +int ForkAndWait(const std::string & confDir); +void KillExecuters(); //----------------------------------------------------------------------------- bool StartModCmp(const PLUGIN_RUNNER & lhs, const PLUGIN_RUNNER & rhs) @@ -82,7 +89,7 @@ bool StopModCmp(const PLUGIN_RUNNER & lhs, const PLUGIN_RUNNER & rhs) return lhs.GetStopPosition() > rhs.GetStopPosition(); } //----------------------------------------------------------------------------- -static void StartTimer() +void StartTimer() { STG_LOGGER & WriteServLog = GetStgLogger(); @@ -99,7 +106,7 @@ else } } //----------------------------------------------------------------------------- -#ifdef LINUX +#if defined(LINUX) || defined(DARWIN) int StartScriptExecuter(char * procName, int msgKey, int * msgID, SETTINGS_IMPL * settings) #else int StartScriptExecuter(char *, int msgKey, int * msgID, SETTINGS_IMPL * settings) @@ -144,7 +151,7 @@ switch (executerPid) case 0: delete settings; -#ifdef LINUX +#if defined(LINUX) || defined(DARWIN) Executer(*msgID, executerPid, procName); #else Executer(*msgID, executerPid); @@ -153,7 +160,7 @@ switch (executerPid) default: if (executersPid.empty()) { -#ifdef LINUX +#if defined(LINUX) || defined(DARWIN) Executer(*msgID, executerPid, NULL); #else Executer(*msgID, executerPid); @@ -165,14 +172,14 @@ return 0; } //----------------------------------------------------------------------------- #ifndef NO_DAEMON -int ForkAndWait(const string & confDir) +int ForkAndWait(const std::string & confDir) #else -int ForkAndWait(const string &) +int ForkAndWait(const std::string &) #endif { #ifndef NO_DAEMON pid_t childPid = fork(); -string startFile = confDir + START_FILE; +std::string startFile = confDir + START_FILE; unlink(startFile.c_str()); switch (childPid) @@ -209,7 +216,7 @@ return 0; //----------------------------------------------------------------------------- void KillExecuters() { -set::iterator pid; +std::set::iterator pid; pid = executersPid.begin(); while (pid != executersPid.end()) { @@ -219,6 +226,8 @@ while (pid != executersPid.end()) } } //----------------------------------------------------------------------------- +} // namespace anonymous +//----------------------------------------------------------------------------- int main(int argc, char * argv[]) { SETTINGS_IMPL * settings = NULL; @@ -236,10 +245,10 @@ int msgID = -11; WriteServLog.SetLogFileName("/var/log/stargazer.log"); } -vector modSettings; -list modules; +std::vector modSettings; +std::list modules; -list::iterator modIter; +std::list::iterator modIter; if (getuid()) { @@ -262,9 +271,8 @@ if (settings->ReadSettings()) WriteServLog("ReadSettings error. %s", settings->GetStrError().c_str()); exit(1); } - #ifndef NO_DAEMON -string startFile(settings->GetConfDir() + START_FILE); +std::string startFile(settings->GetConfDir() + START_FILE); #endif if (ForkAndWait(settings->GetConfDir()) < 0) @@ -338,7 +346,7 @@ modSettings = settings->GetModulesSettings(); for (size_t i = 0; i < modSettings.size(); i++) { - string modulePath = settings->GetModulesPath(); + std::string modulePath = settings->GetModulesPath(); modulePath += "/mod_"; modulePath += modSettings[i].moduleName; modulePath += ".so"; @@ -363,7 +371,8 @@ while (modIter != modules.end()) { if (modIter->Load()) { - WriteServLog("Error: %s", + WriteServLog("Error loading module '%s': %s", + modIter->GetPlugin()->GetVersion().c_str(), modIter->GetStrError().c_str()); goto exitLblNotStarted; } @@ -390,7 +399,8 @@ while (modIter != modules.end()) { if (modIter->Start()) { - WriteServLog("Error: %s", + WriteServLog("Error starting module '%s': %s", + modIter->GetPlugin()->GetVersion().c_str(), modIter->GetStrError().c_str()); goto exitLbl; } @@ -398,7 +408,7 @@ while (modIter != modules.end()) ++modIter; } -srandom(stgTime); +srandom(static_cast(stgTime)); WriteServLog("Stg started successfully."); WriteServLog("+++++++++++++++++++++++++++++++++++++++++++++"); @@ -415,7 +425,7 @@ while (true) bool stop = false; int status; pid_t childPid; - set::iterator it; + std::set::iterator it; switch (sig) { case SIGHUP: @@ -425,9 +435,9 @@ while (true) { if (modIter->Reload()) { - WriteServLog("Error reloading %s ('%s')", modIter->GetPlugin()->GetVersion().c_str(), + WriteServLog("Error reloading module '%s': '%s'", modIter->GetPlugin()->GetVersion().c_str(), modIter->GetStrError().c_str()); - printfd(__FILE__, "Error reloading %s ('%s')\n", modIter->GetPlugin()->GetVersion().c_str(), + printfd(__FILE__, "Error reloading module '%s': '%s'\n", modIter->GetPlugin()->GetVersion().c_str(), modIter->GetStrError().c_str()); } } @@ -453,7 +463,7 @@ while (true) } break; default: - WriteServLog("Ignore signel %d", sig); + WriteServLog("Ignore signal %d", sig); break; } if (stop) @@ -473,14 +483,14 @@ while (modIter != modules.end()) printfd(__FILE__, "Stopping module '%s'\n", name.c_str()); if (modIter->Stop()) { - WriteServLog("Module \'%s\': Error: %s", + WriteServLog("Error stopping module '%s': %s", modIter->GetPlugin()->GetVersion().c_str(), modIter->GetStrError().c_str()); - printfd(__FILE__, "Failed to stop module '%s'\n", name.c_str()); + printfd(__FILE__, "Error stopping module '%s': '%s'\n", modIter->GetPlugin()->GetVersion().c_str(), modIter->GetStrError().c_str()); } else { - WriteServLog("Module: \'%s\'. Stop successfull.", modIter->GetPlugin()->GetVersion().c_str()); + WriteServLog("Module: '%s'. Stop successfull.", modIter->GetPlugin()->GetVersion().c_str()); } ++modIter; } @@ -505,10 +515,10 @@ while (modIter != modules.end()) printfd(__FILE__, "Unloading module '%s'\n", name.c_str()); if (modIter->Unload()) { - WriteServLog("Module \'%s\': Error: %s", - name.c_str(), + WriteServLog("Error unloading module '%s': '%s'", + modIter->GetPlugin()->GetVersion().c_str(), modIter->GetStrError().c_str()); - printfd(__FILE__, "Failed to unload module '%s'\n", name.c_str()); + printfd(__FILE__, "Error unloading module '%s': '%s'\n", modIter->GetPlugin()->GetVersion().c_str(), modIter->GetStrError().c_str()); } } ++modIter;