#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
+#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)
case 0:
delete settings;
-#ifdef LINUX
+#if defined(LINUX) || defined(DARWIN)
Executer(*msgID, executerPid, procName);
#else
Executer(*msgID, executerPid);
default:
if (executersPid.empty()) {
-#ifdef LINUX
+#if defined(LINUX) || defined(DARWIN)
Executer(*msgID, executerPid, NULL);
#else
Executer(*msgID, 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";
++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: