summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sysExec.cpp20
-rw-r--r--src/sysExec.h1
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,40 +50,44 @@
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) {
cLog.msg(Log::PRIO_ERROR) << "executing script '" << script << "' pipe() error: " << AnytunErrno(errno);
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_;