11 #include "script_executer.h"
15 #define MAX_SCRIPT_LEN (1100)
20 //-----------------------------------------------------------------------------
24 char script[MAX_SCRIPT_LEN];
26 //-----------------------------------------------------------------------------
27 static void CatchUSR1Executer(int)
31 //-----------------------------------------------------------------------------
32 int ScriptExec(const string & str)
34 if (str.length() >= MAX_SCRIPT_LEN)
38 strncpy(sd.script, str.c_str(), MAX_SCRIPT_LEN);
40 ret = msgsnd(msgid, (void *)&sd, MAX_SCRIPT_LEN, 0);
47 //-----------------------------------------------------------------------------
49 void Executer(int, int msgID, pid_t pid, char * procName)
51 void Executer(int, int msgID, pid_t pid, char *)
60 memset(procName, 0, strlen(procName));
61 strcpy(procName, "stg-exec");
63 setproctitle("stg-exec");
66 struct sigaction newsa, oldsa;
69 sigemptyset(&sigmask);
70 sigaddset(&sigmask, SIGTERM);
71 newsa.sa_handler = SIG_IGN;
72 newsa.sa_mask = sigmask;
74 sigaction(SIGTERM, &newsa, &oldsa);
76 sigemptyset(&sigmask);
77 sigaddset(&sigmask, SIGINT);
78 newsa.sa_handler = SIG_IGN;
79 newsa.sa_mask = sigmask;
81 sigaction(SIGINT, &newsa, &oldsa);
83 sigemptyset(&sigmask);
84 sigaddset(&sigmask, SIGHUP);
85 newsa.sa_handler = SIG_IGN;
86 newsa.sa_mask = sigmask;
88 sigaction(SIGHUP, &newsa, &oldsa);
90 sigemptyset(&sigmask);
91 sigaddset(&sigmask, SIGUSR1);
92 newsa.sa_handler = CatchUSR1Executer;
93 newsa.sa_mask = sigmask;
95 sigaction(SIGUSR1, &newsa, &oldsa);
104 ret = msgrcv(msgid, &sd, MAX_SCRIPT_LEN, 0, 0);
111 int ret = system(sd.script);
118 //-----------------------------------------------------------------------------