From 018e96cf689e0456ab32ba1a6dfca9cd720c6b30 Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Sun, 10 Jan 2010 22:32:55 +0000 Subject: bugfix in new sysexec --- src/sysExec.cpp | 20 ++++++++++++-------- src/sysExec.h | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/sysExec.cpp b/src/sysExec.cpp index 869df3a..cb12f13 100644 --- a/src/sysExec.cpp +++ b/src/sysExec.cpp @@ -50,20 +50,25 @@ SysExec::SysExec(std::string const& script) : script_(script),closed_(false) { - SysExec(script, StringVector(), StringList()); + doExec(script, StringVector(), StringList()); } SysExec::SysExec(std::string const& script, StringVector const& args) : script_(script),closed_(false) { - SysExec(script, args, StringList()); + doExec(script, args, StringList()); } SysExec::SysExec(std::string const& script, StringList const& env) : script_(script),closed_(false) { - SysExec(script, StringVector(), env); + doExec( script, StringVector(), env); } SysExec::SysExec(std::string const& script, StringVector const& args, StringList const& env) : script_(script),closed_(false) +{ + doExec( script, args, env); +} + +void SysExec::doExec(std::string const& script, StringVector const& args, StringList const& env) { int pipefd[2]; if(pipe(pipefd) == -1) { @@ -71,19 +76,18 @@ SysExec::SysExec(std::string const& script, StringVector const& args, StringList return; } - pid_t pid; - pid = fork(); - if(pid == -1) { + pid_ = fork(); + if(pid_ == -1) { cLog.msg(Log::PRIO_ERROR) << "executing script '" << script << "' fork() error: " << AnytunErrno(errno); return; } - if(pid) { + if(pid_) { close(pipefd[1]); + pipefd_=pipefd[0]; //boost::thread(boost::bind(waitForScript, script, pid, pipefd[0])); return; } - // child code int fd; for (fd=getdtablesize();fd>=0;--fd) // close all file descriptors diff --git a/src/sysExec.h b/src/sysExec.h index f0461af..d5315e4 100644 --- a/src/sysExec.h +++ b/src/sysExec.h @@ -52,6 +52,7 @@ class SysExec void waitForScript(); ~SysExec(); private: + void doExec(std::string const& script, StringVector const& args, StringList const& env); std::string script_; pid_t pid_; int pipefd_; -- cgit v1.2.3