11 #include "scriptexecuter.h"
14 #define MAX_SCRIPT_LEN (1100)
19 //-----------------------------------------------------------------------------
23 char script[MAX_SCRIPT_LEN];
25 //-----------------------------------------------------------------------------
26 static void CatchUSR1Executer()
30 //-----------------------------------------------------------------------------
31 int ScriptExec(const char * str)
33 if (strlen(str) >= MAX_SCRIPT_LEN)
36 strncpy(sd.script, str, MAX_SCRIPT_LEN);
38 if (msgsnd(msgid, (void *)&sd, MAX_SCRIPT_LEN, 0) < 0)
43 //-----------------------------------------------------------------------------
45 void Executer(int msgID, pid_t pid, char * procName)
47 void Executer(int msgID, pid_t pid)
56 memset(procName, 0, strlen(procName));
57 strcpy(procName, "stg-exec");
59 setproctitle("stg-exec");
62 struct sigaction newsa, oldsa;
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);
95 struct SCRIPT_DATA sd;
100 ret = msgrcv(msgid, &sd, MAX_SCRIPT_LEN, 0, 0);
107 int ret = system(sd.script);
114 //-----------------------------------------------------------------------------