X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/53c1823aaef2eb8d547a8eed8cfe12fe7204ca79..f91192c77eec33a27dea7fcd0d451823ef478529:/projects/stargazer/plugins/other/rscript/rscript.cpp diff --git a/projects/stargazer/plugins/other/rscript/rscript.cpp b/projects/stargazer/plugins/other/rscript/rscript.cpp index c1d66051..f7479da6 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.cpp +++ b/projects/stargazer/plugins/other/rscript/rscript.cpp @@ -30,12 +30,15 @@ #include #include #include +#include +#include #include #include "stg/common.h" #include "stg/locker.h" #include "stg/user_property.h" #include "stg/plugin_creator.h" +#include "stg/logger.h" #include "rscript.h" #include "ur_functor.h" #include "send_functor.h" @@ -149,19 +152,13 @@ subnetFile = pvi->value[0]; NRMapParser nrMapParser; -if (nrMapParser.ReadFile(subnetFile)) +if (!nrMapParser.ReadFile(subnetFile)) { - errorStr = nrMapParser.GetErrorStr(); - return -1; + netRouters = nrMapParser.GetMap(); } - -netRouters = nrMapParser.GetMap(); - -if (netRouters.empty()) +else { - errorStr = "Parameter(s) \'Subnet*\' not found."; - printfd(__FILE__, "Parameter(s) 'Subnet*' not found\n"); - return -1; + GetStgLogger()("mod_rscript: error opening subnets file '%s'", subnetFile.c_str()); } return 0; @@ -186,7 +183,8 @@ REMOTE_SCRIPT::REMOTE_SCRIPT() mutex(), sock(0), onAddUserNotifier(*this), - onDelUserNotifier(*this) + onDelUserNotifier(*this), + logger(GetPluginLogger(GetStgLogger(), "rscript")) { pthread_mutex_init(&mutex, NULL); } @@ -198,6 +196,10 @@ pthread_mutex_destroy(&mutex); //----------------------------------------------------------------------------- void * REMOTE_SCRIPT::Run(void * d) { +sigset_t signalSet; +sigfillset(&signalSet); +pthread_sigmask(SIG_BLOCK, &signalSet, NULL); + REMOTE_SCRIPT * rs = static_cast(d); rs->isRunning = true; @@ -253,6 +255,7 @@ if (!isRunning) if (pthread_create(&thread, NULL, Run, this)) { errorStr = "Cannot create thread."; + logger("Cannot create thread."); printfd(__FILE__, "Cannot create thread\n"); return -1; } @@ -285,23 +288,17 @@ if (isRunning) struct timespec ts = {0, 200000000}; nanosleep(&ts, NULL); } - - //after 5 seconds waiting thread still running. now killing it - if (isRunning) - { - if (pthread_kill(thread, SIGINT)) - { - errorStr = "Cannot kill thread."; - printfd(__FILE__, "Cannot kill thread\n"); - return -1; - } - printfd(__FILE__, "REMOTE_SCRIPT killed Run\n"); - } } users->DelNotifierUserDel(&onDelUserNotifier); users->DelNotifierUserAdd(&onAddUserNotifier); +if (isRunning) + { + logger("Cannot stop thread."); + return -1; + } + return 0; } //----------------------------------------------------------------------------- @@ -312,6 +309,7 @@ NRMapParser nrMapParser; if (nrMapParser.ReadFile(rsSettings.GetMapFileName())) { errorStr = nrMapParser.GetErrorStr(); + logger("Map file reading error: %s", errorStr.c_str()); return -1; } @@ -337,6 +335,7 @@ sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { errorStr = "Cannot create socket."; + logger("Canot create a socket: %s", strerror(errno)); printfd(__FILE__, "Cannot create socket\n"); return true; } @@ -474,6 +473,9 @@ sendAddr.sin_addr.s_addr = routerIP; int res = sendto(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&sendAddr, sizeof(sendAddr)); +if (res < 0) + logger("sendto error: %s", strerror(errno)); + return (res != sizeof(buffer)); } //----------------------------------------------------------------------------- @@ -482,12 +484,7 @@ bool REMOTE_SCRIPT::GetUsers() USER_PTR u; int h = users->OpenSearch(); -if (!h) - { - errorStr = "users->OpenSearch() error."; - printfd(__FILE__, "OpenSearch() error\n"); - return true; - } +assert(h && "USERS::OpenSearch is always correct"); while (!users->SearchNext(h, &u)) {