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 //-----------------------------------------------------------------------------
44 void Executer(int msgID, pid_t pid, char * procName)
46 void Executer(int msgID, pid_t pid)
50 struct SCRIPT_DATA sd;
51 struct sigaction newsa, oldsa;
60 memset(procName, 0, strlen(procName));
61 strcpy(procName, "stg-exec");
63 setproctitle("stg-exec");
66 sigemptyset(&sigmask);
67 sigaddset(&sigmask, SIGTERM);
68 newsa.sa_handler = SIG_IGN;
69 newsa.sa_mask = sigmask;
71 sigaction(SIGTERM, &newsa, &oldsa);
73 sigemptyset(&sigmask);
74 sigaddset(&sigmask, SIGINT);
75 newsa.sa_handler = SIG_IGN;
76 newsa.sa_mask = sigmask;
78 sigaction(SIGINT, &newsa, &oldsa);
80 sigemptyset(&sigmask);
81 sigaddset(&sigmask, SIGHUP);
82 newsa.sa_handler = SIG_IGN;
83 newsa.sa_mask = sigmask;
85 sigaction(SIGHUP, &newsa, &oldsa);
87 sigemptyset(&sigmask);
88 sigaddset(&sigmask, SIGUSR1);
89 newsa.sa_handler = CatchUSR1Executer;
90 newsa.sa_mask = sigmask;
92 sigaction(SIGUSR1, &newsa, &oldsa);
97 ret = msgrcv(msgid, &sd, MAX_SCRIPT_LEN, 0, 0);
104 ret = system(sd.script);
111 //-----------------------------------------------------------------------------