Stability improvements for Mac virtual Ethernet tap driver.

This commit is contained in:
Adam Ierymenko 2018-11-13 12:42:03 -08:00
parent 7bde2c089d
commit 350116c513
2 changed files with 13 additions and 9 deletions

View file

@ -147,7 +147,7 @@ MacEthernetTap::MacEthernetTap(
_agentStdin2 = agentStdin[0]; _agentStdin2 = agentStdin[0];
_agentStdout2 = agentStdout[1]; _agentStdout2 = agentStdout[1];
_agentStderr2 = agentStderr[1]; _agentStderr2 = agentStderr[1];
long apid = (long)vfork(); long apid = (long)fork();
if (apid < 0) { if (apid < 0) {
throw std::runtime_error("fork failed"); throw std::runtime_error("fork failed");
} else if (apid == 0) { } else if (apid == 0) {
@ -155,10 +155,13 @@ MacEthernetTap::MacEthernetTap(
::dup2(agentStdout[1],STDOUT_FILENO); ::dup2(agentStdout[1],STDOUT_FILENO);
::dup2(agentStderr[1],STDERR_FILENO); ::dup2(agentStderr[1],STDERR_FILENO);
::close(agentStdin[0]); ::close(agentStdin[0]);
::close(agentStdin[1]);
::close(agentStdout[0]);
::close(agentStdout[1]); ::close(agentStdout[1]);
::close(agentStderr[0]);
::close(agentStderr[1]); ::close(agentStderr[1]);
::execl(agentPath.c_str(),agentPath.c_str(),devnostr,ethaddr,mtustr,metricstr,(char *)0); ::execl(agentPath.c_str(),agentPath.c_str(),devnostr,ethaddr,mtustr,metricstr,(char *)0);
::exit(-1); ::_exit(-1);
} else { } else {
_agentPid = apid; _agentPid = apid;
} }
@ -356,8 +359,8 @@ void MacEthernetTap::threadMain()
const int nfds = std::max(std::max(_shutdownSignalPipe[0],_agentStdout),_agentStderr) + 1; const int nfds = std::max(std::max(_shutdownSignalPipe[0],_agentStdout),_agentStderr) + 1;
long agentReadPtr = 0; long agentReadPtr = 0;
fcntl(_agentStdout,F_SETFL,O_NONBLOCK); fcntl(_agentStdout,F_SETFL,fcntl(_agentStdout,F_GETFL)|O_NONBLOCK);
fcntl(_agentStderr,F_SETFL,O_NONBLOCK); fcntl(_agentStderr,F_SETFL,fcntl(_agentStderr,F_GETFL)|O_NONBLOCK);
FD_ZERO(&readfds); FD_ZERO(&readfds);
FD_ZERO(&nullfds); FD_ZERO(&nullfds);

View file

@ -104,8 +104,8 @@
#define P_IFCONFIG "/sbin/ifconfig" #define P_IFCONFIG "/sbin/ifconfig"
static unsigned char s_pktReadBuf[262144] __attribute__ ((__aligned__(16))); static unsigned char s_pktReadBuf[524288] __attribute__ ((__aligned__(16)));
static unsigned char s_stdinReadBuf[262144] __attribute__ ((__aligned__(16))); static unsigned char s_stdinReadBuf[524288] __attribute__ ((__aligned__(16)));
static char s_deviceName[IFNAMSIZ]; static char s_deviceName[IFNAMSIZ];
static char s_peerDeviceName[IFNAMSIZ]; static char s_peerDeviceName[IFNAMSIZ];
static int s_bpffd = -1; static int s_bpffd = -1;
@ -175,7 +175,7 @@ static int run(const char *path,...)
} else if (pid == 0) { } else if (pid == 0) {
dup2(STDERR_FILENO,STDOUT_FILENO); dup2(STDERR_FILENO,STDOUT_FILENO);
execv(args[0],args); execv(args[0],args);
exit(-1); _exit(-1);
} }
int rv = 0; int rv = 0;
waitpid(pid,&rv,0); waitpid(pid,&rv,0);
@ -322,7 +322,6 @@ int main(int argc,char **argv)
return ZT_MACETHERNETTAPAGENT_EXIT_CODE_UNABLE_TO_CREATE; 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_ndrvfd,F_SETFL,fcntl(s_ndrvfd,F_GETFL)|O_NONBLOCK);
fcntl(s_bpffd,F_SETFL,fcntl(s_bpffd,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; break;
case ZT_MACETHERNETTAPAGENT_STDIN_CMD_IFCONFIG: { case ZT_MACETHERNETTAPAGENT_STDIN_CMD_IFCONFIG: {
char *args[16]; char *args[16];
args[0] = P_IFCONFIG; args[0] = P_IFCONFIG;
@ -410,12 +410,13 @@ int main(int argc,char **argv)
} else if (pid == 0) { } else if (pid == 0) {
dup2(STDERR_FILENO,STDOUT_FILENO); dup2(STDERR_FILENO,STDOUT_FILENO);
execv(args[0],args); execv(args[0],args);
exit(-1); _exit(-1);
} }
int rv = 0; int rv = 0;
waitpid(pid,&rv,0); waitpid(pid,&rv,0);
} }
} break; } break;
case ZT_MACETHERNETTAPAGENT_STDIN_CMD_EXIT: case ZT_MACETHERNETTAPAGENT_STDIN_CMD_EXIT:
return ZT_MACETHERNETTAPAGENT_EXIT_CODE_SUCCESS; return ZT_MACETHERNETTAPAGENT_EXIT_CODE_SUCCESS;
} }