9#include "daq/rfarm/manager/RFProcessManager.h"
10#include "daq/rfarm/manager/RFNSM.h"
21#include <nsm2/nsmlib2.h>
22#include <nsm2/nsmsys2.h>
34RFProcessManager::RFProcessManager(
char* )
37 if (pipe2(m_iopipe, O_NONBLOCK) < 0) {
39 m_iopipe[0] = -1; m_iopipe[1] = -1;
41 FILE* f = fopen(
"pid.data",
"w");
43 fprintf(f,
"%d", getpid());
48RFProcessManager::~RFProcessManager()
52void RFProcessManager::signal_handler(
int )
60 printf(
"RFProcessManager : Execute : scr=%s, nargs=%d\n", scr, nargs);
63 if (pid == (pid_t) 0) {
68 strcpy(argbuf[0], scr);
69 argval[nargval++] = argbuf[0];
71 for (
int i = 0; i < nargs; i++) {
72 strcpy(argbuf[nargval], args[i]);
73 argval[nargval] = argbuf[nargval];
77 argval[nargval] = NULL;
87 printf(
"RFProcessManager : invoking %s\n", scr);
88 for (
int i = 0; i < 10; i++) {
89 if (argval[i] == NULL)
break;
90 printf(
"argval[%d] = %s\n", i, argval[i]);
96 fprintf(stderr,
"missing file : %s\n", scr);
101 printf(
"RFProcessManager : forked. pid=%d\n", pid);
104 m_pidlist.push_back(pid);
109 char* arg0,
char* arg1,
char* arg2,
char* arg3,
110 char* arg4,
char* arg5,
char* arg6,
char* arg7)
146 return Execute(scr, narg, arglist);
149int RFProcessManager::CheckOutput()
159 if (m_iopipe[0] > 0) {
160 FD_SET(m_iopipe[0], &fdset);
161 highest = m_iopipe[0];
163 printf(
"Pipe for log is not availablle\n");
165 NSMcontext* nsmc = RFNSM::GetContext();
167 if (nsmc->sock > highest) highest = nsmc->sock;
168 FD_SET(nsmc->sock, &fdset);
177 if ((nfd = select(highest + 1, &fdset, NULL, NULL, &tv)) < 0) {
179 case EINTR:
continue;
180 case EAGAIN:
continue;
187 if (nsmc && FD_ISSET(nsmc->sock, &fdset)) {
189 char buf[NSM_TCPMSGSIZ];
190 if (nsmlib_recv(nsmc,
reinterpret_cast<struct NSMtcphead_struct*
>(buf), 1000) < 0)
191 printf(
"RFProcessManager: Failed to read NSM context\n");
193 nsmlib_call(nsmc,
reinterpret_cast<struct NSMtcphead_struct*
>(buf));
195 if (m_iopipe[0] > 0 &&
196 FD_ISSET(m_iopipe[0], &fdset)) {
209int RFProcessManager::GetFd()
214pid_t RFProcessManager::CheckProcess()
216 for (vector<pid_t>::iterator it = m_pidlist.begin(); it != m_pidlist.end(); ++it) {
219 pid_t outpid = waitpid(pid, &status, WNOHANG);
221 if (outpid != 0 || outpid == pid) {
int Execute(char *script, int nargs, char **args)
Abstract base class for different kinds of events.