#include <csignal>
#include <cassert>
#include <cstdlib>
+#include <cerrno>
+#include <cstring>
#include <algorithm>
#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"
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;
mutex(),
sock(0),
onAddUserNotifier(*this),
- onDelUserNotifier(*this)
+ onDelUserNotifier(*this),
+ logger(GetPluginLogger(GetStgLogger(), "rscript"))
{
pthread_mutex_init(&mutex, NULL);
}
//-----------------------------------------------------------------------------
void * REMOTE_SCRIPT::Run(void * d)
{
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
REMOTE_SCRIPT * rs = static_cast<REMOTE_SCRIPT *>(d);
rs->isRunning = true;
if (pthread_create(&thread, NULL, Run, this))
{
errorStr = "Cannot create thread.";
+ logger("Cannot create thread.");
printfd(__FILE__, "Cannot create thread\n");
return -1;
}
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;
}
//-----------------------------------------------------------------------------
if (nrMapParser.ReadFile(rsSettings.GetMapFileName()))
{
errorStr = nrMapParser.GetErrorStr();
+ logger("Map file reading error: %s", errorStr.c_str());
return -1;
}
if (sock < 0)
{
errorStr = "Cannot create socket.";
+ logger("Canot create a socket: %s", strerror(errno));
printfd(__FILE__, "Cannot create socket\n");
return true;
}
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));
}
//-----------------------------------------------------------------------------
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))
{