summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2010-01-12 22:28:42 +0000
committerChristian Pointner <equinox@anytun.org>2010-01-12 22:28:42 +0000
commit7b1fed972fa671f6ffa98449a1d3d334d3044573 (patch)
tree2046bb6ef060297d050ad34890e2d02c94129525
parentreferences are better than pointer ;) (diff)
better speration of waitForScript and waitAndDestroy()
-rw-r--r--src/sysExec.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/sysExec.cpp b/src/sysExec.cpp
index 005e2cc..07615e6 100644
--- a/src/sysExec.cpp
+++ b/src/sysExec.cpp
@@ -91,10 +91,10 @@ void SysExec::doExec(std::string const& script, StringVector const& args, String
if(pid_) {
close(pipefd[1]);
pipefd_=pipefd[0];
- //boost::thread(boost::bind(waitForScript, script, pid, pipefd[0]));
+ // parent exits here, call waitForScript to cleanup up zombie
return;
}
-// child code
+ // child code, exec the script
int fd;
for (fd=getdtablesize();fd>=0;--fd) // close all file descriptors
if(fd != pipefd[1]) close(fd);
@@ -153,22 +153,16 @@ int SysExec::waitForScript()
if(read(pipefd_, (void*)(&err), sizeof(err)) >= static_cast<int>(sizeof(err))) {
cLog.msg(Log::PRIO_NOTICE) << "script '" << script_ << "' exec() error: " << AnytunErrno(err);
close(pipefd_);
- return -1;
+ return_code_ = -1;
+ return return_code_;
}
}
- if(WIFEXITED(status))
- cLog.msg(Log::PRIO_NOTICE) << "script '" << script_ << "' returned " << WEXITSTATUS(status);
- else if(WIFSIGNALED(status))
- cLog.msg(Log::PRIO_NOTICE) << "script '" << script_ << "' terminated after signal " << WTERMSIG(status);
- else
- cLog.msg(Log::PRIO_ERROR) << "executing script '" << script_ << "': unknown error";
close(pipefd_);
- closed_=true;
-
+ closed_ = true;
return_code_ = status;
- return status;
+ return return_code_;
}
int SysExec::getReturnCode() const
@@ -182,6 +176,13 @@ void SysExec::waitAndDestroy(SysExec*& s)
return;
s->waitForScript();
+ if(WIFEXITED(s->return_code_))
+ cLog.msg(Log::PRIO_NOTICE) << "script '" << s->script_ << "' returned " << WEXITSTATUS(s->return_code_);
+ else if(WIFSIGNALED(s->return_code_))
+ cLog.msg(Log::PRIO_NOTICE) << "script '" << s->script_ << "' terminated after signal " << WTERMSIG(s->return_code_);
+ else
+ cLog.msg(Log::PRIO_ERROR) << "executing script '" << s->script_ << "': unknown error";
+
delete(s);
s = NULL;
}