11 #include "stg/scriptexecuter.h"
13 #define MAX_SCRIPT_LEN (1100)
18 //-----------------------------------------------------------------------------
22 char script[MAX_SCRIPT_LEN];
24 //-----------------------------------------------------------------------------
25 static void CatchUSR1Executer()
29 //-----------------------------------------------------------------------------
30 int ScriptExec(const char * str)
32 if (strlen(str) >= MAX_SCRIPT_LEN)
35 strncpy(sd.script, str, MAX_SCRIPT_LEN);
37 if (msgsnd(msgid, (void *)&sd, MAX_SCRIPT_LEN, 0) < 0)
42 //-----------------------------------------------------------------------------
43 #if defined(LINUX) || defined(DARWIN)
44 void Executer(int msgID, pid_t pid, char * procName)
46 void Executer(int msgID, pid_t pid)
49 struct SCRIPT_DATA sd;
50 struct sigaction newsa, oldsa;
58 #if defined(LINUX) || defined(DARWIN)
59 memset(procName, 0, strlen(procName));
60 strcpy(procName, "stg-exec");
62 setproctitle("stg-exec");
65 sigemptyset(&sigmask);
66 sigaddset(&sigmask, SIGTERM);
67 newsa.sa_handler = SIG_IGN;
68 newsa.sa_mask = sigmask;
70 sigaction(SIGTERM, &newsa, &oldsa);
72 sigemptyset(&sigmask);
73 sigaddset(&sigmask, SIGINT);
74 newsa.sa_handler = SIG_IGN;
75 newsa.sa_mask = sigmask;
77 sigaction(SIGINT, &newsa, &oldsa);
79 sigemptyset(&sigmask);
80 sigaddset(&sigmask, SIGHUP);
81 newsa.sa_handler = SIG_IGN;
82 newsa.sa_mask = sigmask;
84 sigaction(SIGHUP, &newsa, &oldsa);
86 sigemptyset(&sigmask);
87 sigaddset(&sigmask, SIGUSR1);
88 newsa.sa_handler = CatchUSR1Executer;
89 newsa.sa_mask = sigmask;
91 sigaction(SIGUSR1, &newsa, &oldsa);
96 int ret = msgrcv(msgid, &sd, MAX_SCRIPT_LEN, 0, 0);
103 ret = system(sd.script);
110 //-----------------------------------------------------------------------------