37 std::string startupMsg =
"startup:";
38 for (i = 0; i < ac; i++)
51 memset(&sa, 0,
sizeof(sa));
52 sa.sa_handler = SIG_IGN;
53 sigemptyset(&sa.sa_mask);
54 (void)sigaction(SIGPIPE, &sa, NULL);
72 strftime(s,
sizeof(sbuf),
"%Y-%m-%dT%H:%M:%S", tp);
100 fp = fopen(logfn,
"a");
103 fprintf(fp,
"%s: %s: %s\n", ts, dev, ms);
110 fprintf(stderr,
"%s: good bye\n",
indi_tstamp(NULL));
116 std::string sizeStr =
findXMLAttValu(blobWithAttachedBuffer,
"size");
122 size = std::stoll(sizeStr, &pos, 10);
123 if (pos != sizeStr.size())
125 log(
"Invalid size attribute value " + sizeStr);
133 auto map = (
const std::unordered_map<XMLEle*, XMLEle*> *) self;
134 auto idx = map->find(source);
135 if (idx == map->end())
139 *replace = (
XMLEle*)idx->second;
150 std::vector<XMLEle *> result;
153 if (strcmp(
tagXMLEle(ep),
"oneBLOB") == 0)
155 result.push_back(ep);
164 fprintf(stderr,
"%s",
log.c_str());
175 iov.iov_base = &rcvbuf;
176 iov.iov_len =
sizeof(rcvbuf);
178 msg.msg_name =
nullptr;
183 msg.msg_control = cbuf;
184 msg.msg_controllen =
sizeof(cbuf);
186 int recv_bytes = recvmsg(
fd, &msg, MSG_ERRQUEUE | MSG_DONTWAIT);
187 if (recv_bytes == -1)
189 if (
errno == EAGAIN ||
errno == EWOULDBLOCK)
return 0;
194 for (
struct cmsghdr * cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg))
196 fprintf(stderr,
"cmsg_len=%zu, cmsg_level=%u, cmsg_type=%u\n", cmsg->cmsg_len, cmsg->cmsg_level, cmsg->cmsg_type);
198 if (cmsg->cmsg_level == SOL_IP && cmsg->cmsg_type == IP_RECVERR)
200 return ((
struct sock_extended_err *)CMSG_DATA(cmsg))->ee_errno;
214 if (fstat(
fd, &sb) == -1)
216 perror(
"invalid shared buffer fd");
220 void * ret = mmap(0, size, PROT_READ, MAP_SHARED,
fd, 0);
222 if (ret == MAP_FAILED)
234 if (munmap(ptr, size) == -1)
236 perror(
"shared buffer munmap");
244 int size =
sizeof(buffer);
250 size = vsnprintf(p, size,
fmt, ap);
258 if ((
unsigned)size <
sizeof(buffer))
260 return std::string(buffer);
264 p = (
char*)malloc(size);
272 size = vsnprintf(p, size,
fmt, ap);
CommandLineArgs * userConfigurableArguments
void log(const std::string &log)
void logDMsg(XMLEle *root, const char *dev)
XMLEle * cloneXMLEleWithReplacementMap(XMLEle *root, const std::unordered_map< XMLEle *, XMLEle * > &replacement)
bool parseBlobSize(XMLEle *blobWithAttachedBuffer, ssize_t &size)
std::string fmt(const char *fmt,...)
char * indi_tstamp(char *s)
std::vector< XMLEle * > findBlobElements(XMLEle *root)
int xmlReplacementMapFind(void *self, XMLEle *source, XMLEle **replace)
void dettachSharedBuffer(int fd, void *ptr, size_t size)
void logStartup(int ac, char *av[])
void * attachSharedBuffer(int fd, size_t &size)
const char * findXMLAttValu(XMLEle *ep, const char *name)
Find an XML element's attribute value.
XMLEle * nextXMLEle(XMLEle *ep, int init)
Iterate an XML element for a list of nesetd XML elements.
char * tagXMLEle(XMLEle *ep)
Return the tag of an XML element.
XMLEle * cloneXMLEle(XMLEle *ep)