From ee9a811b81c5deefd459960936fc9f416c7aa8d2 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 1 Aug 2013 10:11:59 -0400 Subject: Netconf service code, interacts with our MySQL database. --- node/Service.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'node/Service.cpp') diff --git a/node/Service.cpp b/node/Service.cpp index e0d06792..88a6d15c 100644 --- a/node/Service.cpp +++ b/node/Service.cpp @@ -109,9 +109,14 @@ bool Service::send(const Dictionary &msg) void Service::main() throw() { + char buf[4096]; fd_set readfds,writefds,exceptfds; struct timeval tv; + std::string stderrBuf; + std::string stdoutBuf; + unsigned int stdoutExpecting = 0; + while (_run) { if (_pid <= 0) { LOG("launching service %s...",_name.c_str()); @@ -133,10 +138,15 @@ void Service::main() _childStdin = in[1]; _childStdout = out[0]; _childStderr = err[0]; + fcntl(_childStdout,F_SETFL,O_NONBLOCK); + fcntl(_childStderr,F_SETFL,O_NONBLOCK); } else { dup2(in[0],STDIN_FILENO); dup2(out[1],STDOUT_FILENO); dup2(err[1],STDERR_FILENO); + close(in[1]); + close(out[0]); + close(err[0]); execl(_path.c_str(),_path.c_str(),_r->homePath.c_str(),(const char *)0); exit(-1); } @@ -179,9 +189,42 @@ void Service::main() } if ((_childStderr > 0)&&(FD_ISSET(_childStderr,&readfds))) { + int n = (int)read(_childStderr,buf,sizeof(buf)); + for(int i=0;i 0)&&(FD_ISSET(_childStdout,&readfds))) { + int n = (int)read(_childStdout,buf,sizeof(buf)); + for(int i=0;i ZT_SERVICE_MAX_MESSAGE_SIZE) { + LOG("message size overrun from service %s: %u bytes -- restarting service",_name.c_str(),stdoutExpecting); + stdoutExpecting = 0; + kill(_pid,SIGKILL); + break; + } + } + } } } } -- cgit v1.2.3