From 2a6b74746edbfde0b0f1468cdf153263670c908a Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 2 Aug 2013 14:25:23 -0400 Subject: Netconf service itself works, time to integrate. --- node/Service.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'node/Service.cpp') diff --git a/node/Service.cpp b/node/Service.cpp index 88a6d15c..c614e4e4 100644 --- a/node/Service.cpp +++ b/node/Service.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -109,7 +110,7 @@ bool Service::send(const Dictionary &msg) void Service::main() throw() { - char buf[4096]; + char buf[131072]; fd_set readfds,writefds,exceptfds; struct timeval tv; @@ -126,27 +127,30 @@ void Service::main() pipe(out); pipe(err); - long pid = fork(); + long pid = vfork(); if (pid < 0) { LOG("service %s terminating: could not fork!",_name.c_str()); return; } else if (pid) { - close(in[1]); - close(out[0]); - close(err[0]); + // Parent + close(in[0]); + close(out[1]); + close(err[1]); Thread::sleep(500); // give child time to start _childStdin = in[1]; _childStdout = out[0]; _childStderr = err[0]; fcntl(_childStdout,F_SETFL,O_NONBLOCK); fcntl(_childStderr,F_SETFL,O_NONBLOCK); + _pid = pid; } else { - dup2(in[0],STDIN_FILENO); - dup2(out[1],STDOUT_FILENO); - dup2(err[1],STDERR_FILENO); + // Child close(in[1]); close(out[0]); close(err[0]); + dup2(in[0],STDIN_FILENO); + dup2(out[1],STDOUT_FILENO); + dup2(err[1],STDERR_FILENO); execl(_path.c_str(),_path.c_str(),_r->homePath.c_str(),(const char *)0); exit(-1); } @@ -169,6 +173,8 @@ void Service::main() } } + // If we've made it here, _pid is running last we checked. + FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds); -- cgit v1.2.3