X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/a622b081808494796d3679acaebbf5ee364fe9de..1c529746ff07312e30e76fd933c628c658e3c77d:/projects/rscriptd/main.cpp diff --git a/projects/rscriptd/main.cpp b/projects/rscriptd/main.cpp index 93e1d605..1baca9e8 100644 --- a/projects/rscriptd/main.cpp +++ b/projects/rscriptd/main.cpp @@ -48,8 +48,6 @@ #include "listener.h" #include "pidfile.h" -using namespace std; - #ifdef DEBUG # define MAIN_DEBUG 1 # define NO_DAEMON 1 @@ -57,13 +55,13 @@ using namespace std; #define START_FILE "/._ST_ART_ED_" -set executersPid; +std::set executersPid; volatile time_t stgTime = time(NULL); //----------------------------------------------------------------------------- void KillExecuters() { -set::iterator pid; +std::set::iterator pid; pid = executersPid.begin(); while (pid != executersPid.end()) { @@ -73,9 +71,13 @@ while (pid != executersPid.end()) } } //----------------------------------------------------------------------------- +#if defined(LINUX) || defined(DARWIN) int StartScriptExecuter(char * procName, int msgKey, int * msgID) +#else +int StartScriptExecuter(char *, int msgKey, int * msgID) +#endif { -STG_LOGGER & WriteServLog = GetStgLogger(); +auto & WriteServLog = STG::Logger::get(); if (*msgID == -11) // If msgID == -11 - first call. Create queue { @@ -117,12 +119,20 @@ switch (executerPid) //close(1); //close(2); //setsid(); +#if defined(LINUX) || defined(DARWIN) Executer(*msgID, executerPid, procName); +#else + Executer(*msgID, executerPid); +#endif return 1; default: // Parent if (executersPid.empty()) +#if defined(LINUX) || defined(DARWIN) Executer(*msgID, executerPid, NULL); +#else + Executer(*msgID, executerPid); +#endif executersPid.insert(executerPid); } return 0; @@ -130,7 +140,7 @@ return 0; //----------------------------------------------------------------------------- void StopScriptExecuter(int msgID) { -STG_LOGGER & WriteServLog = GetStgLogger(); +auto & WriteServLog = STG::Logger::get(); for (int i = 0; i < 5; ++i) { @@ -166,11 +176,7 @@ else KillExecuters(); } //----------------------------------------------------------------------------- -#ifdef NO_DAEMON -int ForkAndWait(const string &) -#else -int ForkAndWait(const string & confDir) -#endif +int ForkAndWait() { #ifndef NO_DAEMON pid_t childPid = fork(); @@ -204,11 +210,11 @@ int msgID = -11; int execNum = 0; int execMsgKey = 0; -string logFileName; -string confDir; -string password; -string onConnect; -string onDisconnect; +std::string logFileName; +std::string confDir; +std::string password; +std::string onConnect; +std::string onDisconnect; int port; int userTimeout; @@ -225,8 +231,8 @@ else if (cfg->Error()) { - STG_LOGGER & WriteServLog = GetStgLogger(); - WriteServLog.SetLogFileName("/var/log/rscriptd.log"); + auto & WriteServLog = STG::Logger::get(); + WriteServLog.setFileName("/var/log/rscriptd.log"); WriteServLog("Error reading config file!"); delete cfg; return EXIT_FAILURE; @@ -242,17 +248,17 @@ cfg->ReadInt("UserTimeout", &userTimeout, 60); cfg->ReadString("ScriptOnConnect", &onConnect, "/etc/rscriptd/OnConnect"); cfg->ReadString("ScriptOnDisconnect", &onDisconnect, "/etc/rscriptd/OnDisconnect"); -if (ForkAndWait(confDir) < 0) +if (ForkAndWait() < 0) { - STG_LOGGER & WriteServLog = GetStgLogger(); + auto & WriteServLog = STG::Logger::get(); WriteServLog("Fork error!"); delete cfg; return EXIT_FAILURE; } -STG_LOGGER & WriteServLog = GetStgLogger(); +auto & WriteServLog = STG::Logger::get(); PIDFile pidFile("/var/run/rscriptd.pid"); -WriteServLog.SetLogFileName(logFileName); +WriteServLog.setFileName(logFileName); WriteServLog("rscriptd v. %s", SERVER_VERSION); for (int i = 0; i < execNum; i++) @@ -260,8 +266,7 @@ for (int i = 0; i < execNum; i++) int ret = StartScriptExecuter(argv[0], execMsgKey, &msgID); if (ret < 0) { - STG_LOGGER & WriteServLog = GetStgLogger(); - WriteServLog("Start Script Executer error!"); + STG::Logger::get()("Start Script Executer error!"); delete cfg; return EXIT_FAILURE; }