#include "pidfile.h"
#include "eventloop.h"
-using namespace std;
-
#ifdef DEBUG
#define MAIN_DEBUG (1)
#define NO_DAEMON (1)
#define START_FILE "/._ST_ART_ED_"
-set<pid_t> executersPid;
+namespace
+{
+std::set<pid_t> 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)
return lhs.GetStopPosition() > rhs.GetStopPosition();
}
//-----------------------------------------------------------------------------
-static void StartTimer()
+void StartTimer()
{
STG_LOGGER & WriteServLog = GetStgLogger();
}
}
//-----------------------------------------------------------------------------
+#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();
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);
}
}
//-----------------------------------------------------------------------------
#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)
//-----------------------------------------------------------------------------
void KillExecuters()
{
-set<pid_t>::iterator pid;
+std::set<pid_t>::iterator pid;
pid = executersPid.begin();
while (pid != executersPid.end())
{
}
}
//-----------------------------------------------------------------------------
+} // namespace anonymous
+//-----------------------------------------------------------------------------
int main(int argc, char * argv[])
{
SETTINGS_IMPL * settings = NULL;
WriteServLog.SetLogFileName("/var/log/stargazer.log");
}
-vector<MODULE_SETTINGS> modSettings;
-list<PLUGIN_RUNNER> modules;
+std::vector<MODULE_SETTINGS> modSettings;
+std::list<PLUGIN_RUNNER> modules;
-list<PLUGIN_RUNNER>::iterator modIter;
+std::list<PLUGIN_RUNNER>::iterator modIter;
if (getuid())
{
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)
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";
{
if (modIter->Load())
{
- WriteServLog("Error: %s",
+ WriteServLog("Error loading module '%s': %s",
+ modIter->GetPlugin()->GetVersion().c_str(),
modIter->GetStrError().c_str());
goto exitLblNotStarted;
}
{
if (modIter->Start())
{
- WriteServLog("Error: %s",
+ WriteServLog("Error starting module '%s': %s",
+ modIter->GetPlugin()->GetVersion().c_str(),
modIter->GetStrError().c_str());
goto exitLbl;
}
++modIter;
}
-srandom(stgTime);
+srandom(static_cast<unsigned int>(stgTime));
WriteServLog("Stg started successfully.");
WriteServLog("+++++++++++++++++++++++++++++++++++++++++++++");
bool stop = false;
int status;
pid_t childPid;
- set<pid_t>::iterator it;
+ std::set<pid_t>::iterator it;
switch (sig)
{
case SIGHUP:
{
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());
}
}
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;
}
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;