Line data Source code
1 : #include "ErrorHandler/MessageAnalyzer/ma_action_script.h"
2 :
3 : #include <unistd.h>
4 : // #include <sys/types.h>
5 : #include <sys/wait.h>
6 :
7 : using namespace novadaq::errorhandler;
8 :
9 0 : REG_MA_ACTION(script, ma_action_script)
10 :
11 : namespace {
12 :
13 0 : int RunCommand(std::string const& strCmd, std::string const& strParam)
14 : {
15 : int iForkId, iStatus;
16 0 : iForkId = vfork();
17 0 : if (iForkId == 0) // This is the child
18 : {
19 0 : std::string command = strCmd + " " + strParam;
20 :
21 0 : iStatus = execl("/bin/sh", "sh", "-c", command.c_str(), (char*)NULL);
22 0 : exit(iStatus); // We must exit here,
23 : // or we will have multiple
24 : // mainlines running...
25 : }
26 0 : else if (iForkId > 0) // Parent, no error
27 : {
28 0 : iStatus = 0;
29 0 : waitpid(iForkId, &iStatus, 0);
30 : }
31 : else // Parent, with error (iForkId == -1)
32 : {
33 0 : iStatus = -1;
34 : }
35 0 : return (iStatus);
36 : }
37 :
38 : } // namespace
39 :
40 0 : ma_action_script::ma_action_script(ma_rule const* rule, pset_t const& pset)
41 0 : : ma_action(rule, pset)
42 : {
43 0 : script_name = pset.get<std::string>("name");
44 0 : script_para = pset.get<std::string>("param", std::string());
45 :
46 0 : param.init(rule, script_para);
47 0 : }
48 :
49 0 : bool ma_action_script::exec()
50 : {
51 0 : RunCommand(script_name, param.message());
52 0 : return true;
53 : }
|