From 350116c513a8d6ea48842245b1d85287b834fbf5 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 13 Nov 2018 12:42:03 -0800 Subject: [PATCH] Stability improvements for Mac virtual Ethernet tap driver. --- osdep/MacEthernetTap.cpp | 11 +++++++---- osdep/MacEthernetTapAgent.c | 11 ++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/osdep/MacEthernetTap.cpp b/osdep/MacEthernetTap.cpp index 92df2f312..1cfb93757 100644 --- a/osdep/MacEthernetTap.cpp +++ b/osdep/MacEthernetTap.cpp @@ -147,7 +147,7 @@ MacEthernetTap::MacEthernetTap( _agentStdin2 = agentStdin[0]; _agentStdout2 = agentStdout[1]; _agentStderr2 = agentStderr[1]; - long apid = (long)vfork(); + long apid = (long)fork(); if (apid < 0) { throw std::runtime_error("fork failed"); } else if (apid == 0) { @@ -155,10 +155,13 @@ MacEthernetTap::MacEthernetTap( ::dup2(agentStdout[1],STDOUT_FILENO); ::dup2(agentStderr[1],STDERR_FILENO); ::close(agentStdin[0]); + ::close(agentStdin[1]); + ::close(agentStdout[0]); ::close(agentStdout[1]); + ::close(agentStderr[0]); ::close(agentStderr[1]); ::execl(agentPath.c_str(),agentPath.c_str(),devnostr,ethaddr,mtustr,metricstr,(char *)0); - ::exit(-1); + ::_exit(-1); } else { _agentPid = apid; } @@ -356,8 +359,8 @@ void MacEthernetTap::threadMain() const int nfds = std::max(std::max(_shutdownSignalPipe[0],_agentStdout),_agentStderr) + 1; long agentReadPtr = 0; - fcntl(_agentStdout,F_SETFL,O_NONBLOCK); - fcntl(_agentStderr,F_SETFL,O_NONBLOCK); + fcntl(_agentStdout,F_SETFL,fcntl(_agentStdout,F_GETFL)|O_NONBLOCK); + fcntl(_agentStderr,F_SETFL,fcntl(_agentStderr,F_GETFL)|O_NONBLOCK); FD_ZERO(&readfds); FD_ZERO(&nullfds); diff --git a/osdep/MacEthernetTapAgent.c b/osdep/MacEthernetTapAgent.c index ca1f7a4ec..7eaac8711 100644 --- a/osdep/MacEthernetTapAgent.c +++ b/osdep/MacEthernetTapAgent.c @@ -104,8 +104,8 @@ #define P_IFCONFIG "/sbin/ifconfig" -static unsigned char s_pktReadBuf[262144] __attribute__ ((__aligned__(16))); -static unsigned char s_stdinReadBuf[262144] __attribute__ ((__aligned__(16))); +static unsigned char s_pktReadBuf[524288] __attribute__ ((__aligned__(16))); +static unsigned char s_stdinReadBuf[524288] __attribute__ ((__aligned__(16))); static char s_deviceName[IFNAMSIZ]; static char s_peerDeviceName[IFNAMSIZ]; static int s_bpffd = -1; @@ -175,7 +175,7 @@ static int run(const char *path,...) } else if (pid == 0) { dup2(STDERR_FILENO,STDOUT_FILENO); execv(args[0],args); - exit(-1); + _exit(-1); } int rv = 0; waitpid(pid,&rv,0); @@ -322,7 +322,6 @@ int main(int argc,char **argv) return ZT_MACETHERNETTAPAGENT_EXIT_CODE_UNABLE_TO_CREATE; } - fcntl(STDIN_FILENO,F_SETFL,fcntl(STDIN_FILENO,F_GETFL)|O_NONBLOCK); fcntl(s_ndrvfd,F_SETFL,fcntl(s_ndrvfd,F_GETFL)|O_NONBLOCK); fcntl(s_bpffd,F_SETFL,fcntl(s_bpffd,F_GETFL)|O_NONBLOCK); @@ -381,6 +380,7 @@ int main(int argc,char **argv) } } break; + case ZT_MACETHERNETTAPAGENT_STDIN_CMD_IFCONFIG: { char *args[16]; args[0] = P_IFCONFIG; @@ -410,12 +410,13 @@ int main(int argc,char **argv) } else if (pid == 0) { dup2(STDERR_FILENO,STDOUT_FILENO); execv(args[0],args); - exit(-1); + _exit(-1); } int rv = 0; waitpid(pid,&rv,0); } } break; + case ZT_MACETHERNETTAPAGENT_STDIN_CMD_EXIT: return ZT_MACETHERNETTAPAGENT_EXIT_CODE_SUCCESS; }