11 #include "stg/common.h"
12 #include "scriptexecuter.h"
16 #define MAX_SCRIPT_LEN (1100)
21 //-----------------------------------------------------------------------------
25 char script[MAX_SCRIPT_LEN];
27 //-----------------------------------------------------------------------------
28 static void CatchUSR1Executer(int)
32 //-----------------------------------------------------------------------------
33 int ScriptExec(const string & str)
35 if (str.length() >= MAX_SCRIPT_LEN)
37 printfd(__FILE__, "ScriptExec() - script params exceeds MAX_SCRIPT_LENGTH (%d > %d)\n", str.length(), MAX_SCRIPT_LEN);
41 strncpy(sd.script, str.c_str(), MAX_SCRIPT_LEN);
43 if (msgsnd(msgid, (void *)&sd, MAX_SCRIPT_LEN, 0) < 0)
45 printfd(__FILE__, "ScriptExec() - failed to send message to the IPC queue: '%s'\n", strerror(errno));
50 //-----------------------------------------------------------------------------
52 void Executer(int, int msgID, pid_t pid, char * procName)
54 void Executer(int, int msgID, pid_t pid, char *)
63 memset(procName, 0, strlen(procName));
64 strcpy(procName, "stg-exec");
66 setproctitle("stg-exec");
69 struct sigaction newsa, oldsa;
72 sigemptyset(&sigmask);
73 sigaddset(&sigmask, SIGTERM);
74 newsa.sa_handler = SIG_IGN;
75 newsa.sa_mask = sigmask;
77 sigaction(SIGTERM, &newsa, &oldsa);
79 sigemptyset(&sigmask);
80 sigaddset(&sigmask, SIGINT);
81 newsa.sa_handler = SIG_IGN;
82 newsa.sa_mask = sigmask;
84 sigaction(SIGINT, &newsa, &oldsa);
86 sigemptyset(&sigmask);
87 sigaddset(&sigmask, SIGHUP);
88 newsa.sa_handler = SIG_IGN;
89 newsa.sa_mask = sigmask;
91 sigaction(SIGHUP, &newsa, &oldsa);
93 sigemptyset(&sigmask);
94 sigaddset(&sigmask, SIGUSR1);
95 newsa.sa_handler = CatchUSR1Executer;
96 newsa.sa_mask = sigmask;
98 sigaction(SIGUSR1, &newsa, &oldsa);
107 ret = msgrcv(msgid, &sd, MAX_SCRIPT_LEN, 0, 0);
114 int ret = system(sd.script);
121 //-----------------------------------------------------------------------------