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");
42 fprintf(f,
"%d", getpid());
46RFProcessManager::~RFProcessManager()
50void RFProcessManager::signal_handler(
int )
58 printf(
"RFProcessManager : Execute : scr=%s, nargs=%d\n", scr, nargs);
61 if (pid == (pid_t) 0) {
66 strcpy(argbuf[0], scr);
67 argval[nargval++] = argbuf[0];
69 for (
int i = 0; i < nargs; i++) {
70 strcpy(argbuf[nargval], args[i]);
71 argval[nargval] = argbuf[nargval];
75 argval[nargval] = NULL;
85 printf(
"RFProcessManager : invoking %s\n", scr);
86 for (
int i = 0; i < 10; i++) {
87 if (argval[i] == NULL)
break;
88 printf(
"argval[%d] = %s\n", i, argval[i]);
94 fprintf(stderr,
"missing file : %s\n", scr);
99 printf(
"RFProcessManager : forked. pid=%d\n", pid);
102 m_pidlist.push_back(pid);
107 char* arg0,
char* arg1,
char* arg2,
char* arg3,
108 char* arg4,
char* arg5,
char* arg6,
char* arg7)
144 return Execute(scr, narg, arglist);
147int RFProcessManager::CheckOutput()
157 if (m_iopipe[0] > 0) {
158 FD_SET(m_iopipe[0], &fdset);
159 highest = m_iopipe[0];
161 printf(
"Pipe for log is not availablle\n");
165 if (nsmc->sock > highest) highest = nsmc->sock;
166 FD_SET(nsmc->sock, &fdset);
175 if ((nfd = select(highest + 1, &fdset, NULL, NULL, &tv)) < 0) {
177 case EINTR:
continue;
178 case EAGAIN:
continue;
185 if (nsmc && FD_ISSET(nsmc->sock, &fdset)) {
187 char buf[NSM_TCPMSGSIZ];
189 printf(
"RFProcessManager: Failed to read NSM context\n");
193 if (m_iopipe[0] > 0 &&
194 FD_ISSET(m_iopipe[0], &fdset)) {
207int RFProcessManager::GetFd()
212pid_t RFProcessManager::CheckProcess()
214 for (vector<pid_t>::iterator it = m_pidlist.begin(); it != m_pidlist.end(); ++it) {
217 pid_t outpid = waitpid(pid, &status, WNOHANG);
219 if (outpid != 0 || outpid == pid) {
int Execute(char *script, int nargs, char **args)
Abstract base class for different kinds of events.