if (access(filePath.c_str(), X_OK) == 0)
{
std::string execString("\"" + filePath + "\" \"" + login + "\" \"" + paramName + "\" \"" + oldValue + "\" \"" + newValue + "\" \"" + admin->GetLogin() + "\" \"" + admin->GetIPStr() + "\"");
- ScriptExec(execString);
+ ScriptExec(execString.c_str());
}
else
{
printfd(__FILE__, "Connect %s\n", data.login.c_str());
if (access(scriptOnConnect.c_str(), X_OK) == 0)
{
- if (ScriptExec(scriptOnConnect + " " + data.params))
+ if (ScriptExec((scriptOnConnect + " " + data.params).c_str()))
{
WriteServLog("Script %s cannot be executed for an unknown reason.", scriptOnConnect.c_str());
return true;
printfd(__FILE__, "Disconnect %s\n", data.login.c_str());
if (access(scriptOnDisconnect.c_str(), X_OK) == 0)
{
- if (ScriptExec(scriptOnDisconnect + " " + data.params))
+ if (ScriptExec((scriptOnDisconnect + " " + data.params).c_str()))
{
WriteServLog("Script %s cannot be executed for an unknown reson.", scriptOnDisconnect.c_str());
return true;
//close(1);
//close(2);
//setsid();
- Executer(msgKey, *msgID, executerPid, procName);
+ Executer(*msgID, executerPid, procName);
return 1;
default: // Parent
if (executersPid.empty())
- Executer(msgKey, *msgID, executerPid, NULL);
+ Executer(*msgID, executerPid, NULL);
executersPid.insert(executerPid);
}
return 0;
LIB_NAME = stgscriptexecuter
-SRCS = scriptexecuter.cpp
+SRCS = scriptexecuter.c
INCS = scriptexecuter.h
--- /dev/null
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <string.h>
+#include <errno.h>
+#include <signal.h>
+
+#include "scriptexecuter.h"
+
+
+#define MAX_SCRIPT_LEN (1100)
+
+static int msgid;
+static int nonstop;
+
+//-----------------------------------------------------------------------------
+struct SCRIPT_DATA
+{
+ long mtype;
+ char script[MAX_SCRIPT_LEN];
+} sd;
+//-----------------------------------------------------------------------------
+static void CatchUSR1Executer()
+{
+nonstop = 0;
+}
+//-----------------------------------------------------------------------------
+int ScriptExec(const char * str)
+{
+if (strlen(str) >= MAX_SCRIPT_LEN)
+ return -1;
+
+strncpy(sd.script, str, MAX_SCRIPT_LEN);
+sd.mtype = 1;
+if (msgsnd(msgid, (void *)&sd, MAX_SCRIPT_LEN, 0) < 0)
+ return -1;
+
+return 0;
+}
+//-----------------------------------------------------------------------------
+#ifdef LINUX
+void Executer(int msgID, pid_t pid, char * procName)
+#else
+void Executer(int msgID, pid_t pid)
+#endif
+{
+msgid = msgID;
+if (pid)
+ return;
+nonstop = 1;
+
+#ifdef LINUX
+memset(procName, 0, strlen(procName));
+strcpy(procName, "stg-exec");
+#else
+setproctitle("stg-exec");
+#endif
+
+struct sigaction newsa, oldsa;
+sigset_t sigmask;
+
+sigemptyset(&sigmask);
+sigaddset(&sigmask, SIGTERM);
+newsa.sa_handler = SIG_IGN;
+newsa.sa_mask = sigmask;
+newsa.sa_flags = 0;
+sigaction(SIGTERM, &newsa, &oldsa);
+
+sigemptyset(&sigmask);
+sigaddset(&sigmask, SIGINT);
+newsa.sa_handler = SIG_IGN;
+newsa.sa_mask = sigmask;
+newsa.sa_flags = 0;
+sigaction(SIGINT, &newsa, &oldsa);
+
+sigemptyset(&sigmask);
+sigaddset(&sigmask, SIGHUP);
+newsa.sa_handler = SIG_IGN;
+newsa.sa_mask = sigmask;
+newsa.sa_flags = 0;
+sigaction(SIGHUP, &newsa, &oldsa);
+
+sigemptyset(&sigmask);
+sigaddset(&sigmask, SIGUSR1);
+newsa.sa_handler = CatchUSR1Executer;
+newsa.sa_mask = sigmask;
+newsa.sa_flags = 0;
+sigaction(SIGUSR1, &newsa, &oldsa);
+
+int ret;
+
+struct SCRIPT_DATA sd;
+
+while (nonstop)
+ {
+ sd.mtype = 1;
+ ret = msgrcv(msgid, &sd, MAX_SCRIPT_LEN, 0, 0);
+
+ if (ret < 0)
+ {
+ usleep(20000);
+ continue;
+ }
+ int ret = system(sd.script);
+ if (ret == -1)
+ {
+ // Fork failed
+ }
+ }
+}
+//-----------------------------------------------------------------------------
+++ /dev/null
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/msg.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <cstring>
-#include <cerrno>
-#include <csignal>
-
-#include "stg/common.h"
-#include "scriptexecuter.h"
-
-using namespace std;
-
-#define MAX_SCRIPT_LEN (1100)
-
-static int msgid;
-static bool nonstop;
-
-//-----------------------------------------------------------------------------
-struct SCRIPT_DATA
-{
- long mtype;
- char script[MAX_SCRIPT_LEN];
-} sd;
-//-----------------------------------------------------------------------------
-static void CatchUSR1Executer(int)
-{
-nonstop = false;
-}
-//-----------------------------------------------------------------------------
-int ScriptExec(const string & str)
-{
-if (str.length() >= MAX_SCRIPT_LEN)
- {
- printfd(__FILE__, "ScriptExec() - script params exceeds MAX_SCRIPT_LENGTH (%d > %d)\n", str.length(), MAX_SCRIPT_LEN);
- return -1;
- }
-
-strncpy(sd.script, str.c_str(), MAX_SCRIPT_LEN);
-sd.mtype = 1;
-if (msgsnd(msgid, (void *)&sd, MAX_SCRIPT_LEN, 0) < 0)
- {
- printfd(__FILE__, "ScriptExec() - failed to send message to the IPC queue: '%s'\n", strerror(errno));
- return -1;
- }
-return 0;
-}
-//-----------------------------------------------------------------------------
-#ifdef LINUX
-void Executer(int, int msgID, pid_t pid, char * procName)
-#else
-void Executer(int, int msgID, pid_t pid, char *)
-#endif
-{
-msgid = msgID;
-if (pid)
- return;
-nonstop = true;
-
-#ifdef LINUX
-memset(procName, 0, strlen(procName));
-strcpy(procName, "stg-exec");
-#else
-setproctitle("stg-exec");
-#endif
-
-struct sigaction newsa, oldsa;
-sigset_t sigmask;
-
-sigemptyset(&sigmask);
-sigaddset(&sigmask, SIGTERM);
-newsa.sa_handler = SIG_IGN;
-newsa.sa_mask = sigmask;
-newsa.sa_flags = 0;
-sigaction(SIGTERM, &newsa, &oldsa);
-
-sigemptyset(&sigmask);
-sigaddset(&sigmask, SIGINT);
-newsa.sa_handler = SIG_IGN;
-newsa.sa_mask = sigmask;
-newsa.sa_flags = 0;
-sigaction(SIGINT, &newsa, &oldsa);
-
-sigemptyset(&sigmask);
-sigaddset(&sigmask, SIGHUP);
-newsa.sa_handler = SIG_IGN;
-newsa.sa_mask = sigmask;
-newsa.sa_flags = 0;
-sigaction(SIGHUP, &newsa, &oldsa);
-
-sigemptyset(&sigmask);
-sigaddset(&sigmask, SIGUSR1);
-newsa.sa_handler = CatchUSR1Executer;
-newsa.sa_mask = sigmask;
-newsa.sa_flags = 0;
-sigaction(SIGUSR1, &newsa, &oldsa);
-
-int ret;
-
-SCRIPT_DATA sd;
-
-while (nonstop)
- {
- sd.mtype = 1;
- ret = msgrcv(msgid, &sd, MAX_SCRIPT_LEN, 0, 0);
-
- if (ret < 0)
- {
- usleep(20000);
- continue;
- }
- int ret = system(sd.script);
- if (ret == -1)
- {
- // Fork failed
- }
- }
-}
-//-----------------------------------------------------------------------------
#ifndef SCRIPT_EXECUTER_H
#define SCRIPT_EXECUTER_H
-#include <string>
+#ifdef __cplusplus
+extern "C" {
+#endif
-int ScriptExec(const std::string & str);
-void Executer(int msgKey, int msgID, pid_t pid, char * procName);
+int ScriptExec(const char * str);
+#ifdef LINUX
+void Executer(int msgID, pid_t pid, char * procName);
+#else
+void Executer(int msgID, pid_t pid);
+#endif
-#endif //SCRIPT_EXECUTER_H
+#ifdef __cplusplus
+}
+#endif
+
+#endif