X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/d6a36e320b2e843931f45e718d4179231a763c4f..37925a173b073b547ffc7dd7412de658accf694c:/projects/stargazer/main.cpp diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index a8678893..c7bfb4aa 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,11 @@ else } } //----------------------------------------------------------------------------- +#ifdef LINUX int StartScriptExecuter(char * procName, int msgKey, int * msgID, SETTINGS_IMPL * settings) +#else +int StartScriptExecuter(char *, int msgKey, int * msgID, SETTINGS_IMPL * settings) +#endif { STG_LOGGER & WriteServLog = GetStgLogger(); @@ -140,12 +151,20 @@ switch (executerPid) case 0: delete settings; +#ifdef LINUX Executer(*msgID, executerPid, procName); +#else + Executer(*msgID, executerPid); +#endif return 1; default: if (executersPid.empty()) { +#ifdef LINUX Executer(*msgID, executerPid, NULL); +#else + Executer(*msgID, executerPid); +#endif } executersPid.insert(executerPid); } @@ -153,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) @@ -197,7 +216,7 @@ return 0; //----------------------------------------------------------------------------- void KillExecuters() { -set::iterator pid; +std::set::iterator pid; pid = executersPid.begin(); while (pid != executersPid.end()) { @@ -207,6 +226,8 @@ while (pid != executersPid.end()) } } //----------------------------------------------------------------------------- +} // namespace anonymous +//----------------------------------------------------------------------------- int main(int argc, char * argv[]) { SETTINGS_IMPL * settings = NULL; @@ -224,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()) { @@ -243,16 +264,26 @@ else if (settings->ReadSettings()) { STG_LOGGER & WriteServLog = GetStgLogger(); - if (settings->GetLogFileName() != "") WriteServLog.SetLogFileName(settings->GetLogFileName()); WriteServLog("ReadSettings error. %s", settings->GetStrError().c_str()); exit(1); } - +/*************************************************************************************************/ +//вывод scriptParams + printfd(__FILE__, "--- Script params dump ---\n"); + std::vector::const_iterator it(settings->GetScriptParams().begin()); + while (it != settings->GetScriptParams().end()) + { + printfd(__FILE__, "%s\n", it->c_str()); + it++; + } + printfd(__FILE__, "--- End dump ---\n"); +/*************************************************************************************************/ + #ifndef NO_DAEMON -string startFile(settings->GetConfDir() + START_FILE); +std::string startFile(settings->GetConfDir() + START_FILE); #endif if (ForkAndWait(settings->GetConfDir()) < 0) @@ -326,7 +357,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"; @@ -351,7 +382,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; } @@ -378,7 +410,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; } @@ -386,7 +419,7 @@ while (modIter != modules.end()) ++modIter; } -srandom(stgTime); +srandom(static_cast(stgTime)); WriteServLog("Stg started successfully."); WriteServLog("+++++++++++++++++++++++++++++++++++++++++++++"); @@ -403,7 +436,7 @@ while (true) bool stop = false; int status; pid_t childPid; - set::iterator it; + std::set::iterator it; switch (sig) { case SIGHUP: @@ -413,9 +446,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()); } } @@ -461,12 +494,15 @@ 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; } @@ -490,10 +526,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;