git.stg.codes
/
stg.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Some small changes in srvconf.lib.
[stg.git]
/
projects
/
stargazer
/
main.cpp
diff --git
a/projects/stargazer/main.cpp
b/projects/stargazer/main.cpp
index 6a96519bc5c35ecbd4f43cc0fb0f77eaf4f5180a..73786c4efd6c0cc46ba8aa805b9edaca0d9687cb 100644
(file)
--- a/
projects/stargazer/main.cpp
+++ b/
projects/stargazer/main.cpp
@@
-63,10
+63,10
@@
namespace
{
namespace
{
-std::set<pid_t> executers
Pid
;
+std::set<pid_t> executers;
void StartTimer();
void StartTimer();
-int StartScriptExecuter(char * procName, int msgKey, int * msgID
, SETTINGS_IMPL * settings
);
+int StartScriptExecuter(char * procName, int msgKey, int * msgID);
int ForkAndWait(const std::string & confDir);
void KillExecuters();
int ForkAndWait(const std::string & confDir);
void KillExecuters();
@@
-89,9
+89,9
@@
else
}
//-----------------------------------------------------------------------------
#if defined(LINUX) || defined(DARWIN)
}
//-----------------------------------------------------------------------------
#if defined(LINUX) || defined(DARWIN)
-int StartScriptExecuter(char * procName, int msgKey, int * msgID
, SETTINGS_IMPL * settings
)
+int StartScriptExecuter(char * procName, int msgKey, int * msgID)
#else
#else
-int StartScriptExecuter(char *, int msgKey, int * msgID
, SETTINGS_IMPL * settings
)
+int StartScriptExecuter(char *, int msgKey, int * msgID)
#endif
{
STG_LOGGER & WriteServLog = GetStgLogger();
#endif
{
STG_LOGGER & WriteServLog = GetStgLogger();
@@
-123,32
+123,31
@@
if (*msgID == -11) // If msgID == -11 - first call. Create queue
}
}
}
}
-pid_t
executerP
id = fork();
+pid_t
p
id = fork();
-switch (
executerP
id)
+switch (
p
id)
{
case -1:
WriteServLog("Fork error!");
return -1;
case 0:
{
case -1:
WriteServLog("Fork error!");
return -1;
case 0:
- delete settings;
#if defined(LINUX) || defined(DARWIN)
#if defined(LINUX) || defined(DARWIN)
- Executer(*msgID,
executerP
id, procName);
+ Executer(*msgID,
p
id, procName);
#else
#else
- Executer(*msgID,
executerP
id);
+ Executer(*msgID,
p
id);
#endif
return 1;
default:
#endif
return 1;
default:
- if (executers
Pid
.empty()) {
+ if (executers.empty()) {
#if defined(LINUX) || defined(DARWIN)
#if defined(LINUX) || defined(DARWIN)
- Executer(*msgID,
executerP
id, NULL);
+ Executer(*msgID,
p
id, NULL);
#else
#else
- Executer(*msgID,
executerP
id);
+ Executer(*msgID,
p
id);
#endif
}
#endif
}
- executers
Pid.insert(executerP
id);
+ executers
.insert(p
id);
}
return 0;
}
}
return 0;
}
@@
-160,11
+159,11
@@
int ForkAndWait(const std::string &)
#endif
{
#ifndef NO_DAEMON
#endif
{
#ifndef NO_DAEMON
-pid_t
childP
id = fork();
+pid_t
p
id = fork();
std::string startFile = confDir + START_FILE;
unlink(startFile.c_str());
std::string startFile = confDir + START_FILE;
unlink(startFile.c_str());
-switch (
childP
id)
+switch (
p
id)
{
case -1:
return -1;
{
case -1:
return -1;
@@
-198,9
+197,8
@@
return 0;
//-----------------------------------------------------------------------------
void KillExecuters()
{
//-----------------------------------------------------------------------------
void KillExecuters()
{
-std::set<pid_t>::iterator pid;
-pid = executersPid.begin();
-while (pid != executersPid.end())
+std::set<pid_t>::iterator pid(executers.begin());
+while (pid != executers.end())
{
printfd(__FILE__, "KillExecuters pid=%d\n", *pid);
kill(*pid, SIGUSR1);
{
printfd(__FILE__, "KillExecuters pid=%d\n", *pid);
kill(*pid, SIGUSR1);
@@
-212,7
+210,6
@@
while (pid != executersPid.end())
//-----------------------------------------------------------------------------
int main(int argc, char * argv[])
{
//-----------------------------------------------------------------------------
int main(int argc, char * argv[])
{
-SETTINGS_IMPL * settings = NULL;
int msgID = -11;
GetStgLogger().SetLogFileName("/var/log/stargazer.log");
int msgID = -11;
GetStgLogger().SetLogFileName("/var/log/stargazer.log");
@@
-223,27
+220,24
@@
if (getuid())
return 1;
}
return 1;
}
-if (argc == 2)
- settings = new SETTINGS_IMPL(argv[1]);
-else
- settings = new SETTINGS_IMPL();
+SETTINGS_IMPL settings(argc == 2 ? argv[1] : "");
-if (settings
->
ReadSettings())
+if (settings
.
ReadSettings())
{
STG_LOGGER & WriteServLog = GetStgLogger();
{
STG_LOGGER & WriteServLog = GetStgLogger();
- if (settings
->
GetLogFileName() != "")
- WriteServLog.SetLogFileName(settings
->
GetLogFileName());
+ if (settings
.
GetLogFileName() != "")
+ WriteServLog.SetLogFileName(settings
.
GetLogFileName());
- WriteServLog("ReadSettings error. %s", settings
->
GetStrError().c_str());
+ WriteServLog("ReadSettings error. %s", settings
.
GetStrError().c_str());
return -1;
}
#ifndef NO_DAEMON
return -1;
}
#ifndef NO_DAEMON
-std::string startFile(settings
->
GetConfDir() + START_FILE);
+std::string startFile(settings
.
GetConfDir() + START_FILE);
#endif
#endif
-if (ForkAndWait(settings
->
GetConfDir()) < 0)
+if (ForkAndWait(settings
.
GetConfDir()) < 0)
{
STG_LOGGER & WriteServLog = GetStgLogger();
WriteServLog("Fork error!");
{
STG_LOGGER & WriteServLog = GetStgLogger();
WriteServLog("Fork error!");
@@
-251,12
+245,12
@@
if (ForkAndWait(settings->GetConfDir()) < 0)
}
STG_LOGGER & WriteServLog = GetStgLogger();
}
STG_LOGGER & WriteServLog = GetStgLogger();
-WriteServLog.SetLogFileName(settings
->
GetLogFileName());
+WriteServLog.SetLogFileName(settings
.
GetLogFileName());
WriteServLog("Stg v. %s", SERVER_VERSION);
WriteServLog("Stg v. %s", SERVER_VERSION);
-for (size_t i = 0; i < settings
->
GetExecutersNum(); i++)
+for (size_t i = 0; i < settings
.
GetExecutersNum(); i++)
{
{
- int ret = StartScriptExecuter(argv[0], settings
->GetExecMsgKey(), &msgID, settings
);
+ int ret = StartScriptExecuter(argv[0], settings
.GetExecMsgKey(), &msgID
);
if (ret < 0)
{
STG_LOGGER & WriteServLog = GetStgLogger();
if (ret < 0)
{
STG_LOGGER & WriteServLog = GetStgLogger();
@@
-270,7
+264,7
@@
for (size_t i = 0; i < settings->GetExecutersNum(); i++)
}
}
}
}
-PIDFile pidFile(settings
->
GetPIDFileName());
+PIDFile pidFile(settings
.
GetPIDFileName());
sigset_t signalSet;
sigfillset(&signalSet);
sigset_t signalSet;
sigfillset(&signalSet);
@@
-287,7
+281,7
@@
if (!IsStgTimerRunning())
EVENT_LOOP & loop(EVENT_LOOP_SINGLETON::GetInstance());
EVENT_LOOP & loop(EVENT_LOOP_SINGLETON::GetInstance());
-STORE_LOADER storeLoader(
*
settings);
+STORE_LOADER storeLoader(settings);
if (storeLoader.Load())
{
printfd(__FILE__, "Storage plugin: '%s'\n", storeLoader.GetStrError().c_str());
if (storeLoader.Load())
{
printfd(__FILE__, "Storage plugin: '%s'\n", storeLoader.GetStrError().c_str());
@@
-309,9
+303,9
@@
ADMINS_IMPL admins(&store);
TARIFFS_IMPL tariffs(&store);
SERVICES_IMPL services(&store);
CORPORATIONS_IMPL corps(&store);
TARIFFS_IMPL tariffs(&store);
SERVICES_IMPL services(&store);
CORPORATIONS_IMPL corps(&store);
-USERS_IMPL users(settings, &store, &tariffs, services, admins.GetSysAdmin());
-TRAFFCOUNTER_IMPL traffCnt(&users, settings
->
GetRulesFileName());
-traffCnt.SetMonitorDir(settings
->
GetMonitorDir());
+USERS_IMPL users(
&
settings, &store, &tariffs, services, admins.GetSysAdmin());
+TRAFFCOUNTER_IMPL traffCnt(&users, settings
.
GetRulesFileName());
+traffCnt.SetMonitorDir(settings
.
GetMonitorDir());
if (users.Start())
return -1;
if (users.Start())
return -1;
@@
-323,7
+317,7
@@
if (traffCnt.Start())
WriteServLog("Traffcounter started successfully.");
WriteServLog("Traffcounter started successfully.");
-STG::PluginManager manager(
*
settings, store, admins, tariffs, services, corps, users, traffCnt);
+STG::PluginManager manager(settings, store, admins, tariffs, services, corps, users, traffCnt);
srandom(static_cast<unsigned int>(stgTime));
srandom(static_cast<unsigned int>(stgTime));
@@
-334,15
+328,13
@@
WriteServLog("+++++++++++++++++++++++++++++++++++++++++++++");
creat(startFile.c_str(), S_IRUSR);
#endif
creat(startFile.c_str(), S_IRUSR);
#endif
-while (true)
+bool running = true;
+while (running)
{
sigfillset(&signalSet);
int sig = 0;
sigwait(&signalSet, &sig);
{
sigfillset(&signalSet);
int sig = 0;
sigwait(&signalSet, &sig);
- bool stop = false;
int status;
int status;
- pid_t childPid;
- std::set<pid_t>::iterator it;
switch (sig)
{
case SIGHUP:
switch (sig)
{
case SIGHUP:
@@
-350,31
+342,23
@@
while (true)
manager.reload();
break;
case SIGTERM:
manager.reload();
break;
case SIGTERM:
-
stop = tru
e;
+
running = fals
e;
break;
case SIGINT:
break;
case SIGINT:
-
stop = tru
e;
+
running = fals
e;
break;
case SIGPIPE:
WriteServLog("Broken pipe!");
break;
case SIGCHLD:
break;
case SIGPIPE:
WriteServLog("Broken pipe!");
break;
case SIGCHLD:
- childPid = waitpid(-1, &status, WNOHANG);
-
- it = executersPid.find(childPid);
- if (it != executersPid.end())
- {
- executersPid.erase(it);
- if (executersPid.empty())
- stop = true;
- }
+ executers.erase(waitpid(-1, &status, WNOHANG));
+ if (executers.empty())
+ running = false;
break;
default:
WriteServLog("Ignore signal %d", sig);
break;
}
break;
default:
WriteServLog("Ignore signal %d", sig);
break;
}
- if (stop)
- break;
}
WriteServLog("+++++++++++++++++++++++++++++++++++++++++++++");
}
WriteServLog("+++++++++++++++++++++++++++++++++++++++++++++");
@@
-400,8
+384,6
@@
KillExecuters();
StopStgTimer();
WriteServLog("StgTimer: Stop successfull.");
StopStgTimer();
WriteServLog("StgTimer: Stop successfull.");
-delete settings;
-
WriteServLog("Stg stopped successfully.");
WriteServLog("---------------------------------------------");
WriteServLog("Stg stopped successfully.");
WriteServLog("---------------------------------------------");