X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/9b9f5b6503dab7eaf2c35de920169933496715d0..1347f3d1e04bedd1508589173f577673ee2c5554:/projects/stargazer/main.cpp diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index 37582348..eb61e2d5 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(); @@ -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()) { @@ -264,7 +273,7 @@ if (settings->ReadSettings()) } #ifndef NO_DAEMON -string startFile(settings->GetConfDir() + START_FILE); +std::string startFile(settings->GetConfDir() + START_FILE); #endif if (ForkAndWait(settings->GetConfDir()) < 0) @@ -338,7 +347,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 +372,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 +400,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 +409,7 @@ while (modIter != modules.end()) ++modIter; } -srandom(stgTime); +srandom(static_cast(stgTime)); WriteServLog("Stg started successfully."); WriteServLog("+++++++++++++++++++++++++++++++++++++++++++++"); @@ -415,7 +426,7 @@ while (true) bool stop = false; int status; pid_t childPid; - set::iterator it; + std::set::iterator it; switch (sig) { case SIGHUP: @@ -425,9 +436,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()); } } @@ -473,12 +484,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; } @@ -502,10 +516,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;