artdaq_mfextensions  v1_06_02
ma_action_script.cpp
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 REG_MA_ACTION(script, ma_action_script)
10 
11 namespace {
12 
13 int RunCommand(std::string const& strCmd, std::string const& strParam)
14 {
15  int iForkId, iStatus;
16  iForkId = vfork();
17  if (iForkId == 0) // This is the child
18  {
19  std::string command = strCmd + " " + strParam;
20 
21  iStatus = execl("/bin/sh", "sh", "-c", command.c_str(), (char*)NULL);
22  exit(iStatus); // We must exit here,
23  // or we will have multiple
24  // mainlines running...
25  }
26  else if (iForkId > 0) // Parent, no error
27  {
28  iStatus = 0;
29  waitpid(iForkId, &iStatus, 0);
30  }
31  else // Parent, with error (iForkId == -1)
32  {
33  iStatus = -1;
34  }
35  return (iStatus);
36 }
37 
38 } // namespace
39 
40 ma_action_script::ma_action_script(ma_rule const* rule, pset_t const& pset)
41  : ma_action(rule, pset)
42 {
43  script_name = pset.get<std::string>("name");
44  script_para = pset.get<std::string>("param", std::string());
45 
46  param.init(rule, script_para);
47 }
48 
49 bool ma_action_script::exec()
50 {
51  RunCommand(script_name, param.message());
52  return true;
53 }
base class - all customized fucntions are inherited from it
Definition: ma_action.h:25