]> git.stg.codes - stg.git/commitdiff
Cosmetic changes.
authorMaxim Mamontov <faust.madf@gmail.com>
Sat, 25 Oct 2014 03:27:00 +0000 (06:27 +0300)
committerMaxim Mamontov <faust.madf@gmail.com>
Sat, 25 Oct 2014 03:27:00 +0000 (06:27 +0300)
projects/stargazer/main.cpp
projects/stargazer/plugin_mgr.cpp
projects/stargazer/settings_impl.cpp
projects/stargazer/settings_impl.h

index 6a96519bc5c35ecbd4f43cc0fb0f77eaf4f5180a..3db3b2669ede87b264d6c417108e2fb35342f6bc 100644 (file)
@@ -63,7 +63,7 @@
 
 namespace
 {
 
 namespace
 {
-std::set<pid_t> executersPid;
+std::set<pid_t> executers;
 
 void StartTimer();
 int StartScriptExecuter(char * procName, int msgKey, int * msgID, SETTINGS_IMPL * settings);
 
 void StartTimer();
 int StartScriptExecuter(char * procName, int msgKey, int * msgID, SETTINGS_IMPL * settings);
@@ -123,9 +123,9 @@ if (*msgID == -11)   // If msgID == -11 - first call. Create queue
         }
     }
 
         }
     }
 
-pid_t executerPid = fork();
+pid_t pid = fork();
 
 
-switch (executerPid)
+switch (pid)
     {
     case -1:
         WriteServLog("Fork error!");
     {
     case -1:
         WriteServLog("Fork error!");
@@ -134,21 +134,21 @@ switch (executerPid)
     case 0:
         delete settings;
 #if defined(LINUX) || defined(DARWIN)
     case 0:
         delete settings;
 #if defined(LINUX) || defined(DARWIN)
-        Executer(*msgID, executerPid, procName);
+        Executer(*msgID, pid, procName);
 #else
 #else
-        Executer(*msgID, executerPid);
+        Executer(*msgID, pid);
 #endif
         return 1;
 
     default:
 #endif
         return 1;
 
     default:
-        if (executersPid.empty()) {
+        if (executers.empty()) {
 #if defined(LINUX) || defined(DARWIN)
 #if defined(LINUX) || defined(DARWIN)
-            Executer(*msgID, executerPid, NULL);
+            Executer(*msgID, pid, NULL);
 #else
 #else
-            Executer(*msgID, executerPid);
+            Executer(*msgID, pid);
 #endif
         }
 #endif
         }
-        executersPid.insert(executerPid);
+        executers.insert(pid);
     }
 return 0;
 }
     }
 return 0;
 }
@@ -160,11 +160,11 @@ int ForkAndWait(const std::string &)
 #endif
 {
 #ifndef NO_DAEMON
 #endif
 {
 #ifndef NO_DAEMON
-pid_t childPid = fork();
+pid_t pid = fork();
 std::string startFile = confDir + START_FILE;
 unlink(startFile.c_str());
 
 std::string startFile = confDir + START_FILE;
 unlink(startFile.c_str());
 
-switch (childPid)
+switch (pid)
     {
     case -1:
         return -1;
     {
     case -1:
         return -1;
@@ -198,9 +198,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 +211,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 +221,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 +246,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, &settings);
     if (ret < 0)
         {
         STG_LOGGER & WriteServLog = GetStgLogger();
     if (ret < 0)
         {
         STG_LOGGER & WriteServLog = GetStgLogger();
@@ -270,7 +265,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 +282,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 +304,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 +318,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 +329,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 +343,23 @@ while (true)
             manager.reload();
             break;
         case SIGTERM:
             manager.reload();
             break;
         case SIGTERM:
-            stop = true;
+            running = false;
             break;
         case SIGINT:
             break;
         case SIGINT:
-            stop = true;
+            running = false;
             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 +385,6 @@ KillExecuters();
 StopStgTimer();
 WriteServLog("StgTimer: Stop successfull.");
 
 StopStgTimer();
 WriteServLog("StgTimer: Stop successfull.");
 
-delete settings;
-
 WriteServLog("Stg stopped successfully.");
 WriteServLog("---------------------------------------------");
 
 WriteServLog("Stg stopped successfully.");
 WriteServLog("---------------------------------------------");
 
index 9a3dab0040f36d17ac3a0af91730bcca7cb89270..5346db8b684c9242869dd7b7012e1d2f1ef97e8c 100644 (file)
@@ -84,7 +84,7 @@ PluginManager::PluginManager(const SETTINGS_IMPL& settings,
         {
             m_log("Failed to start module '%s': '%s'", plugin.GetVersion().c_str(),
                                                        plugin.GetStrError().c_str());
         {
             m_log("Failed to start module '%s': '%s'", plugin.GetVersion().c_str(),
                                                        plugin.GetStrError().c_str());
-            printfd(__FILE__, "Failed to start module '%s': '%s'", plugin.GetVersion().c_str(),
+            printfd(__FILE__, "Failed to start module '%s': '%s'\n", plugin.GetVersion().c_str(),
                                                                    plugin.GetStrError().c_str());
         }
         else
                                                                    plugin.GetStrError().c_str());
         }
         else
@@ -105,7 +105,7 @@ PluginManager::~PluginManager()
         {
             m_log("Failed to stop module '%s': '%s'", plugin.GetVersion().c_str(),
                                                       plugin.GetStrError().c_str());
         {
             m_log("Failed to stop module '%s': '%s'", plugin.GetVersion().c_str(),
                                                       plugin.GetStrError().c_str());
-            printfd(__FILE__, "Failed to stop module '%s': '%s'", plugin.GetVersion().c_str(),
+            printfd(__FILE__, "Failed to stop module '%s': '%s'\n", plugin.GetVersion().c_str(),
                                                                   plugin.GetStrError().c_str());
         }
         else
                                                                   plugin.GetStrError().c_str());
         }
         else
index f6a40db3d3305ce123c59f43ef112ae9e1528e54..d115919d0e096142bee210b917eaa0ea7e2a4879 100644 (file)
@@ -36,48 +36,13 @@ $Author: faust $
 #include "stg/dotconfpp.h"
 #include "settings_impl.h"
 
 #include "stg/dotconfpp.h"
 #include "settings_impl.h"
 
-//-----------------------------------------------------------------------------
-SETTINGS_IMPL::SETTINGS_IMPL()
-    : SETTINGS(),
-      strError(),
-      modulesPath("/usr/lib/stg"),
-      dirName(DIR_NUM),
-      confDir("/etc/stargazer"),
-      scriptsDir("/etc/stargazer"),
-      rules("/etc/stargazer/rules"),
-      logFile("/var/log/stargazer.log"),
-      pidFile("/var/run/stargazer.pid"),
-      monitorDir("/var/stargazer/monitoring"),
-      monitoring(false),
-      detailStatWritePeriod(dsPeriod_1_6),
-      statWritePeriod(10),
-      stgExecMsgKey(5555),
-      executersNum(1),
-      fullFee(false),
-      dayFee(0),
-      dayResetTraff(0),
-      spreadFee(false),
-      freeMbAllowInet(false),
-      dayFeeIsLastDay(false),
-      writeFreeMbTraffCost(false),
-      showFeeInCash(true),
-      messageTimeout(0),
-      feeChargeType(0),
-      reconnectOnTariffChange(false),
-      modulesSettings(),
-      storeModuleSettings(),
-      logger(GetStgLogger())
-{
-}
 //-----------------------------------------------------------------------------
 SETTINGS_IMPL::SETTINGS_IMPL(const std::string & cd)
 //-----------------------------------------------------------------------------
 SETTINGS_IMPL::SETTINGS_IMPL(const std::string & cd)
-    : SETTINGS(),
-      strError(),
-      modulesPath("/usr/lib/stg"),
+    : modulesPath("/usr/lib/stg"),
       dirName(DIR_NUM),
       dirName(DIR_NUM),
-      confDir(cd),
-      scriptsDir(cd),
-      rules(cd + "/rules"),
+      confDir(cd.empty() ? "/etc/stargazer" : cd),
+      scriptsDir(confDir),
+      rules(confDir + "/rules"),
       logFile("/var/log/stargazer.log"),
       pidFile("/var/run/stargazer.pid"),
       monitorDir("/var/stargazer/monitoring"),
       logFile("/var/log/stargazer.log"),
       pidFile("/var/run/stargazer.pid"),
       monitorDir("/var/stargazer/monitoring"),
@@ -97,8 +62,6 @@ SETTINGS_IMPL::SETTINGS_IMPL(const std::string & cd)
       messageTimeout(0),
       feeChargeType(0),
       reconnectOnTariffChange(false),
       messageTimeout(0),
       feeChargeType(0),
       reconnectOnTariffChange(false),
-      modulesSettings(),
-      storeModuleSettings(),
       logger(GetStgLogger())
 {
 }
       logger(GetStgLogger())
 {
 }
index 7ba2708fd7ae6aace5260277b5421140918a2c4c..690137643bbe272e3e9089f51c22f5f0802c3ebc 100644 (file)
@@ -58,7 +58,6 @@ class DOTCONFDocumentNode;
 //-----------------------------------------------------------------------------
 class SETTINGS_IMPL : public SETTINGS {
 public:
 //-----------------------------------------------------------------------------
 class SETTINGS_IMPL : public SETTINGS {
 public:
-    SETTINGS_IMPL();
     SETTINGS_IMPL(const std::string &);
     SETTINGS_IMPL(const SETTINGS_IMPL &);
     virtual ~SETTINGS_IMPL() {}
     SETTINGS_IMPL(const std::string &);
     SETTINGS_IMPL(const SETTINGS_IMPL &);
     virtual ~SETTINGS_IMPL() {}